Discussion of Python 3.8 support
This issue is intended to track the status of Python 3.8 core features as implemented by MicroPython.
Python 3.8.0 (final) was released on the 14 October 2019. The Features for 3.8 are defined in PEP 569 and a detailed description of the changes can be found in What's New in Python 3.8.
- PEP 570, Positional-only arguments
- PEP 572, Assignment Expressions; Done, see #4908
- PEP 574, Pickle protocol 5 with out-of-band data
- PEP 578, Runtime audit hooks
- PEP 587, Python Initialization Configuration
- PEP 590, Vectorcall: a fast calling protocol for CPython
Misc
- f-strings support = for self-documenting expressions and debugging; Done, see #7649
- A
continuestatement was illegal in thefinallyclause due to a problem with the implementation. In Python 3.8 this restriction was lifted; Done, see 82c494a97e874912e7eb23d2f03f39212e343fb3 - The
bool,int, andfractions.Fractiontypes now have anas_integer_ratio()method like that found infloatanddecimal.Decimal - Constructors of
int,floatandcomplexwill now use the__index__()special method, if available and the corresponding method__int__(),__float__()or__complex__()is not available - Added support of
\N{name}escapes in regular expressions - Dict and dictviews are now iterable in reversed insertion order using
reversed() - The syntax allowed for keyword names in function calls was further restricted. In particular, f((keyword)=arg) is no longer allowed
- Generalized iterable unpacking in yield and return statements no longer requires enclosing parentheses
- When a comma is missed in code such as [(10, 20) (30, 40)], the compiler displays a SyntaxWarning with a helpful suggestion
- Arithmetic operations between subclasses of
datetime.dateordatetime.datetimeanddatetime.timedeltaobjects now return an instance of the subclass, rather than the base class - When the Python interpreter is interrupted by
Ctrl-C (SIGINT)and the resultingKeyboardInterruptexception is not caught, the Python process now exits via aSIGINTsignal or with the correct exit code such that the calling process can detect that it died due to aCtrl-C - Some advanced styles of programming require updating the
types.CodeTypeobject for an existing function - For integers, the three-argument form of the pow() function now permits the exponent to be negative in the case where the base is relatively prime to the modulus
- Dict comprehensions have been synced-up with dict literals so that the key is computed first and the value second
- The
object.__reduce__()method can now return a tuple from two to six elements long
Changes to MicroPython built-in modules
- asyncio
-
asyncio.run()has graduated from the provisional to stable API - Running
python -m asynciolaunches a natively async REPL - The exception
asyncio.CancelledErrornow inherits fromBaseExceptionrather thanExceptionand no longer inherits fromconcurrent.futures.CancelledError - Added
asyncio.Task.get_coro()for getting the wrapped coroutine within anasyncio.Task - Asyncio tasks can now be named, either by passing the name keyword argument to
asyncio.create_task()or thecreate_task()event loop method, or by calling theset_name()method on the task object - Added support for Happy Eyeballs to
asyncio.loop.create_connection(). To specify the behavior, two new parameters have been added:happy_eyeballs_delayandinterleave.
-
- gc -
get_objects()can now receive an optional generation parameter indicating a generation to get objects from- (Note, though, that while
gcis a built-in,get_objects()is not implemented for MicroPython)
- (Note, though, that while
- math
- Added new function
math.dist()for computing Euclidean distance between two points - Expanded the
math.hypot()function to handle multiple dimensions - Added new function,
math.prod(), as analogous function tosum()that returns the product of a ‘start’ value (default: 1) times an iterable of numbers - Added two new combinatoric functions
math.perm()andmath.comb() - Added a new function
math.isqrt()for computing accurate integer square roots without conversion to floating point - The function
math.factorial()no longer accepts arguments that are not int-like
- Added new function
- sys - Add new
sys.unraisablehook()function which can be overridden to control how “unraisable exceptions” are handled
(Changes to non-built-in modules will need to be documented elsewhere.)
Discussion of Python 3.7 support
This issue is intended to track the status of Python 3.7 core features as implemented by MicroPython. Not all of these changes should necessarily be implemented in MicroPython but documenting their status is important.
Python 3.7.0 (final) was released on the 27 June 2018. The Features for 3.7 are defined in PEP 537 and an explanation of the changes can be found in What's New in Python 3.7.
- PEP 538 - Coercing the legacy C locale to a UTF-8 based locale
- PEP 539 - A New C-API for Thread-Local Storage in CPython
- PEP 540 -
UTF-8mode - PEP 552 - Deterministic
pyc - PEP 553 - Built-in breakpoint()
- PEP 557 - Data Classes
- PEP 560 - Core support for typing module and generic types
- PEP 562 - Module
__getattr__and__dir__; see partial implementation (__getattr__): 454cca6016afc96deb6d1ad5d1b3553ab9ad18dd - PEP 563 - Postponed Evaluation of Annotations
- PEP 564 - Time functions with nanosecond resolution; see partial implementation: d4b61b00172ccc231307e3ef33f66f28cb6b051f
- PEP 565 - Show DeprecationWarning in
__main__ - PEP 567 - Context Variables
Other language changes
-
asyncandawaitare now reserved keywords -
dictobjects must preserve insertion-order - More than 255 arguments can now be passed to a function, and a function can now have more than 255 parameters
-
bytes.fromhex()andbytearray.fromhex()now ignore all ASCII whitespace, not only spaces -
str,bytes, andbytearraygained support for the newisascii()method, which can be used to test if a string or bytes contain only the ASCII characters -
ImportErrornow displays module name and module__file__path whenfrom ... import ... fails - Circular imports involving absolute imports with binding a submodule to a name are now supported
-
object.__format__(x, '')is now equivalent tostr(x)rather thanformat(str(self), '') - In order to better support dynamic creation of stack traces,
types.TracebackTypecan now be instantiated from Python code, and thetb_nextattribute on tracebacks is now writable - When using the
-mswitch,sys.path[0]is now eagerly expanded to the full starting directory path, rather than being left as the empty directory (which allows imports from the current working directory at the time when an import occurs) - The new
-X importtimeoption or thePYTHONPROFILEIMPORTTIMEenvironment variable can be used to show the timing of each module import
Changes to MicroPython built-in modules
- asyncio (many, may need a separate ticket)
- gc - New features:
gc.freeze(),gc.unfreeze(),gc-get_freeze_count - math -
math.remainder()added to implement IEEE 754-style remainder - re - A number of tidy up features including better support for splitting on empty strings and copy support for compiled expressions and match objects
- sys -
sys.breakpointhook()added.sys.get(/set)_coroutine_origin_tracking_depth()added. - time - Mostly updates to support nanosecond resolution in PEP564, see above.
(Changes to non-built-in modules will need to be documented elsewhere.)