What’s New In Python 3.7

Release:3.7.0a0
Date:March 28, 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. (Contributed by Matthias Bussonnier in bpo-29546.)

New Modules

  • None yet.

Improved Modules

locale

Added another argument monetary in format_string() of locale. If monetary is true, the conversion uses monetary thousands separator and grouping strings. (Contributed by Garvit in bpo-10379.)

os

Added support for bytes paths in fwalk(). (Contributed by Serhiy Storchaka in bpo-28682.)

unittest.mock

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

xmlrpc.server

register_function() of xmlrpc.server.SimpleXMLRPCDispatcher and its subclasses can be used as a decorator. (Contributed by Xiang Zhang in bpo-7769.)

urllib.parse

urllib.parse.quote() has been updated to from RFC 2396 to RFC 3986, adding ~ to the set of characters that is never quoted by default. (Contributed by Christian Theune and Ratnadeep Debnath in bpo-16285.)

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.)
  • Fast implementation from standard C library is now used for functions tgamma(), lgamma(), erf() and erfc() in the math module. (Contributed by Serhiy Storchaka in bpo-26121.)

Build and C API Changes

Deprecated

Changes in the C API

  • The type of results of PyThread_start_new_thread() and PyThread_get_thread_ident(), and the id parameter of PyThreadState_SetAsyncExc() changed from long to unsigned long. (Contributed by Serhiy Storchaka in bpo-6532.)

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.
  • Functions bool(), float(), list() and tuple() no longer take keyword arguments. The first argument of int() can now be passes only as positional argument.

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.)
  • The mode argument of os.makedirs() no longer affects the file permission bits of newly-created intermediate-level directories. To set their file permission bits you can set the umask before invoking makedirs(). (Contributed by Serhiy Storchaka in bpo-19930.)

CPython bytecode changes