3 min read

Python 3.7.1 and 3.6.7 are maintenance releases for Python 3.7 and Python 3.6 respectively. They contain a variety of fixes.

New features in Python 3.7

Python 3.7 was released in June and is the next branch after Python 3.6. Some of the new features in Python 3.7 are:

Postponed evaluation of annotations

By postponing the evaluation of annotations in Python, two bugs were fixed:

  • Annotations were restricted to using names which were already available in the current scope. That is, they did not support forward references.
  • Annotating source code had negative effects on starting a Python program.

Legacy C locale coercion

Determining a sensible default strategy for handling the 7-bit ASCII text encoding is a problem in Python 3. It is implied by the use of the default C or POSIX locale on non-Windows platforms.

With PEP 538, the default interpreter command line interface is updated to automatically coerce that locale to an available UTF-8 based locale. Automatically setting LC_CTYPE using this method means that both the core interpreter and locale-aware C extensions will assume the use of UTF-8 as the default text encoding.

Forced UTF-8 runtime mode

The new -X utf8 command line option and PYTHONUTF8 environment variable can now be used to enable the CPython UTF-8 mode. While in UTF-8 mode, CPython ignores the locale settings to use the UTF-8 encoding by default.

Built-in breakpoint()

The new built-in breakpoint() function is included as an easy and consistent way to enter the Python debugger. The built-in breakpoint() function calls sys.breakpointhook().

A new C API for thread-local storage

Anew Thread Specific Storage (TSS) API is added to CPython which annuls use of the existing TLS API within the CPython interpreter. It deprecates the existing API.

Customization of access to module attributes

Python 3.7 allows defining __getattr__() on modules. It will be called whenever a module attribute is not found otherwise. Also, defining __dir__() on modules is now allowed.

New time functions with nanosecond resolution

The range of clocks in modern systems can exceed the precision of a floating point number returned by the time.time() function. For having greater precision, six new nanosecond variants are added.

Show DeprecationWarning in __main__

The default handling of DeprecationWarning has been changed in Python 3.7. These warnings are again shown by default. It happens only when the code triggering them is running directly in the __main__ module.

Core support for typing module and generic types

Earlier, any changes to the core CPython interpreter were not made by PEP 484. Since type hints and the typing module are extensively used by developers, this restriction is now removed.

Hash-based .pyc Files

The pyc format is extended to allow the hash of the source file to be used for invalidation instead. This was previously used for the source timestamp. Such .pyc files are considered “hash-based”. Hash-based .pyc files come can be of the types checked and unchecked.

New documentation translations

Three new translations namely Japanese, French and Korean are added.

Some fixes in Python 3.7.1

  • Fix for a possible null pointer dereference in bytesobject.c.
  • Fix a bug where iteration order of OrderedDict was not copied.
  • A Fix for async generators not being finalized. This used to happen even when the event loop was in debug mode and garbage collector runs in another thread.
  • Fix self-cancellation in a C implementation of asyncio.Task.
  • Fix for a reference issue inside multiprocessing.Pool that caused the pool to remain alive on being deleted without being closed or terminated explicitly.
  • Ensure that PyObject_Print() returns -1 on error every time.

Also, Python 3.6.7 is released as the seventh maintenance release for Python 3.6.

Visit the Python documentation for a complete list of bug fixes in Python 3.7.1 visit the Python documentation and know more about features in Python 3.7 in the documentation.

Read next

Meet Pypeline, a simple python library for building concurrent data pipelines

Python comes third in TIOBE popularity index for the first time

Home Assistant: an open source Python home automation hub to rule all things smart


Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.