← index #2415Issue #7905
Related · high · value 4.122
QUERY · ISSUE

Discussion of Python 3.6 support

openby dpgeorgeopened 2016-09-13updated 2022-01-22
rfc

Python 3.6 beta 1 was released on 12 Sep 2016, and a summary of the new features can be found here: https://docs.python.org/3.6/whatsnew/3.6.html . Being in beta stage means we can provide feedback on any of the new features/changes if we like.

(See #1329 for Python 3.5 support, which is still pending.)

New syntax features:

  • PEP 498 - Literal String Formatting : f-strings were implemented in 692d36d779192f32371f7f9daa845b566f26968d
  • PEP 515 - Underscores in Numeric Literals; done in 6a445b60fad87c94a1d00ce3a043b881a1f7a5a4 ; see also #3831
  • PEP 525 - Asynchronous Generators (provisional); see #6668
  • PEP 526 - Syntax for Variable Annotations (provisional) for uPy: requires changes to parser, relevant for viper; see #6126
  • PEP 530 - Asynchronous Comprehensions

New built-in features:

  • PEP 468 - Preserving the order of **kwargs in a function
  • PEP 487 - Simpler customization of class creation
  • PEP 520 - Preserving Class Attribute Definition Order

Standard library changes:

  • PEP 495 - Local Time Disambiguation
  • PEP 506 - Adding A Secrets Module To The Standard Library [not relevant to uPy core]
  • PEP 519 - Adding a file system path protocol

CPython internals (not exposed at the Python level so not relevant to uPy):

  • PEP 509 - Add a private version to dict
  • PEP 523 - Adding a frame evaluation API to CPython

Linux/Windows changes:

  • PEP 524 - Make os.urandom() blocking on Linux (during system startup)
  • PEP 528 - Change Windows console encoding to UTF-8 (provisional)
  • PEP 529 - Change Windows filesystem encoding to UTF-8 (provisional)

Other Language Changes

  • A global or nonlocal statement must now textually appear before the first use of the affected name in the same scope. Previously this was a SyntaxWarning.
  • It is now possible to set a special method to None to indicate that the corresponding operation is not available. For example, if a class sets __iter__() to None, the class is not iterable.
  • Long sequences of repeated traceback lines are now abbreviated as "[Previous line repeated {count} more times]"
  • Import now raises the new exception ModuleNotFoundError when it cannot find a module. Code that currently checks for ImportError (in try-except) will still work.
  • Class methods relying on zero-argument super() will now work correctly when called from metaclass methods during class creation.

Changes to MicroPython built-in modules

  • array - Exhausted iterators of array.array will now stay exhausted even if the iterated array is extended.
  • asyncio (many, may need another ticket)
  • binascii - The b2a_base64() function now accepts an optional newline keyword argument to control whether the newline character is appended to the return value.
  • cmath
    • The new cmath.tau (τ) constant has been added.
    • New constants: cmath.inf and cmath.nan to match math.inf and math.nan, and also cmath.infj and cmath.nanj to match the format used by complex repr.
  • collections
    • The new Collection abstract base class has been added to represent sized iterable container classes.
    • The new Reversible abstract base class represents iterable classes that also provide the __reversed__() method.
    • The new AsyncGenerator abstract base class represents asynchronous generators
    • The namedtuple() function now accepts an optional keyword argument module, which, when specified, is used for the __module__ attribute of the returned named tuple class.
    • The verbose and rename arguments for namedtuple() are now keyword-only.
    • Recursive collections.deque instances can now be pickled.
  • hashlib
    • hashlib supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
    • BLAKE2 hash functions were added to the module. blake2b() and blake2s() are always available and support the full feature set of BLAKE2.
    • The SHA-3 hash functions sha3_224(), sha3_256(), sha3_384(), sha3_512(), and SHAKE hash functions shake_128() and shake_256() were added.
    • The password-based key derivation function scrypt() is now available with OpenSSL 1.1.0 and newer.
  • json - json.load() and json.loads() now support binary input. Encoded JSON should be represented using either UTF-8, UTF-16, or UTF-32.
  • math - The tau (τ) constant has been added to the math and cmath modules.
  • os
    • See the summary of PEP 519 for details on how the os and os.path modules now support path-like objects.
    • A new close() method allows explicitly closing a scandir() iterator. The scandir() iterator now supports the context manager protocol.
    • On Linux, os.urandom() now blocks until the system urandom entropy pool is initialized to increase the security.
    • The Linux getrandom() syscall (get random bytes) is now exposed as the new os.getrandom() function.
  • re
    • Added support of modifier spans in regular expressions. Examples: '(?i:p)ython' matches 'python' and 'Python', but not 'PYTHON'; '(?i)g(?-i:v)r' matches 'GvR' and 'gvr', but not 'GVR'.
    • Match object groups can be accessed by __getitem__, which is equivalent to group(). So mo['name'] is now equivalent to mo.group('name').
    • Match objects now support index-like objects as group indices.
  • socket
    • The ioctl() function now supports the SIO_LOOPBACK_FAST_PATH control code.
    • The getsockopt() constants SO_DOMAIN, SO_PROTOCOL, SO_PEERSEC, and SO_PASSSEC are now supported.
    • The setsockopt() now supports the setsockopt(level, optname, None, optlen: int) form.
    • The socket module now supports the address family AF_ALG to interface with Linux Kernel crypto API. ALG_*, SOL_ALG and sendmsg_afalg() were added.
    • New Linux constants TCP_USER_TIMEOUT and TCP_CONGESTION were added.
  • ssl
    • ssl supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
    • 3DES has been removed from the default cipher suites and ChaCha20 Poly1305 cipher suites have been added.
    • SSLContext has better default configuration for options and ciphers.
    • SSL session can be copied from one client-side connection to another with the new SSLSession class. TLS session resumption can speed up the initial handshake, reduce latency and improve performance.
    • The new get_ciphers() method can be used to get a list of enabled ciphers in order of cipher priority.
    • All constants and flags have been converted to IntEnum and IntFlags.
    • Server and client-side specific TLS protocols for SSLContext were added.
    • Added SSLContext.post_handshake_auth to enable and ssl.SSLSocket.verify_client_post_handshake() to initiate TLS 1.3 post-handshake authentication.
  • struct - now supports IEEE 754 half-precision floats via the 'e' format specifier.
  • sys - The new getfilesystemencodeerrors() function returns the name of the error mode used to convert between Unicode filenames and bytes filenames.
  • zlib - The compress() and decompress() functions now accept keyword arguments.

(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