|Date:||May 31, 2015|
This article explains the new features in Python 3.5, compared to 3.4.
For full details, see the Misc/NEWS file.
Prerelease users should be aware that this document is currently in draft form. It will be updated substantially as Python 3.5 moves towards release, so it’s worth checking back even after reading earlier versions.
PEP 478 - Python 3.5 Release Schedule
New syntax features:
New library modules:
New built-in features:
Significantly Improved Library Modules:
Please read on for a comprehensive list of user-facing changes.
async def read_data(db): async with db.transaction(): data = await db.fetch('SELECT ...')
PEP written and implemented by Yury Selivanov.
PEP 492 – Coroutines with async and await syntax
>>> b'Hello %s!' % b'World' b'Hello World!' >>> b'x=%i y=%f' % (1, 2.5) b'x=1 y=2.500000'
Unicode is not allowed for %s, but it is accepted by %a (equivalent of repr(obj).encode('ascii', 'backslashreplace')):
>>> b'Hello %s!' % 'World' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: %b requires bytes, or an object that implements __bytes__, not 'str' >>> b'price: %a' % '10€' b"price: '10\\u20ac'"
PEP 461 – Adding % formatting to bytes and bytearray
This PEP proposes a new binary operator to be used for matrix multiplication, called @. (Mnemonic: @ is * for mATrices.)
PEP 465 – A dedicated infix operator for matrix multiplication
PEP 471 adds a new directory iteration function, os.scandir(), to the standard library. Additionally, os.walk() is now implemented using os.scandir(), which speeds it up by 3-5 times on POSIX systems and by 7-20 times on Windows systems.
PEP and implementation written by Ben Hoyt with the help of Victor Stinner.
PEP 471 – os.scandir() function – a better and faster directory iterator
PEP 475 adds support for automatic retry of system calls failing with EINTR: this means that user code doesn’t have to deal with EINTR or InterruptedError manually, and should make it more robust against asynchronous signal reception.
PEP 475 – Retry system calls failing with EINTR
from __future__ import generator_stop
Without a __future__ import, a PendingDeprecationWarning will be raised.
PEP written by Chris Angelico and Guido van Rossum. Implemented by Chris Angelico, Yury Selivanov and Nick Coghlan.
PEP 479 – Change StopIteration handling inside generators
PEP 486 makes the Windows launcher (see PEP 397) aware of an active virtual environment. When the default interpreter would be used and the VIRTUAL_ENV environment variable is set, the interpreter in the virtual environment will be used.
PEP 486 – Make the Python Launcher aware of virtual environments
PEP 488 does away with the concept of .pyo files. This means that .pyc files represent both unoptimized and optimized bytecode. To prevent the need to constantly regenerate bytecode files, .pyc files now have an optional opt- tag in their name when the bytecode is optimized. This has the side-effect of no more bytecode file name clashes when running under either -O or -OO. Consequently, bytecode files generated from -O, and -OO may now exist simultaneously. importlib.util.cache_from_source() has an updated API to help with this change.
PEP 488 – Elimination of PYO files
This change brings the import semantics of extension modules that opt-in to using the new mechanism much closer to those of Python source and bytecode modules, including the ability to any valid identifier as a module name, rather than being restricted to ASCII.
PEP 488 – Multi-phase extension module initialization
PEP 485 adds the math.isclose() and cmath.isclose() functions which tell whether two values are approximately equal or “close” to each other. Whether or not two values are considered close is determined according to given absolute and relative tolerances.
PEP 485 – A function for testing approximate equality
Some smaller changes made to the core Python language are:
The new zipapp module (specified in PEP 441) provides an API and command line tool for creating executable Python Zip Applications, which were introduced in Python 2.6 in issue 1739468 but which were not well publicised, either at the time or since.
With the new module, bundling your application is as simple as putting all the files, including a __main__.py file, into a directory myapp and running:
$ python -m zipapp myapp $ python myapp.pyz
Since idlelib implements the IDLE shell and editor and is not intended for import by other programs, it gets improvements with every release. See Lib/idlelib/NEWS.txt for a cumulative list of changes since 3.4.0, as well as changes made in future 3.5.x releases. This file is also available from the IDLE Help -> About Idle dialog.
The following performance enhancements have been added:
Changes to Python’s build process and to the C API include:
async and await are not recommended to be used as variable, class or function names. Introduced by PEP 492 in Python 3.5, they will become proper keywords in Python 3.7.
The following obsolete and previously deprecated APIs and features have been removed:
This section lists previously described changes and other bugfixes that may require changes to your code.
- The socket module now exports the CAN_RAW_FD_FRAMES constant on linux 3.6 and greater.
The undocumented format member of the (non-public) PyMemoryViewObject structure has been removed.
All extensions relying on the relevant parts in memoryobject.h must be rebuilt.
The PyMemAllocator structure was renamed to PyMemAllocatorEx and a new calloc field was added.
Because the lack of the __module__ attribute breaks pickling and introspection, a deprecation warning now is raised for builtin type without the __module__ attribute. Would be an AttributeError in future. (issue 20204)