What’s New In Python 3.10

编者 :

Pablo Galindo Salgado

This article explains the new features in Python 3.10, compared to 3.9. Python 3.10 was released on October 4, 2021. For full details, see the changelog .

摘要 – 发行亮点

新句法特征:

  • PEP 634 , Structural Pattern Matching: Specification

  • PEP 635 , Structural Pattern Matching: Motivation and Rationale

  • PEP 636 , Structural Pattern Matching: Tutorial

  • bpo-12782 , Parenthesized context managers are now officially allowed.

新的标准库特征:

  • PEP 618 , Add Optional Length-Checking To zip.

解释器改进:

  • PEP 626 , Precise line numbers for debugging and other tools.

新类型特征:

Important deprecations, removals or restrictions:

  • PEP 644 , Require OpenSSL 1.1.1 or newer

  • PEP 632 , Deprecate distutils module.

  • PEP 623 , Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.

  • PEP 624 , Remove Py_UNICODE encoder APIs

  • PEP 597 , Add optional EncodingWarning

新特征

Parenthesized context managers

Using enclosing parentheses for continuation across multiple lines in context managers is now supported. This allows formatting a long collection of context managers in multiple lines in a similar way as it was previously possible with import statements. For instance, all these examples are now valid:

with (CtxManager() as example):
    ...
with (
    CtxManager1(),
    CtxManager2()
):
    ...
with (CtxManager1() as example,
      CtxManager2()):
    ...
with (CtxManager1(),
      CtxManager2() as example):
    ...
with (
    CtxManager1() as example1,
    CtxManager2() as example2
):
    ...