What’s New In Python 3.7¶
Release: | 3.7.0a0 |
---|---|
Date: | mai 23, 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.)ImportError
now displays module name and module__file__
path whenfrom ... import ...
fails. (Contributed by Matthias Bussonnier in bpo-29546.)- Circular imports involving absolute imports with binding a submodule to a name are now supported. (Contributed by Serhiy Storchaka in bpo-30024.)
object.__format__(x, '')
is now equivalent tostr(x)
rather thanformat(str(self), '')
. (Contributed by Serhiy Storchaka in bpo-28974.)
New Modules¶
- None yet.
Improved Modules¶
cgi¶
parse_multipart()
returns the same results as
FieldStorage
: for non-file fields, the value associated to a key
is a list of strings, not bytes.
(Contributed by Pierre Quentel in bpo-29979.)
binascii¶
The b2a_uu()
function now accepts an optional backtick
keyword argument. When it’s true, zeros are represented by '`'
instead of spaces. (Contributed by Xiang Zhang in bpo-30103.)
contextlib¶
contextlib.asynccontextmanager()
has been added. (Contributed by
Jelle Zijlstra in bpo-29679.)
distutils¶
README.rst is now included in the list of distutils standard READMEs and therefore included in source distributions. (Contributed by Ryan Gonzalez in bpo-11913.)
http.server¶
SimpleHTTPRequestHandler
supports the HTTP
If-Modified-Since header. The server returns the 304 response status if the
target file was not modified after the time specified in the header.
(Contributed by Pierre Quentel in bpo-29654.)
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.)
math¶
New remainder()
function, implementing the IEEE 754-style remainder
operation. (Contributed by Mark Dickinson in bpo-29962.)
os¶
Added support for bytes
paths in fwalk()
. (Contributed by
Serhiy Storchaka in bpo-28682.)
Added support for file descriptors in scandir()
on Unix. (Contributed by Serhiy Storchaka in bpo-25996.)
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
andCALL_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.) - Searching some unlucky Unicode characters (like Ukrainian capital “Є”) in a string was to 25 times slower than searching other characters. Now it is slower only by 3 times in worst case. (Contributed by Serhiy Storchaka in bpo-24821.)
- Fast implementation from standard C library is now used for functions
tgamma()
,lgamma()
,erf()
anderfc()
in themath
module. (Contributed by Serhiy Storchaka in bpo-26121.) - The
os.fwalk()
function has been sped up by 2 times. This was done using theos.scandir()
function. (Contributed by Serhiy Storchaka in bpo-25996.) - Optimized case-insensitive matching and searching of
regular expressions
. Searching some patterns can now be up to 20 times faster. (Contributed by Serhiy Storchaka in bpo-30285.)
Build and C API Changes¶
- A full copy of libffi is no longer bundled for use when building the
_ctypes
module on non-OSX UNIX platforms. An installed copy of libffi is now required when building_ctypes
on such platforms. Contributed by Zachary Ware in bpo-27979. - The fields
name
anddoc
of structuresPyMemberDef
,PyGetSetDef
,PyStructSequence_Field
,PyStructSequence_Desc
, andwrapperbase
are 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_API
is not set or set to the value between0x03050400
and0x03060000
(not including) or0x03060100
or higher. (Contributed by Serhiy Storchaka in bpo-27867.) - Deprecated
format()
fromlocale
, use theformat_string()
instead. (Contributed by Garvit in bpo-10379.) - 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) - Using non-integer value for selecting a plural form in
gettext
is now deprecated. It never correctly worked. (Contributed by Serhiy Storchaka in bpo-28692.) - The
macpath
is now deprecated and will be removed in Python 3.8.
Changes in the C API¶
- The type of results of
PyThread_start_new_thread()
andPyThread_get_thread_ident()
, and the id parameter ofPyThreadState_SetAsyncExc()
changed fromlong
tounsigned long
. (Contributed by Serhiy Storchaka in bpo-6532.)
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 thentpath
module was deprecated in Python 3.1, and has now been removed. Use thesplitdrive()
function instead. - Functions
bool()
,float()
,list()
andtuple()
no longer take keyword arguments. The first argument ofint()
can now be passes only as positional argument. - Removed previously deprecated in Python 2.4 classes
Plist
,Dict
and_InternalDict
in theplistlib
module. Dict values in the result of functionsreadPlist()
andreadPlistFromBytes()
are now normal dicts. You no longer can use attribute access to access items of these dictionaries.
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
andcoded_value
of classhttp.cookies.Morsel
are 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
, andClassDef
AST nodes now have a newdocstring
field. The first statement in their body is not considered as a docstring anymore.co_firstlineno
andco_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 invokingmakedirs()
. (Contributed by Serhiy Storchaka in bpo-19930.)
CPython bytecode changes¶
- Added two new opcodes:
LOAD_METHOD
andCALL_METHOD
. (Contributed by Yury Selivanov and INADA Naoki in bpo-26110.)