← index #7886Issue #7905
Related · high · value 8.338
QUERY · ISSUE

Discussion of Python 3.7 support

openby mattytrentiniopened 2021-10-08updated 2025-10-03
py-core

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-8 mode
  • 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

  • async and await are now reserved keywords
  • dict objects 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() and bytearray.fromhex() now ignore all ASCII whitespace, not only spaces
  • str, bytes, and bytearray gained support for the new isascii() method, which can be used to test if a string or bytes contain only the ASCII characters
  • ImportError now displays module name and module __file__ path when from ... import ... fails
  • Circular imports involving absolute imports with binding a submodule to a name are now supported
  • object.__format__(x, '') is now equivalent to str(x) rather than format(str(self), '')
  • In order to better support dynamic creation of stack traces, types.TracebackType can now be instantiated from Python code, and the tb_next attribute on tracebacks is now writable
  • When using the -m switch, 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 importtime option or the PYTHONPROFILEIMPORTTIME environment 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.)

CANDIDATE · ISSUE

Discussion of Python 3.9 support

openby mattytrentiniopened 2021-10-15updated 2025-10-03
enhancementpy-core

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

Other language changes

  • __import__() now raises ImportError instead of ValueError; 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 returns s instead 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 the ThreadPoolExecutor to 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.
    • asyncio now raises TyperError when calling incompatible methods with an ssl.SSLSocket socket
  • 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
  • os
    • Exposed the Linux-specific os.pidfd_open() and os.P_PIDFD
    • The os.unsetenv() function is now also available on Windows
    • The os.putenv() and os.unsetenv() functions are now always available
    • Added os.waitstatus_to_exitcode() function: convert a wait status to an exit code
  • random - Added a new random.Random.randbytes method: generate random bytes
  • sys
    • Added a new sys.platlibdir attribute: name of the platform-specific library directory
    • Previously, sys.stderr was block-buffered when non-interactive. Now stderr defaults to always being line-buffered.

(Changes to non-built-in modules will need to be documented elsewhere.)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied