|Date:||April 21, 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.
>>> 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
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, thus allowing unoptimized, -O, and -OO bytecode files to all exist simultaneously. importlib.util.cache_from_source() has an updated API to help with this change.
PEP 488 – Elimination of PYO files
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
The following performance enhancements have been added:
Changes to Python’s build process and to the C API include:
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)