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()andbytearray.fromhex()now ignore all ASCII whitespace, not only spaces. (Contributed by Robert Xiao in bpo-28927.)ImportErrornow displays module name and module__file__path whenfrom ... import ...fails. bpo-29546.
New Modules¶
- None yet.
Improved Modules¶
Optimizations¶
- Added two new opcodes:
LOAD_METHODandCALL_METHODto 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¶
- A full copy of libffi is no longer bundled for use when building the
_ctypesmodule on non-OSX UNIX platforms. An installed copy of libffi is now required when building_ctypeson such platforms. Contributed by Zachary Ware in bpo-27979. - The fields
nameanddocof structuresPyMemberDef,PyGetSetDef,PyStructSequence_Field,PyStructSequence_Desc, andwrapperbaseare now of typeconst char *rather ofchar *. (Contributed by Serhiy Storchaka in bpo-28761.) - The result of
PyUnicode_AsUTF8AndSize()andPyUnicode_AsUTF8()is now of typeconst char *rather ofchar *. (Contributed by Serhiy Storchaka in bpo-28769.) - Added functions
PySlice_Unpack()andPySlice_AdjustIndices(). (Contributed by Serhiy Storchaka in bpo-27867.)
Deprecated¶
- Function
PySlice_GetIndicesEx()is deprecated and replaced with a macro ifPy_LIMITED_APIis not set or set to the value between0x03050400and0x03060000(not including) or0x03060100or higher. (Contributed by Serhiy Storchaka in bpo-27867.) - Methods
MetaPathFinder.find_module()(replaced byMetaPathFinder.find_spec()) andPathEntryFinder.find_loader()(replaced byPathEntryFinder.find_spec()) both deprecated in Python 3.4 now emitDeprecationWarning. (Contributed by Matthias Bussonnier in bpo-29576)
Removed¶
API and Feature Removals¶
- Unknown escapes consisting of
'\'and an ASCII letter in replacement templates forre.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 thentpathmodule was deprecated in Python 3.1, and has now been removed. Use thesplitdrive()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,valueandcoded_valueof classhttp.cookies.Morselare now read-only. Assigning to them was deprecated in Python 3.5. Use theset()method for setting them. (Contributed by Serhiy Storchaka in bpo-29192.) Module,FunctionDef,AsyncFunctionDef, andClassDefAST nodes now have a newdocstringfield. The first statement in their body is not considered as a docstring anymore.co_firstlinenoandco_lnotabof code object for class and module are affected by this change. (Contributed by INADA Naoki and Eugene Toder in bpo-29463.)
CPython bytecode changes¶
- Added two new opcodes:
LOAD_METHODandCALL_METHOD. (Contributed by Yury Selivanov and INADA Naoki in bpo-26110.)
