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.9 support
This issue is intended to track the status of Python 3.9 core features as implemented by MicroPython.
Python 3.9.0 (final) was released on the 5th October 2020. The Features for 3.9 are defined in PEP 596 and a detailed description of the changes can be found in What's New in Python 3.9.
- PEP 584, union operators added to dict;
- PEP 585, type hinting generics in standard collections;
- PEP 614, relaxed grammar restrictions on decorators.
- PEP 616, string methods to remove prefixes and suffixes.
- PEP 593, flexible function and variable annotations;
- PEP 573, fast access to module state from methods of C extension types;
- PEP 617, CPython now uses a new parser based on PEG;
- PEP 615, the IANA Time Zone Database is now present in the standard library in the zoneinfo module;
- PEP 602, CPython adopts an annual release cycle. Instead of annual, aiming for two month release cycle
-
__import__()now raisesImportErrorinstead ofValueError; Done, see 53519e322a5a0bb395676cdaa132f5e82de22909 - Python now gets the absolute path of the script filename specified on the command line (ex:
python3 script.py): the__file__attribute of the__main__module became an absolute path, rather than a relative path. - By default, for best performance, the errors argument is only checked at the first encoding/decoding error and the encoding argument is sometimes ignored for empty strings.
-
"".replace("", s, n)now returnssinstead of an empty string for all non-zero n. It is now consistent with"".replace("", s). - Any valid expression can now be used as a decorator. Previously, the grammar was much more restrictive.
- Parallel running of
aclose()/asend()/athrow()is now prohibited, and ag_running now reflects the actual running status of the async generator. - Unexpected errors in calling the
__iter__method are no longer masked by TypeError in the in operator and functions contains(), indexOf() and countOf() of the operator module. - Unparenthesized lambda expressions can no longer be the expression part in an if clause in comprehensions and generator expressions.
Changes to MicroPython built-in modules
- asyncio
- Due to significant security concerns, the reuse_address parameter of
asyncio.loop.create_datagram_endpoint()is no longer supported - Added a new coroutine
shutdown_default_executor()that schedules a shutdown for the default executor that waits on theThreadPoolExecutorto finish closing. Also,asyncio.run()has been updated to use the new coroutine. - Added
asyncio.PidfdChildWatcher, a Linux-specific child watcher implementation that polls process file descriptors - Added a new
coroutine asyncio.to_thread() - When cancelling the task due to a timeout,
asyncio.wait_for()will now wait until the cancellation is complete also in the case when timeout is <= 0, like it does with positive timeouts. -
asyncionow raisesTyperErrorwhen calling incompatible methods with anssl.SSLSocketsocket
- Due to significant security concerns, the reuse_address parameter of
- gc
- Garbage collection does not block on resurrected objects
- Added a new function
gc.is_finalized()to check if an object has been finalized by the garbage collector
- math
- Expanded the
math.gcd()function to handle multiple arguments. Formerly, it only supported two arguments. - Added
math.lcm(): return the least common multiple of specified arguments - Added
math.nextafter(): return the next floating-point value after x towards y - Added
math.ulp(): return the value of the least significant bit of a float
- Expanded the
- os
- Exposed the Linux-specific
os.pidfd_open()andos.P_PIDFD - The
os.unsetenv()function is now also available on Windows - The
os.putenv()andos.unsetenv()functions are now always available - Added
os.waitstatus_to_exitcode()function: convert a wait status to an exit code
- Exposed the Linux-specific
- random - Added a new
random.Random.randbytesmethod: generate random bytes
- sys
- Added a new
sys.platlibdir attribute: name of the platform-specific library directory - Previously,
sys.stderrwas block-buffered when non-interactive. Now stderr defaults to always being line-buffered.
- Added a new
(Changes to non-built-in modules will need to be documented elsewhere.)