The Python Software Foundation just released Python 3.7 recently.

There are several updates:

  • Postponed evaluation of annotations. Using this feature breaks the compatibility, a user has to explicitly use from __future__ import annotations in each python module. But the release team said this feature will become a default one in Python 4.0.
  • async and await becomes reserved keywords in Python. async and await belongs to the coroutine function (starts from 3.5). They can be used to suspend or resume the Python coroutines. Now any await and async identifiers become reserved keywords. Functions defined with async def  syntax are always coroutine functions, even if they do not contain await or async keywords.
  • Three new modules are added to Python 3.7:
    • contextvars. Class ContextVar is used to declare and work with context variables. The context variables should be created at the top module level. Context objects hold strong references to context variables which prevent context variables from being properly garbage collected.
    • dataclasses. It offers a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes.
    • importlib.resources. The module can be used to access, open and read resources in packages.
  • New built-in breakpoint(). It calls sys.breakpointhook(), which allows us to enter any debugger from the function of interest. We can set PYTHONBREAKPOINT=0 to completely disable the built-in breakpoint().
  • Some data model improvements. One of them is the insertion-order preservation nature of dict objects has been declared to be an official part of Python language spec.
  • Some significant improvement in the standard library. One particular interesting improvement is the time module can handle the nanosecond resolution.
  • Some improvement regarding CPython.
    • Avoid the use of ASCII as a default text encoding. Both the core interpreter and locale-aware C extensions (such as readline) assumes the use of UTF-8 as the default text encoding, rather than ASCII. The forced UTF-8 mode can be used to change the text handling behaviour in an embedded Python interpreter without changing the locale settings of an embedding application.
    • deterministic .pycs. If filesystem timestamps are too coarse, Python can miss source updates, which leads to user confusion. Also, having a timestamp (for up-to-dateness check of bytecode cache files) can be problematic for build reproducibility and content-based build system. In Python 3.7, the hash of the source file can be used for invalidation instead of the source timestamp. Such .pyc files are called “hash-based“. By default, Python still uses timestamp based invalidation. But hash-based .pyc can be generated with py_compile or compileall.
    • New command line option to enable CPython’s development mode. Note that although enabling development mode can be used for debugging and performance optimisation, it yields additional runtime checks that are quite expensive. So the development mode is disabled by default.
    • DeprecationWarning handling improvement. In Python 3.7, the deprecation warnings triggered by imported application, library and framework modules can be exposed.
  • C API improvement for thread-local storage.
  • Some document improvement.

Reference:

[1] https://docs.python.org/3.7/whatsnew/3.7.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注