Discussion of Python 3.6 support
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):
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)
- A
globalornonlocalstatement 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
Noneto indicate that the corresponding operation is not available. For example, if a class sets__iter__()toNone, 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
ModuleNotFoundErrorwhen 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.arraywill 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.infandcmath.nanto matchmath.infandmath.nan, and alsocmath.infjandcmath.nanjto match the format used by complex repr.
- The new
- collections
- The new
Collectionabstract base class has been added to represent sized iterable container classes. - The new
Reversibleabstract base class represents iterable classes that also provide the__reversed__()method. - The new
AsyncGeneratorabstract 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.dequeinstances can now be pickled.
- The new
- hashlib
-
hashlibsupports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. - BLAKE2 hash functions were added to the module.
blake2b()andblake2s()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 functionsshake_128()andshake_256()were added. - The password-based key derivation function
scrypt()is now available with OpenSSL 1.1.0 and newer.
-
- json -
json.load()andjson.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
mathandcmathmodules. - os
- See the summary of PEP 519 for details on how the
osandos.pathmodules now support path-like objects.
- A new
close()method allows explicitly closing ascandir()iterator. Thescandir()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 newos.getrandom()function.
- See the summary of PEP 519 for details on how the
- 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 togroup(). Somo['name']is now equivalent tomo.group('name'). - Match objects now support index-like objects as group indices.
- Added support of modifier spans in regular expressions. Examples:
- socket
- The
ioctl()function now supports theSIO_LOOPBACK_FAST_PATHcontrol code. - The
getsockopt()constantsSO_DOMAIN,SO_PROTOCOL,SO_PEERSEC, andSO_PASSSECare now supported. - The
setsockopt()now supports thesetsockopt(level, optname, None, optlen: int)form. - The socket module now supports the address family
AF_ALGto interface with Linux Kernel crypto API.ALG_*,SOL_ALGandsendmsg_afalg()were added. - New Linux constants
TCP_USER_TIMEOUTandTCP_CONGESTIONwere added.
- The
- ssl
-
sslsupports 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.
-
SSLContexthas better default configuration for options and ciphers. - SSL session can be copied from one client-side connection to another with the new
SSLSessionclass. 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
IntEnumandIntFlags. - Server and client-side specific TLS protocols for
SSLContextwere added. - Added
SSLContext.post_handshake_authto enable andssl.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()anddecompress()functions now accept keyword arguments.
(Changes to non-built-in modules will need to be documented elsewhere.)
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.)