What’s New In Python 3.7

Release:3.7.0a0
Date:February 22, 2017

This article explains the new features in Python 3.7, compared to 3.6.

For full details, see the changelog.

Note

Prerelease users should be aware that this document is currently in draft form. It will be updated substantially as Python 3.7 moves towards release, so it’s worth checking back even after reading earlier versions.

Summary – Release highlights

New Features

Other Language Changes

  • More than 255 arguments can now be passed to a function, and a function can now have more than 255 parameters. (Contributed by Serhiy Storchaka in bpo-12844 and bpo-18896.)
  • bytes.fromhex() and bytearray.fromhex() now ignore all ASCII whitespace, not only spaces. (Contributed by Robert Xiao in bpo-28927.)
  • ImportError now displays module name and module __file__ path when from ... import ... fails. bpo-29546.

New Modules

  • None yet.

Improved Modules

unittest.mock

The sentinel attributes now preserve their identity when they are copied or pickled. (Contributed by Serhiy Storchaka in bpo-20804.)

Optimizations

  • Added two new opcodes: LOAD_METHOD and CALL_METHOD to avoid instantiation of bound method objects for method calls, which results in method calls being faster up to 20%. (Contributed by Yury Selivanov and INADA Naoki in bpo-26110.)

Build and C API Changes

Deprecated

Removed

API and Feature Removals

  • Unknown escapes consisting of '\' and an ASCII letter in replacement templates for re.sub() were deprecated in Python 3.5, and will now cause an error.
  • Removed support of the exclude argument in tarfile.TarFile.add(). It was deprecated in Python 2.7 and 3.2. Use the filter argument instead.
  • The splitunc() function in the ntpath module was deprecated in Python 3.1, and has now been removed. Use the splitdrive() function instead.

Porting to Python 3.7

This section lists previously described changes and other bugfixes that may require changes to your code.

Changes in the Python API

  • A format string argument for string.Formatter.format() is now positional-only. Passing it as a keyword argument was deprecated in Python 3.5. (Contributed by Serhiy Storchaka in bpo-29193.)
  • Attributes key, value and coded_value of class http.cookies.Morsel are now read-only. Assigning to them was deprecated in Python 3.5. Use the set() method for setting them. (Contributed by Serhiy Storchaka in bpo-29192.)
  • Module, FunctionDef, AsyncFunctionDef, and ClassDef AST nodes now have a new docstring field. The first statement in their body is not considered as a docstring anymore. co_firstlineno and co_lnotab of code object for class and module are affected by this change. (Contributed by INADA Naoki and Eugene Toder in bpo-29463.)

CPython bytecode changes