What's New in Python 3.7 - Python 3.7.4 Documentation
What's New in Python 3.7 - Python 3.7.4 Documentation
4 documentation
This article explains the new features in Python 3.7, compared to 3.6. Python 3.7 was
released on June 27, 2018. For full details, see the changelog.
The asyncio module has received new features, significant usability and performance
improvements.
The time module gained support for functions with nanosecond resolution.
https://docs.python.org/3/whatsnew/3.7.html 1/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
C API improvements:
Documentation improvements:
This release features notable performance improvements in many areas. The Optimizations
section lists them in detail.
For a list of changes that may affect compatibility with previous Python releases please refer
to the Porting to Python 3.7 section.
New Features
PEP 563: Postponed Evaluation of Annotations
The advent of type hints in Python uncovered two glaring usability issues with the functionality
of annotations added in PEP 3107 and refined further in PEP 526:
annotations could only use names which were already available in the current scope, in
other words they didn’t support forward references of any kind; and
annotating source code had adverse effects on startup time of Python programs.
Both of these issues are fixed by postponing the evaluation of annotations. Instead of
compiling code which executes expressions in annotations at their definition time, the
compiler stores the annotation in a string form equivalent to the AST of the expression in
question. If needed, annotations can be resolved at runtime using
typing.get_type_hints() . In the common case where this is not required, the annotations
are cheaper to store (since short strings are interned by the interpreter) and make startup time
faster.
Usability-wise, annotations now support forward references, making the following syntax valid:
class C:
@classmethod
def from_string(cls, source: str) -> C:
...
class B:
...
Since this change breaks compatibility, the new behavior needs to be enabled on a per-
module basis in Python 3.7 using a __future__ import:
See also:
PEP 538 updates the default interpreter command line interface to automatically coerce that
locale to an available UTF-8 based locale as described in the documentation of the new
PYTHONCOERCECLOCALE environment variable. Automatically setting LC_CTYPE this way means
that both the core interpreter and locale-aware C extensions (such as readline ) will assume
the use of UTF-8 as the default text encoding, rather than ASCII.
The platform support definition in PEP 11 has also been updated to limit full text handling
support to suitably configured non-ASCII based locales.
As part of this change, the default error handler for stdin and stdout is now
surrogateescape (rather than strict ) when using any of the defined coercion target locales
(currently C.UTF-8 , C.utf8 , and UTF-8 ). The default error handler for stderr continues to be
backslashreplace , regardless of locale.
Locale coercion is silent by default, but to assist in debugging potentially locale related
integration problems, explicit warnings (emitted directly on stderr ) can be requested by
setting PYTHONCOERCECLOCALE=warn . This setting will also cause the Python runtime to emit a
warning if the legacy C locale remains active when the core interpreter is initialized.
While PEP 538’s locale coercion has the benefit of also affecting extension modules (such as
GNU readline ), as well as child processes (including those running non-Python applications
and older versions of Python), it has the downside of requiring that a suitable target locale be
present on the running system. To better handle the case where no suitable target locale is
available (as occurs on RHEL/CentOS 7, for example), Python 3.7 also implements PEP 540:
Forced UTF-8 Runtime Mode.
See also:
https://docs.python.org/3/whatsnew/3.7.html 3/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The new -X utf8 command line option and PYTHONUTF8 environment variable can be used to
enable the CPython UTF-8 mode.
When in UTF-8 mode, CPython ignores the locale settings, and uses the UTF-8 encoding by
default. The error handlers for sys.stdin and sys.stdout streams are set to
surrogateescape .
The forced UTF-8 mode can be used to change the text handling behavior in an embedded
Python interpreter without changing the locale settings of an embedding application.
While PEP 540’s UTF-8 mode has the benefit of working regardless of which locales are
available on the running system, it has the downside of having no effect on extension
modules (such as GNU readline ), child processes running non-Python applications, and
child processes running older versions of Python. To reduce the risk of corrupting text data
when communicating with such components, Python 3.7 also implements PEP 540: Forced
UTF-8 Runtime Mode).
The UTF-8 mode is enabled by default when the locale is C or POSIX , and the PEP 538 locale
coercion feature fails to change it to a UTF-8 based alternative (whether that failure is due to
PYTHONCOERCECLOCALE=0 being set, LC_ALL being set, or the lack of a suitable target locale).
See also:
Built-in breakpoint() calls sys.breakpointhook() . By default, the latter imports pdb and
then calls pdb.set_trace() , but by binding sys.breakpointhook() to the function of your
choosing, breakpoint() can enter any debugger. Additionally, the environment variable
PYTHONBREAKPOINT can be set to the callable of your debugger of choice. Set
PYTHONBREAKPOINT=0 to completely disable built-in breakpoint() .
See also:
While Python provides a C API for thread-local storage support; the existing Thread Local
Storage (TLS) API has used int to represent TLS keys across all platforms. This has not
https://docs.python.org/3/whatsnew/3.7.html 4/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
generally been a problem for officially-support platforms, but that is neither POSIX-compliant,
nor portable in any practical sense.
PEP 539 changes this by providing a new Thread Specific Storage (TSS) API to CPython
which supersedes use of the existing TLS API within the CPython interpreter, while
deprecating the existing API. The TSS API uses a new type Py_tss_t instead of int to
represent TSS keys–an opaque type the definition of which may depend on the underlying
TLS implementation. Therefore, this will allow to build CPython on platforms where the native
TLS key is defined in a way that cannot be safely cast to int .
Note that on platforms where the native TLS key is defined in a way that cannot be safely cast
to int , all functions of the existing TLS API will be no-op and immediately return failure. This
indicates clearly that the old API is not supported on platforms where it cannot be used
reliably, and that no effort will be made to add such support.
See also:
A typical example of where this may be useful is module attribute deprecation and lazy
loading.
See also:
The resolution of clocks in modern systems can exceed the limited precision of a floating point
number returned by the time.time() function and its variants. To avoid loss of precision,
PEP 564 adds six new “nanosecond” variants of the existing timer functions to the time
module:
time.clock_gettime_ns()
time.clock_settime_ns()
time.monotonic_ns()
time.perf_counter_ns()
time.process_time_ns()
time.time_ns()
https://docs.python.org/3/whatsnew/3.7.html 5/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
See also:
As a result of this change, the standard library now allows developers to choose between
three different deprecation warning behaviours:
See also:
PEP 560: Core Support for typing module and Generic Types
Initially PEP 484 was designed in such way that it would not introduce any changes to the
core CPython interpreter. Now type hints and the typing module are extensively used by the
community, so this restriction is removed. The PEP introduces two special methods
__class_getitem__() and __mro_entries__ , these methods are now used by most classes
and special constructs in typing . As a result, the speed of various operations with types
https://docs.python.org/3/whatsnew/3.7.html 6/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
increased up to 7 times, the generic types can be used without metaclass conflicts, and
several long standing bugs in typing module are fixed.
See also:
PEP 560 – Core support for typing module and generic types
PEP written and implemented by Ivan Levkivskyi
PEP 552 extends the pyc format to allow the hash of the source file to be used for invalidation
instead of the source timestamp. Such .pyc files are called “hash-based”. By default, Python
still uses timestamp-based invalidation and does not generate hash-based .pyc files at
runtime. Hash-based .pyc files may be generated with py_compile or compileall .
Hash-based .pyc files come in two variants: checked and unchecked. Python validates
checked hash-based .pyc files against the corresponding source files at runtime but doesn’t
do so for unchecked hash-based pycs. Unchecked hash-based .pyc files are a useful
performance optimization for environments where a system external to Python (e.g., the build
system) is responsible for keeping .pyc files up-to-date.
See also:
PEP 545 describes the process of creating and maintaining Python documentation
translations.
Japanese: https://docs.python.org/ja/
French: https://docs.python.org/fr/
Korean: https://docs.python.org/ko/
See also:
https://docs.python.org/3/whatsnew/3.7.html 7/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
New Modules
contextvars
The new contextvars module and a set of new C APIs introduce support for context
variables. Context variables are conceptually similar to thread-local variables. Unlike TLS,
context variables support asynchronous code correctly.
https://docs.python.org/3/whatsnew/3.7.html 8/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The asyncio and decimal modules have been updated to use and support context variables
out of the box. Particularly the active decimal context is now stored in a context variable,
which allows decimal operations to work with the correct context in asynchronous code.
See also:
dataclasses
The new dataclass() decorator provides a way to declare data classes. A data class
describes its attributes using class variable annotations. Its constructor and other magic
methods, such as __repr__() , __eq__() , and __hash__() are generated automatically.
Example:
@dataclass
class Point:
x: float
y: float
z: float = 0.0
p = Point(1.5, 2.5)
print(p) # produces "Point(x=1.5, y=2.5, z=0.0)"
See also:
importlib.resources
The new importlib.resources module provides several new APIs and one new ABC for
access to, opening, and reading resources inside packages. Resources are roughly similar to
files inside packages, but they needn’t be actual files on the physical file system. Module
loaders can provide a get_resource_reader() function which returns a
importlib.abc.ResourceReader instance to support this new API. Built-in file path loaders
and zip file loaders both support this.
Improved Modules
argparse
https://docs.python.org/3/whatsnew/3.7.html 9/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
asyncio
The asyncio module has received many new features, usability and performance
improvements. Notable changes include:
The new provisional asyncio.run() function can be used to run a coroutine from
synchronous code by automatically creating and destroying the event loop. (Contributed
by Yury Selivanov in bpo-32314.)
asyncio gained support for contextvars . loop.call_soon() ,
loop.call_soon_threadsafe() , loop.call_later() , loop.call_at() , and
Future.add_done_callback() have a new optional keyword-only context parameter.
Tasks now track their context automatically. See PEP 567 for more details. (Contributed
by Yury Selivanov in bpo-32436.)
The new asyncio.create_task() function has been added as a shortcut to
asyncio.get_event_loop().create_task() . (Contributed by Andrew Svetlov in bpo-
32311.)
The new loop.start_tls() method can be used to upgrade an existing connection to
TLS. (Contributed by Yury Selivanov in bpo-23749.)
The new loop.sock_recv_into() method allows reading data from a socket directly
into a provided buffer making it possible to reduce data copies. (Contributed by Antoine
Pitrou in bpo-31819.)
The new asyncio.current_task() function returns the currently running Task
instance, and the new asyncio.all_tasks() function returns a set of all existing Task
instances in a given loop. The Task.current_task() and Task.all_tasks() methods
have been deprecated. (Contributed by Andrew Svetlov in bpo-32250.)
The new provisional BufferedProtocol class allows implementing streaming protocols
with manual control over the receive buffer. (Contributed by Yury Selivanov in bpo-
32251.)
The new asyncio.get_running_loop() function returns the currently running loop, and
raises a RuntimeError if no loop is running. This is in contrast with
asyncio.get_event_loop() , which will create a new event loop if none is running.
(Contributed by Yury Selivanov in bpo-32269.)
The new StreamWriter.wait_closed() coroutine method allows waiting until the
stream writer is closed. The new StreamWriter.is_closing() method can be used to
determine if the writer is closing. (Contributed by Andrew Svetlov in bpo-32391.)
The new loop.sock_sendfile() coroutine method allows sending files using
os.sendfile when possible. (Contributed by Andrew Svetlov in bpo-32410.)
The new Future.get_loop() and Task.get_loop() methods return the instance of the
loop on which a task or a future were created. Server.get_loop() allows doing the
same for asyncio.Server objects. (Contributed by Yury Selivanov in bpo-32415 and
Srinivas Reddy Thatiparthy in bpo-32418.)
It is now possible to control how instances of asyncio.Server begin serving.
Previously, the server would start serving immediately when created. The new
start_serving keyword argument to loop.create_server() and
https://docs.python.org/3/whatsnew/3.7.html 10/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
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.)
calendar
https://docs.python.org/3/whatsnew/3.7.html 11/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The HTMLCalendar class has new class attributes which ease the customization of CSS
classes in the produced HTML calendar. (Contributed by Oz Tiram in bpo-30095.)
collections
collections.namedtuple() now supports default values. (Contributed by Raymond
Hettinger in bpo-32320.)
compileall
concurrent.futures
ProcessPoolExecutor and ThreadPoolExecutor now support the new initializer and initargs
constructor arguments. (Contributed by Antoine Pitrou in bpo-21423.)
The ProcessPoolExecutor can now take the multiprocessing context via the new mp_context
argument. (Contributed by Thomas Moreau in bpo-31540.)
contextlib
The new nullcontext() is a simpler and faster no-op context manager than ExitStack .
(Contributed by Jesse-Bakker in bpo-10049.)
cProfile
The cProfile command line now accepts -m module_name as an alternative to script path.
(Contributed by Sanyam Khurana in bpo-21862.)
crypt
The crypt module now supports the Blowfish hashing method. (Contributed by Serhiy
Storchaka in bpo-31664.)
The mksalt() function now allows specifying the number of rounds for hashing. (Contributed
by Serhiy Storchaka in bpo-31702.)
datetime
https://docs.python.org/3/whatsnew/3.7.html 12/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The tzinfo class now supports sub-minute offsets. (Contributed by Alexander Belopolsky in
bpo-5288.)
dbm
dbm.dumb now supports reading read-only files and no longer writes the index file when it is
not changed.
decimal
The decimal module now uses context variables to store the decimal context. (Contributed by
Yury Selivanov in bpo-32630.)
dis
The dis() function is now able to disassemble nested code objects (the code of
comprehensions, generator expressions and nested functions, and the code used for building
nested classes). The maximum depth of disassembly recursion is controlled by the new depth
parameter. (Contributed by Serhiy Storchaka in bpo-11822.)
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.)
enum
The Enum learned the new _ignore_ class property, which allows listing the names of
properties which should not become enum members. (Contributed by Ethan Furman in bpo-
31801.)
In Python 3.8, attempting to check for non-Enum objects in Enum classes will raise a
TypeError (e.g. 1 in Color ); similarly, attempting to check for non-Flag objects in a Flag
member will raise TypeError (e.g. 1 in Perm.RW ); currently, both operations return False
instead and are deprecated. (Contributed by Ethan Furman in bpo-33217.)
functools
gc
https://docs.python.org/3/whatsnew/3.7.html 13/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The new gc.freeze() function allows freezing all objects tracked by the garbage collector
and excluding them from future collections. This can be used before a POSIX fork() call to
make the GC copy-on-write friendly or to speed up collection. The new gc.unfreeze()
functions reverses this operation. Additionally, gc.get_freeze_count() can be used to
obtain the number of frozen objects. (Contributed by Li Zekun in bpo-31558.)
hmac
The hmac module now has an optimized one-shot digest() function, which is up to three
times faster than HMAC() . (Contributed by Christian Heimes in bpo-32433.)
http.client
HTTPConnection and HTTPSConnection now support the new blocksize argument for
improved upload throughput. (Contributed by Nir Soffer in bpo-31945.)
http.server
SimpleHTTPRequestHandler now 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.)
Module Browser (on the File menu, formerly called Class Browser), now displays nested
functions and classes in addition to top-level functions and classes. (Contributed by
Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy in bpo-1612262.)
The Settings dialog (Options, Configure IDLE) has been partly rewritten to improve both
appearance and function. (Contributed by Cheryl Sabella and Terry Jan Reedy in multiple
issues.)
The font sample now includes a selection of non-Latin characters so that users can better see
the effect of selecting a particular font. (Contributed by Terry Jan Reedy in bpo-13802.) The
sample can be edited to include other characters. (Contributed by Serhiy Storchaka in bpo-
31860.)
https://docs.python.org/3/whatsnew/3.7.html 14/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The IDLE features formerly implemented as extensions have been reimplemented as normal
features. Their settings have been moved from the Extensions tab to other dialog tabs.
(Contributed by Charles Wohlganger and Terry Jan Reedy in bpo-27099.)
Editor code context option revised. Box displays all context lines up to maxlines. Clicking on a
context line jumps the editor to that line. Context colors for custom themes is added to
Highlights tab of Settings dialog. (Contributed by Cheryl Sabella and Terry Jan Reedy in bpo-
33642, bpo-33768, and bpo-33679.)
On Windows, a new API call tells Windows that tk scales for DPI. On Windows 8.1+ or 10,
with DPI compatibility properties of the Python binary unchanged, and a monitor resolution
greater than 96 DPI, this should make text and lines sharper. It should otherwise have no
effect. (Contributed by Terry Jan Reedy in bpo-33656.)
New in 3.7.1:
Output over N lines (50 by default) is squeezed down to a button. N can be changed in the
PyShell section of the General page of the Settings dialog. Fewer, but possibly extra long,
lines can be squeezed by right clicking on the output. Squeezed output can be expanded in
place by double-clicking the button or into the clipboard or a separate window by right-clicking
the button. (Contributed by Tal Einat in bpo-1529353.)
importlib
The importlib.abc.ResourceReader ABC was introduced to support the loading of
resources from packages. See also importlib.resources. (Contributed by Barry Warsaw, Brett
Cannon in bpo-32248.)
The new importlib.source_hash() can be used to compute the hash of the passed source.
A hash-based .pyc file embeds the value returned by this function.
io
The new TextIOWrapper.reconfigure() method can be used to reconfigure the text stream
with the new settings. (Contributed by Antoine Pitrou in bpo-30526 and INADA Naoki in bpo-
15216.)
ipaddress
https://docs.python.org/3/whatsnew/3.7.html 15/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
itertools
itertools.islice() now accepts integer-like objects as start, stop, and slice
arguments. (Contributed by Will Roberts in bpo-30537.)
locale
logging
Logger instances can now be pickled. (Contributed by Vinay Sajip in bpo-30520.)
The new StreamHandler.setStream() method can be used to replace the logger stream
after handler creation. (Contributed by Vinay Sajip in bpo-30522.)
math
The new math.remainder() function implements the IEEE 754-style remainder operation.
(Contributed by Mark Dickinson in bpo-29962.)
mimetypes
The MIME type of .bmp has been changed from 'image/x-ms-bmp' to 'image/bmp' .
(Contributed by Nitish Chandra in bpo-22589.)
msilib
The new Database.Close() method can be used to close the MSI database. (Contributed by
Berker Peksag in bpo-20486.)
multiprocessing
https://docs.python.org/3/whatsnew/3.7.html 16/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The new Process.close() method explicitly closes the process object and releases all
resources associated with it. ValueError is raised if the underlying process is still running.
(Contributed by Antoine Pitrou in bpo-30596.)
The new Process.kill() method can be used to terminate the process using the SIGKILL
signal on Unix. (Contributed by Vitor Pereira in bpo-30794.)
Non-daemonic threads created by Process are now joined on process exit. (Contributed by
Antoine Pitrou in bpo-18966.)
os
os.fwalk() now accepts the path argument as bytes . (Contributed by Serhiy Storchaka in
bpo-28682.)
os.scandir() gained support for file descriptors. (Contributed by Serhiy Storchaka in bpo-
25996.)
The mode argument of os.makedirs() no longer affects the file permission bits of newly-
created intermediate-level directories. (Contributed by Serhiy Storchaka in bpo-19930.)
os.dup2() now returns the new file descriptor. Previously, None was always returned.
(Contributed by Benjamin Peterson in bpo-32441.)
The structure returned by os.stat() now contains the st_fstype attribute on Solaris and its
derivatives. (Contributed by Jesús Cea Avión in bpo-32659.)
pathlib
The new Path.is_mount() method is now available on POSIX systems and can be used to
determine whether a path is a mount point. (Contributed by Cooper Ry Lees in bpo-30897.)
pdb
pdb.set_trace() now takes an optional header keyword-only argument. If given, it is printed
to the console just before debugging begins. (Contributed by Barry Warsaw in bpo-31389.)
pdb command line now accepts -m module_name as an alternative to script file. (Contributed
by Mario Corchero in bpo-32206.)
py_compile
https://docs.python.org/3/whatsnew/3.7.html 17/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
pydoc
The pydoc server can now bind to an arbitrary hostname specified by the new -n command-
line argument. (Contributed by Feanil Patel in bpo-31128.)
queue
The new SimpleQueue class is an unbounded FIFO queue. (Contributed by Antoine Pitrou in
bpo-14976.)
re
The flags re.ASCII , re.LOCALE and re.UNICODE can be set within the scope of a group.
(Contributed by Serhiy Storchaka in bpo-31690.)
re.split() now supports splitting on a pattern like r'\b' , '^$' or (?=-) that matches an
empty string. (Contributed by Serhiy Storchaka in bpo-25054.)
Regular expressions compiled with the re.LOCALE flag no longer depend on the locale at
compile time. Locale settings are applied only when the compiled regular expression is used.
(Contributed by Serhiy Storchaka in bpo-30215.)
FutureWarning is now emitted if a regular expression contains character set constructs that
will change semantically in the future, such as nested sets and set operations. (Contributed by
Serhiy Storchaka in bpo-30349.)
Compiled regular expression and match objects can now be copied using copy.copy() and
copy.deepcopy() . (Contributed by Serhiy Storchaka in bpo-10076.)
signal
socket
The new socket.getblocking() method returns True if the socket is in blocking mode and
False otherwise. (Contributed by Yury Selivanov in bpo-32373.)
The new socket.close() function closes the passed socket file descriptor. This function
should be used instead of os.close() for better compatibility across platforms. (Contributed
https://docs.python.org/3/whatsnew/3.7.html 18/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
Support for socket.AF_VSOCK sockets has been added to allow communication between
virtual machines and their hosts. (Contributed by Cathy Avery in bpo-27584.)
Sockets now auto-detect family, type and protocol from file descriptor by default. (Contributed
by Christian Heimes in bpo-28134.)
socketserver
socketserver.ThreadingMixIn.server_close() now waits until all non-daemon threads
complete. socketserver.ForkingMixIn.server_close() now waits until all child processes
complete.
sqlite3
sqlite3.Connection now exposes the backup() method when the underlying SQLite library
is at version 3.6.11 or higher. (Contributed by Lele Gaifax in bpo-27645.)
The database argument of sqlite3.connect() now accepts any path-like object, instead of
just a string. (Contributed by Anders Lorentsen in bpo-31843.)
ssl
The ssl module now uses OpenSSL’s builtin API instead of match_hostname() to check a
host name or an IP address. Values are validated during TLS handshake. Any certificate
validation error including failing the host name check now raises SSLCertVerificationError
and aborts the handshake with a proper TLS Alert message. The new exception contains
additional information. Host name validation can be customized with
SSLContext.hostname_checks_common_name . (Contributed by Christian Heimes in bpo-
31399.)
Note: The improved host name check requires a libssl implementation compatible with
OpenSSL 1.0.2 or 1.1. Consequently, OpenSSL 0.9.8 and 1.0.1 are no longer supported
(see Platform Support Removals for more details). The ssl module is mostly compatible with
LibreSSL 2.7.2 and newer.
https://docs.python.org/3/whatsnew/3.7.html 19/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The ssl module no longer sends IP addresses in SNI TLS extension. (Contributed by
Christian Heimes in bpo-32185.)
The default cipher suite selection of the ssl module now uses a blacklist approach rather
than a hard-coded whitelist. Python no longer re-enables ciphers that have been blocked by
OpenSSL security updates. Default cipher suite selection can be configured at compile time.
(Contributed by Christian Heimes in bpo-31429.)
The ssl module has preliminary and experimental support for TLS 1.3 and OpenSSL 1.1.1.
At the time of Python 3.7.0 release, OpenSSL 1.1.1 is still under development and TLS 1.3
hasn’t been finalized yet. The TLS 1.3 handshake and protocol behaves slightly differently
than TLS 1.2 and earlier, see TLS 1.3. (Contributed by Christian Heimes in bpo-32947, bpo-
20995, bpo-29136, bpo-30622 and bpo-33618)
SSLSocket and SSLObject no longer have a public constructor. Direct instantiation was never
a documented and supported feature. Instances must be created with SSLContext methods
wrap_socket() and wrap_bio() . (Contributed by Christian Heimes in bpo-32951)
OpenSSL 1.1 APIs for setting the minimum and maximum TLS protocol version are available
as SSLContext.minimum_version and SSLContext.maximum_version . Supported protocols
are indicated by several new flags, such as HAS_TLSv1_1 . (Contributed by Christian Heimes
in bpo-32609.)
string
string.Template now lets you to optionally modify the regular expression pattern for braced
placeholders and non-braced placeholders separately. (Contributed by Barry Warsaw in bpo-
1198569.)
subprocess
The subprocess.run() function accepts the new capture_output keyword argument. When
true, stdout and stderr will be captured. This is equivalent to passing subprocess.PIPE as
stdout and stderr arguments. (Contributed by Bo Bayles in bpo-32102.)
The subprocess.run function and the subprocess.Popen constructor now accept the text
keyword argument as an alias to universal_newlines. (Contributed by Andrew Clegg in bpo-
https://docs.python.org/3/whatsnew/3.7.html 20/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
31756.)
On Windows the default for close_fds was changed from False to True when redirecting the
standard handles. It’s now possible to set close_fds to true when redirecting the standard
handles. See subprocess.Popen . This means that close_fds now defaults to True on all
supported platforms. (Contributed by Segev Finer in bpo-19764.)
The subprocess module is now more graceful when handling KeyboardInterrupt during
subprocess.call() , subprocess.run() , or in a Popen context manager. It now waits a short
amount of time for the child to exit, before continuing the handling of the KeyboardInterrupt
exception. (Contributed by Gregory P. Smith in bpo-25942.)
sys
The new sys.breakpointhook() hook function is called by the built-in breakpoint() .
(Contributed by Barry Warsaw in bpo-31353.)
On Android, the new sys.getandroidapilevel() returns the build-time Android API version.
(Contributed by Victor Stinner in bpo-28740.)
time
PEP 564 adds six new functions with nanosecond resolution to the time module:
time.clock_gettime_ns()
time.clock_settime_ns()
time.monotonic_ns()
time.perf_counter_ns()
time.process_time_ns()
time.time_ns()
https://docs.python.org/3/whatsnew/3.7.html 21/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
tkinter
The new tkinter.ttk.Spinbox class is now available. (Contributed by Alan Moore in bpo-
32585.)
tracemalloc
tracemalloc.Traceback behaves more like regular tracebacks, sorting the frames from
oldest to most recent. Traceback.format() now accepts negative limit, truncating the result
to the abs(limit) oldest frames. To get the old behaviour, use the new most_recent_first
argument to Traceback.format() . (Contributed by Jesse Bakker in bpo-32121.)
types
The new WrapperDescriptorType , MethodWrapperType , MethodDescriptorType , and
ClassMethodDescriptorType classes are now available. (Contributed by Manuel Krebber
and Guido van Rossum in bpo-29377, and Serhiy Storchaka in bpo-32265.)
unicodedata
The internal unicodedata database has been upgraded to use Unicode 11. (Contributed by
Benjamin Peterson.)
unittest
The new -k command-line option allows filtering tests by a name substring or a Unix shell-like
pattern. For example, python -m unittest -k foo runs
foo_tests.SomeTest.test_something , bar_tests.SomeTest.test_foo , but not
bar_tests.FooTest.test_something . (Contributed by Jonas Haag in bpo-32071.)
unittest.mock
The sentinel attributes now preserve their identity when they are copied or pickled .
(Contributed by Serhiy Storchaka in bpo-20804.)
The new seal() function allows sealing Mock instances, which will disallow further creation of
attribute mocks. The seal is applied recursively to all attributes that are themselves mocks.
(Contributed by Mario Corchero in bpo-30541.)
urllib.parse
https://docs.python.org/3/whatsnew/3.7.html 22/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
urllib.parse.quote() has been updated from RFC 2396 to RFC 3986, adding ~ to the set
of characters that are never quoted by default. (Contributed by Christian Theune and
Ratnadeep Debnath in bpo-16285.)
uu
The uu.encode() 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.)
uuid
The new UUID.is_safe attribute relays information from the platform about whether
generated UUIDs are generated with a multiprocessing-safe method. (Contributed by Barry
Warsaw in bpo-22807.)
warnings
The initialization of the default warnings filters has changed as follows:
warnings enabled via command line options (including those for -b and the new
CPython-specific -X dev option) are always passed to the warnings machinery via the
sys.warnoptions attribute.
warnings filters enabled via the command line or the environment now have the
following order of precedence:
in CPython debug builds, all warnings are now displayed by default (the implicit filter list
is empty)
(Contributed by Nick Coghlan and Victor Stinner in bpo-20361, bpo-32043, and bpo-32230.)
Deprecation warnings are once again shown by default in single-file scripts and at the
interactive prompt. See PEP 565: Show DeprecationWarning in __main__ for details.
(Contributed by Nick Coghlan in bpo-31975.)
xml
https://docs.python.org/3/whatsnew/3.7.html 23/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
As mitigation against DTD and external entity retrieval, the xml.dom.minidom and xml.sax
modules no longer process external entities by default. (Contributed by Christian Heimes in
bpo-17239.)
xml.etree
ElementPath predicates in the find() methods can now compare text of the current node
with [. = "text"] , not only text in children. Predicates also allow adding spaces for better
readability. (Contributed by Stefan Behnel in bpo-31648.)
xmlrpc.server
zipapp
Function create_archive() now accepts an optional filter argument to allow the user to
select which files should be included in the archive. (Contributed by Irmen de Jong in bpo-
31072.)
zipfile
ZipFile now accepts the new compresslevel parameter to control the compression level.
(Contributed by Bo Bayles in bpo-21417.)
C API Changes
A new API for thread-local storage has been implemented. See PEP 539: New C API for
Thread-Local Storage for an overview and Thread Specific Storage (TSS) API for a complete
reference. (Contributed by Masayuki Yamamoto in bpo-25658.)
The new PyImport_GetModule() function returns the previously imported module with the
given name. (Contributed by Eric Snow in bpo-28411.)
https://docs.python.org/3/whatsnew/3.7.html 24/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The new Py_UNREACHABLE macro can be used to mark unreachable code paths. (Contributed
by Barry Warsaw in bpo-31338.)
The tracemalloc now exposes a C API through the new PyTraceMalloc_Track() and
PyTraceMalloc_Untrack() functions. (Contributed by Victor Stinner in bpo-30054.)
The PyExc_RecursionErrorInst singleton that was part of the public API has been removed
as its members being never cleared may cause a segfault during finalization of the interpreter.
Contributed by Xavier de Gaye in bpo-22898 and bpo-30697.
Changes to the startup sequence and the management of dynamic memory allocators mean
that the long documented requirement to call Py_Initialize() before calling most C API
functions is now relied on more heavily, and failing to abide by it may lead to segfaults in
embedding applications. See the Porting to Python 3.7 section in this document and the
Before Python Initialization section in the C API documentation for more details.
https://docs.python.org/3/whatsnew/3.7.html 25/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
Py_DecodeLocale() , Py_EncodeLocale() now use the UTF-8 encoding when the UTF-8
mode is enabled. (Contributed by Victor Stinner in bpo-29240.)
The start and end parameters of PyUnicode_FindChar() are now adjusted to behave like
string slices. (Contributed by Xiang Zhang in bpo-28822.)
Build Changes
Support for building --without-threads has been removed. The threading module is now
always available. (Contributed by Antoine Pitrou in bpo-31370.).
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 Windows build process no longer depends on Subversion to pull in external sources, a
Python script is used to download zipfiles from GitHub instead. If Python 3.6 is not found on
the system (via py -3.6 ), NuGet is used to download a copy of 32-bit Python for this
purpose. (Contributed by Zachary Ware in bpo-30450.)
The ssl module requires OpenSSL 1.0.2 or 1.1 compatible libssl. OpenSSL 1.0.1 has
reached end of lifetime on 2016-12-31 and is no longer supported. LibreSSL is temporarily not
supported as well. LibreSSL releases up to version 2.6.4 are missing required OpenSSL 1.0.2
APIs.
Optimizations
The overhead of calling many methods of various standard library classes implemented in C
has been significantly reduced by porting more code to use the METH_FASTCALL convention.
(Contributed by Victor Stinner in bpo-29300, bpo-29507, bpo-29452, and bpo-29286.)
Various optimizations have reduced Python startup time by 10% on Linux and up to 30% on
macOS. (Contributed by Victor Stinner, INADA Naoki in bpo-29585, and Ivan Levkivskyi in
bpo-31333.)
Method calls are now up to 20% faster due to the bytecode changes which avoid creating
bound method instances. (Contributed by Yury Selivanov and INADA Naoki in bpo-26110.)
The asyncio module received a number of notable optimizations for commonly used
functions:
As a result of PEP 560 work, the import time of typing has been reduced by a factor of 7,
and many typing operations are now faster. (Contributed by Ivan Levkivskyi in bpo-32226.)
sorted() and list.sort() have been optimized for common cases to be up to 40-75%
faster. (Contributed by Elliot Gorokhovsky in bpo-28685.)
hasattr() and getattr() are now about 4 times faster when name is not found and obj
does not override object.__getattr__() or object.__getattribute__() . (Contributed by
INADA Naoki in bpo-32544.)
Searching for certain Unicode characters (like Ukrainian capital “Є”) in a string was up to 25
times slower than searching for other characters. It is now only 3 times slower in the worst
case. (Contributed by Serhiy Storchaka in bpo-24821.)
The os.fwalk() function is now up to 2 times faster thanks to the use of os.scandir() .
(Contributed by Serhiy Storchaka in bpo-25996.)
The speed of the shutil.rmtree() function has been improved by 20–40% thanks to the use
of the os.scandir() function. (Contributed by Serhiy Storchaka in bpo-28564.)
re.compile() now converts flags parameter to int object if it is RegexFlag . It is now as fast
as Python 3.5, and faster than Python 3.6 by about 10% depending on the pattern.
(Contributed by INADA Naoki in bpo-31671.)
Constant folding has been moved from the peephole optimizer to the new AST optimizer,
which is able perform optimizations more consistently. (Contributed by Eugene Toder and
INADA Naoki in bpo-29469 and bpo-11549.)
https://docs.python.org/3/whatsnew/3.7.html 27/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
Most functions and methods in abc have been rewritten in C. This makes creation of abstract
base classes, and calling isinstance() and issubclass() on them 1.5x faster. This also
reduces Python start-up time by up to 10%. (Contributed by Ivan Levkivskyi and INADA Naoki
in bpo-31333)
The math.erf() and math.erfc() functions now use the (faster) C library implementation on
most platforms. (Contributed by Serhiy Storchaka in bpo-26121.)
https://docs.python.org/3/whatsnew/3.7.html 28/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
aifc.openfp() has been deprecated and will be removed in Python 3.9. Use aifc.open()
instead. (Contributed by Brian Curtin in bpo-31985.)
asyncio
Support for directly await -ing instances of asyncio.Lock and other asyncio synchronization
primitives has been deprecated. An asynchronous context manager must be used in order to
acquire and release the synchronization resource. (Contributed by Andrew Svetlov in bpo-
32253.)
collections
In Python 3.8, the abstract base classes in collections.abc will no longer be exposed in the
regular collections module. This will help create a clearer distinction between the concrete
classes and the abstract base classes. (Contributed by Serhiy Storchaka in bpo-25988.)
dbm
dbm.dumb now supports reading read-only files and no longer writes the index file when it is
not changed. A deprecation warning is now emitted if the index file is missing and recreated in
the 'r' and 'w' modes (this will be an error in future Python releases). (Contributed by
Serhiy Storchaka in bpo-28847.)
enum
In Python 3.8, attempting to check for non-Enum objects in Enum classes will raise a
TypeError (e.g. 1 in Color ); similarly, attempting to check for non-Flag objects in a Flag
member will raise TypeError (e.g. 1 in Perm.RW ); currently, both operations return False
instead. (Contributed by Ethan Furman in bpo-33217.)
gettext
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.)
importlib
https://docs.python.org/3/whatsnew/3.7.html 29/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
locale
macpath
The macpath is now deprecated and will be removed in Python 3.8. (Contributed by Chi
Hsuan Yen in bpo-9850.)
threading
socket
The silent argument value truncation in socket.htons() and socket.ntohs() has been
deprecated. In future versions of Python, if the passed argument is larger than 16 bits, an
exception will be raised. (Contributed by Oren Milman in bpo-28332.)
ssl
sunau
sunau.openfp() has been deprecated and will be removed in Python 3.9. Use
sunau.open() instead. (Contributed by Brian Curtin in bpo-31985.)
sys
Deprecated sys.set_coroutine_wrapper() and sys.get_coroutine_wrapper() .
https://docs.python.org/3/whatsnew/3.7.html 30/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The undocumented sys.callstats() function has been deprecated and will be removed in a
future Python version. (Contributed by Victor Stinner in bpo-28799.)
wave
wave.openfp() has been deprecated and will be removed in Python 3.9. Use wave.open()
instead. (Contributed by Brian Curtin in bpo-31985.)
Notably, this issue affects the Debian 8 (aka “jessie”) and Ubuntu 14.04 (aka “Trusty”)
LTS Linux distributions, as they still use OpenSSL 1.0.1 by default.
Debian 9 (“stretch”) and Ubuntu 16.04 (“xenial”), as well as recent releases of other LTS
Linux releases (e.g. RHEL/CentOS 7.5, SLES 12-SP3), use OpenSSL 1.0.2 or later, and
remain supported in the default build configuration.
CPython’s own CI configuration file provides an example of using the SSL compatibility
testing infrastructure in CPython’s test suite to build and link against OpenSSL 1.1.0
rather than an outdated system provided OpenSSL.
https://docs.python.org/3/whatsnew/3.7.html 31/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
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.
collections.namedtuple() no longer supports the verbose parameter or _source
attribute which showed the generated source code for the named tuple class. This was
part of an optimization designed to speed-up class creation. (Contributed by Jelle Zijlstra
with further improvements by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger
in bpo-28638.)
Functions bool() , float() , list() and tuple() no longer take keyword arguments.
The first argument of int() can now be passed only as positional argument.
Removed previously deprecated in Python 2.4 classes Plist , Dict and
_InternalDict in the plistlib module. Dict values in the result of functions
readPlist() and readPlistFromBytes() are now normal dicts. You no longer can use
attribute access to access items of these dictionaries.
The asyncio.windows_utils.socketpair() function has been removed. Use the
socket.socketpair() function instead, it is available on all platforms since Python 3.5.
asyncio.windows_utils.socketpair was just an alias to socket.socketpair on
Python 3.5 and newer.
asyncio no longer exports the selectors and _overlapped modules as
asyncio.selectors and asyncio._overlapped . Replace from asyncio import
selectors with import selectors .
Direct instantiation of ssl.SSLSocket and ssl.SSLObject objects is now prohibited.
The constructors were never documented, tested, or designed as public constructors.
Users were supposed to use ssl.wrap_socket() or ssl.SSLContext . (Contributed by
Christian Heimes in bpo-32951.)
The unused distutils install_misc command has been removed. (Contributed by
Eric N. Vander Weele in bpo-29218.)
Module Removals
The fpectl module has been removed. It was never enabled by default, never worked
correctly on x86-64, and it changed the Python ABI in ways that caused unexpected breakage
of C extensions. (Contributed by Nathaniel J. Smith in bpo-29137.)
Windows-only Changes
The python launcher, (py.exe), can accept 32 & 64 bit specifiers without having to specify a
minor version as well. So py -3-32 and py -3-64 become valid as well as py -3.7-32 , also
the -m-64 and -m.n-64 forms are now accepted to force 64 bit python even if 32 bit would
have otherwise been used. If the specified version is not available py.exe will error exit.
(Contributed by Steve Barnes in bpo-30291.)
https://docs.python.org/3/whatsnew/3.7.html 32/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
The launcher can be run as py -0 to produce a list of the installed pythons, with default
marked with an asterisk. Running py -0p will include the paths. If py is run with a version
specifier that cannot be matched it will also print the short form list of available specifiers.
(Contributed by Steve Barnes in bpo-30362.)
async and await names are now reserved keywords. Code using these names as
identifiers will now raise a SyntaxError . (Contributed by Jelle Zijlstra in bpo-30406.)
PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions
raised directly or indirectly in coroutines and generators are transformed into
RuntimeError exceptions. (Contributed by Yury Selivanov in bpo-32670.)
object.__aiter__() methods can no longer be declared as asynchronous.
(Contributed by Yury Selivanov in bpo-31709.)
Due to an oversight, earlier Python versions erroneously accepted the following syntax:
The locale.localeconv() function now temporarily sets the LC_CTYPE locale to the
value of LC_NUMERIC in some cases. (Contributed by Victor Stinner in bpo-31900.)
pkgutil.walk_packages() now raises a ValueError if path is a string. Previously an
empty list was returned. (Contributed by Sanyam Khurana in bpo-24744.)
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.)
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.)
The struct.Struct.format type is now str instead of bytes . (Contributed by Victor
Stinner in bpo-21071.)
parse_multipart() now accepts the encoding and errors arguments and 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.)
Due to internal changes in socket , calling socket.fromshare() on a socket created by
socket.share in older Python versions is not supported.
repr for BaseException has changed to not include the trailing comma. Most
exceptions are affected by this change. (Contributed by Serhiy Storchaka in bpo-30399.)
repr for datetime.timedelta has changed to include the keyword arguments in the
output. (Contributed by Utkarsh Upadhyay in bpo-30302.)
Because shutil.rmtree() is now implemented using the os.scandir() function, the
user specified handler onerror is now called with the first argument os.scandir instead
of os.listdir when listing the directory is failed.
Support for nested sets and set operations in regular expressions as in Unicode
Technical Standard #18 might be added in the future. This would change the syntax. To
facilitate this future change a FutureWarning will be raised in ambiguous cases for the
time being. That include sets starting with a literal '[' or containing literal character
sequences '--' , '&&' , '~~' , and '||' . To avoid a warning, escape them with a
backslash. (Contributed by Serhiy Storchaka in bpo-30349.)
The result of splitting a string on a regular expression that could match an empty
string has been changed. For example splitting on r'\s*' will now split not only on
whitespaces as it did previously, but also on empty strings before all non-whitespace
characters and just before the end of the string. The previous behavior can be restored
by changing the pattern to r'\s+' . A FutureWarning was emitted for such patterns
since Python 3.5.
For patterns that match both empty and non-empty strings, the result of searching for all
matches may also be changed in other cases. For example in the string 'a\n\n' , the
pattern r'(?m)^\s*?$' will not only match empty strings at positions 2 and 3, but also
the string '\n' at positions 2–3. To match only blank lines, the pattern should be
rewritten as r'(?m)^[^\S\n]*$' .
https://docs.python.org/3/whatsnew/3.7.html 34/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
re.sub() now replaces empty matches adjacent to a previous non-empty match. For
example re.sub('x*', '-', 'abxd') returns now '-a-b--d-' instead of '-a-b-d-'
(the first minus between ‘b’ and ‘d’ replaces ‘x’, and the second minus replaces an
empty string between ‘x’ and ‘d’).
https://docs.python.org/3/whatsnew/3.7.html 35/37
2019/7/10 What’s New In Python 3.7 — Python 3.7.4 documentation
keys and values in the defaults dictionary are now being implicitly converted to strings.
(Contributed by James Tocknell in bpo-23835.)
Several undocumented internal imports were removed. One example is that os.errno is
no longer available; use import errno directly instead. Note that such undocumented
internal imports may be removed any time without notice, even in micro version
releases.
There are two new opcodes: LOAD_METHOD and CALL_METHOD . (Contributed by Yury Selivanov
and INADA Naoki in bpo-26110.)
The STORE_ANNOTATION opcode has been removed. (Contributed by Mark Shannon in bpo-
32550.)
Windows-only Changes
The file used to override sys.path is now called <python-executable>._pth instead of
'sys.path' . See Finding modules for more information. (Contributed by Steve Dower in bpo-
28137.)
In preparation for potential future changes to the public CPython runtime initialization API (see
PEP 432 for an initial, but somewhat outdated, draft), CPython’s internal startup and
configuration management logic has been significantly refactored. While these updates are
intended to be entirely transparent to both embedding applications and users of the regular
CPython CLI, they’re being mentioned here as the refactoring changes the internal order of
various operations during interpreter startup, and hence may uncover previously latent
defects, either in embedding applications, or in CPython itself. (Initially contributed by Nick
Coghlan and Eric Snow as part of bpo-22257, and further updated by Nick, Eric, and Victor
Stinner in a number of other issues). Some known details affected:
interpreter
Due to changes in the way the default warnings filters are configured, setting
Py_BytesWarningFlag to a value greater than one is no longer sufficient to both emit
BytesWarning messages and have them converted to exceptions. Instead, the flag must be
set (to cause the warnings to be emitted in the first place), and an explicit
error::BytesWarning warnings filter added to convert them to exceptions.
Due to a change in the way docstrings are handled by the compiler, the implicit return None
in a function body consisting solely of a docstring is now marked as occurring on the same
line as the docstring, not on the function’s header line.
The current exception state has been moved from the frame object to the co-routine. This
simplified the interpreter and fixed a couple of obscure bugs caused by having swap
exception state when entering or exiting a generator. (Contributed by Mark Shannon in bpo-
25612.)
In 3.7.1 the C API for Context Variables was updated to use PyObject pointers. See also bpo-
34762.
xml.dom.minidom and xml.sax modules no longer process external entities by default. See
also bpo-17239.
In 3.7.1 the tokenize module now implicitly emits a NEWLINE token when provided with input
that does not have a trailing new line. This behavior now matches what the C tokenizer does
internally. (Contributed by Ammar Askar in bpo-33899.)
https://docs.python.org/3/whatsnew/3.7.html 37/37