Generic windows executables là gì

Python 3.11 is between 10-60% faster than Python 3.10. On average, we measured a 1.25x speedup on the standard benchmark suite. See for details.

New syntax features:

New built-in features:

New standard library modules:

  • PEP 680: — Support for parsing TOML in the Standard Library

Interpreter improvements:

  • New command line option and environment variable to to

New typing features:

Important deprecations, removals and restrictions:

  • PEP 594: and will be removed in Python 3.13

  • PEP 624:

  • PEP 670:

New Features

PEP 657: Fine-grained error locations in tracebacks

When printing tracebacks, the interpreter will now point to the exact expression that caused the error, instead of just the line. For example:

Traceback [most recent call last]:
  File "distance.py", line 11, in 
    print[manhattan_distance[p1, p2]]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "distance.py", line 6, in manhattan_distance
    return abs[point_1.x - point_2.x] + abs[point_1.y - point_2.y]
                           ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'x'

Previous versions of the interpreter would point to just the line, making it ambiguous which object was

Traceback [most recent call last]:
  File "calculation.py", line 54, in 
    result = [x / y / z] * [a / b / c]
              ~~~~~~^~~
ZeroDivisionError: division by zero
4. These enhanced errors can also be helpful when dealing with deeply nested objects and multiple function calls:

Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable

As well as complex arithmetic expressions:

Traceback [most recent call last]:
  File "calculation.py", line 54, in 
    result = [x / y / z] * [a / b / c]
              ~~~~~~^~~
ZeroDivisionError: division by zero

Additionally, the information used by the enhanced traceback feature is made available via a general API, that can be used to correlate with source code location. This information can be retrieved using:

  • The method in Python.

  • The function in the C API.

See PEP 657 for more details. [Contributed by Pablo Galindo, Batuhan Taskaya and Ammar Askar in bpo-43950.]

Note

This feature requires storing column positions in , which may result in a small increase in interpreter memory usage and disk usage for compiled Python files. To avoid storing the extra information and deactivate printing the extra traceback information, use the command line option or the environment variable.

PEP 654: Exception Groups and
class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]
0

PEP 654 introduces language features that enable a program to raise and handle multiple unrelated exceptions simultaneously. The builtin types and make it possible to group exceptions and raise them together, and the new syntax generalizes to match subgroups of exception groups.

See PEP 654 for more details.

[Contributed by Irit Katriel in bpo-45292. PEP written by Irit Katriel, Yury Selivanov and Guido van Rossum.]

PEP 678: Exceptions can be enriched with notes

The method is added to . It can be used to enrich exceptions with context information that is not available at the time when the exception is raised. The added notes appear in the default traceback.

See PEP 678 for more details.

[Contributed by Irit Katriel in bpo-45607. PEP written by Zac Hatfield-Dodds.]

Windows
class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]
7 launcher improvements

The copy of the included with Python 3.11 has been significantly updated. It now supports company/tag syntax as defined in PEP 514 using the

class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]
8 argument instead of the limited
class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]
9. This allows launching distributions other than
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
0, the one hosted on python.org.

When using

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
1 selectors, either company or tag can be omitted, but all installs will be searched. For example,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
2 will select the “best” tag registered for
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
3, while
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
4 or
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
5 will select the “best” distribution with tag
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
6.

When using the legacy

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
7,
class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]
9,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
9 or
class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...
0 arguments, all existing behaviour should be preserved from past versions, and only releases from
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
0 will be selected. However, the
class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...
2 suffix now implies “not 32-bit” [not necessarily x86-64], as there are multiple supported 64-bit platforms. 32-bit runtimes are detected by checking the runtime’s tag for a
class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...
3 suffix. All releases of Python since 3.5 have included this in their 32-bit builds.

New Features Related to Type Hints

This section covers major changes affecting PEP 484 type hints and the module.

PEP 646: Variadic generics

PEP 484 previously introduced , enabling creation of generics parameterised with a single type. PEP 646 adds , enabling parameterisation with an arbitrary number of types. In other words, a is a variadic type variable, enabling variadic generics.

This enables a wide variety of use cases. In particular, it allows the type of array-like structures in numerical computing libraries such as NumPy and TensorFlow to be parameterised with the array shape. Static type checkers will now be able to catch shape-related bugs in code that uses these libraries.

See PEP 646 for more details.

[Contributed by Matthew Rahtz in bpo-43224, with contributions by Serhiy Storchaka and Jelle Zijlstra. PEP written by Mark Mendoza, Matthew Rahtz, Pradeep Kumar Srinivasan, and Vincent Siles.]

PEP 655: Marking individual
class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...
8 items as required or not-required

and provide a straightforward way to mark whether individual items in a must be present. Previously, this was only possible using inheritance.

All fields are still required by default, unless the total parameter is set to

def run_query[sql: LiteralString] -> ...
    ...

def caller[
    arbitrary_string: str,
    query_string: LiteralString,
    table_name: LiteralString,
] -> None:
    run_query["SELECT * FROM students"]       # ok
    run_query[query_string]                   # ok
    run_query["SELECT * FROM " + table_name]  # ok
    run_query[arbitrary_string]               # type checker error
    run_query[                                # type checker error
        f"SELECT * FROM students WHERE name = {arbitrary_string}"
    ]
2, in which case all fields are still not-required by default. For example, the following specifies a
class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...
8 with one required and one not-required key:

class Movie[TypedDict]:
   title: str
   year: NotRequired[int]

m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
m3: Movie = {"year": 2022}  # ERROR [missing required field title]

The following definition is equivalent:

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int

See PEP 655 for more details.

[Contributed by David Foster and Jelle Zijlstra in bpo-47087. PEP written by David Foster.]

PEP 673:
def run_query[sql: LiteralString] -> ...
    ...

def caller[
    arbitrary_string: str,
    query_string: LiteralString,
    table_name: LiteralString,
] -> None:
    run_query["SELECT * FROM students"]       # ok
    run_query[query_string]                   # ok
    run_query["SELECT * FROM " + table_name]  # ok
    run_query[arbitrary_string]               # type checker error
    run_query[                                # type checker error
        f"SELECT * FROM students WHERE name = {arbitrary_string}"
    ]
4 type

The new annotation provides a simple and intuitive way to annotate methods that return an instance of their class. This behaves the same as the -based approach , but is more concise and easier to follow.

Common use cases include alternative constructors provided as s, and methods that return

def run_query[sql: LiteralString] -> ...
    ...

def caller[
    arbitrary_string: str,
    query_string: LiteralString,
    table_name: LiteralString,
] -> None:
    run_query["SELECT * FROM students"]       # ok
    run_query[query_string]                   # ok
    run_query["SELECT * FROM " + table_name]  # ok
    run_query[arbitrary_string]               # type checker error
    run_query[                                # type checker error
        f"SELECT * FROM students WHERE name = {arbitrary_string}"
    ]
9:

class MyLock:
    def __enter__[self] -> Self:
        self.lock[]
        return self

    ...

class MyInt:
    @classmethod
    def fromhex[cls, s: str] -> Self:
        return cls[int[s, 16]]

    ...

can also be used to annotate method parameters or attributes of the same type as their enclosing class.

See PEP 673 for more details.

[Contributed by James Hilton-Balfe in bpo-46534. PEP written by Pradeep Kumar Srinivasan and James Hilton-Balfe.]

PEP 675: Arbitrary literal string type

The new annotation may be used to indicate that a function parameter can be of any literal string type. This allows a function to accept arbitrary literal string types, as well as strings created from other literal strings. Type checkers can then enforce that sensitive functions, such as those that execute SQL statements or shell commands, are called only with static arguments, providing protection against injection attacks.

For example, a SQL query function could be annotated as follows:

def run_query[sql: LiteralString] -> ...
    ...

def caller[
    arbitrary_string: str,
    query_string: LiteralString,
    table_name: LiteralString,
] -> None:
    run_query["SELECT * FROM students"]       # ok
    run_query[query_string]                   # ok
    run_query["SELECT * FROM " + table_name]  # ok
    run_query[arbitrary_string]               # type checker error
    run_query[                                # type checker error
        f"SELECT * FROM students WHERE name = {arbitrary_string}"
    ]

See PEP 675 for more details.

[Contributed by Jelle Zijlstra in bpo-47088. PEP written by Pradeep Kumar Srinivasan and Graham Bleaney.]

PEP 681: Data class transforms

may be used to decorate a class, metaclass, or a function that is itself a decorator. The presence of

# The create_model decorator is defined by a library.
@typing.dataclass_transform[]
def create_model[cls: Type[T]] -> Type[T]:
    cls.__init__ = ...
    cls.__eq__ = ...
    cls.__ne__ = ...
    return cls

# The create_model decorator can now be used to create new model classes:
@create_model
class CustomerModel:
    id: int
    name: str

c = CustomerModel[id=327, name="Eric Idle"]
3 tells a static type checker that the decorated object performs runtime “magic” that transforms a class, giving it -like behaviors.

For example:

# The create_model decorator is defined by a library.
@typing.dataclass_transform[]
def create_model[cls: Type[T]] -> Type[T]:
    cls.__init__ = ...
    cls.__eq__ = ...
    cls.__ne__ = ...
    return cls

# The create_model decorator can now be used to create new model classes:
@create_model
class CustomerModel:
    id: int
    name: str

c = CustomerModel[id=327, name="Eric Idle"]

See PEP 681 for more details.

[Contributed by Jelle Zijlstra in gh-91860. PEP written by Erik De Bonte and Eric Traut.]

PEP 563 may not be the future

PEP 563 Postponed Evaluation of Annotations [the

# The create_model decorator is defined by a library.
@typing.dataclass_transform[]
def create_model[cls: Type[T]] -> Type[T]:
    cls.__init__ = ...
    cls.__eq__ = ...
    cls.__ne__ = ...
    return cls

# The create_model decorator can now be used to create new model classes:
@create_model
class CustomerModel:
    id: int
    name: str

c = CustomerModel[id=327, name="Eric Idle"]
5 ] that was originally planned for release in Python 3.10 has been put on hold indefinitely. See this message from the Steering Council for more information.

Other Language Changes

  • Starred unpacking expressions can now be used in statements. [See bpo-46725 for more details.]

  • Asynchronous are now allowed inside comprehensions in . Outer comprehensions implicitly become asynchronous in this case. [Contributed by Serhiy Storchaka in bpo-33346.]

  • A is now raised instead of an in statements and for objects that do not support the protocol, and in statements and for objects not supporting the protocol. [Contributed by Serhiy Storchaka in bpo-12022 and bpo-44471.]

  • Added , which provides the default implementation of the

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    4 method. ing and ing instances of subclasses of builtin types , , , , , , and now copies and pickles instance attributes implemented as . [Contributed by Serhiy Storchaka in bpo-26579.]

  • Added a command line option and a environment variable, which disable the automatic prepending to of the script’s directory when running a script, or the current directory when using and . This ensures only stdlib and installed modules are picked up by , and avoids unintentionally or maliciously shadowing modules with those in a local [and typically user-writable] directory. [Contributed by Victor Stinner in gh-57684.]

  • A

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    00 option was added to the that coerces negative to positive zero after rounding to the format precision. See PEP 682 for more details. [Contributed by John Belmonte in gh-90153.]

  • Bytes are no longer accepted on . Support broke sometime between Python 3.2 and 3.6, with no one noticing until after Python 3.10.0 was released. In addition, bringing back support would be problematic due to interactions between and when there is a mixture of and keys. [Contributed by Thomas Grainger in gh-91181.]

Other CPython Implementation Changes

  • The special methods for and for are implemented to support the and protocols. [Contributed by Mark Dickinson and Dong-hee Na in bpo-24234.]

  • Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    12 is added as a new internal hashing algorithm. It has similar security properties as
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    13, but it is slightly faster for long inputs. , , and some other types now use it as the default algorithm for . PEP 552 now use
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    12 too. [Contributed by Inada Naoki in bpo-29410.]

  • When an active exception is re-raised by a statement with no parameters, the traceback attached to this exception is now always

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    19. This means that changes made to the traceback in the current clause are reflected in the re-raised exception. [Contributed by Irit Katriel in bpo-45711.]

  • The interpreter state’s representation of handled exceptions [aka

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    21 or
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    22] now only has the
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    23 field;
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    24 and
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    25 have been removed, as they can be derived from
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    23. [Contributed by Irit Katriel in bpo-45711.]

  • A new ,

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    27, has been added for the Windows installer. It behaves similarly to
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    28, but appends the install and scripts directories instead of prepending them. [Contributed by Bastian Neuburger in bpo-44934.]

  • The field must now be set to

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    30 for initialization to use to initialize . Otherwise, initialization will recalculate the path and replace any values added to
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    33.

  • The output of the option now fits in 50 lines/80 columns. Information about and options is now available using the respective and flags, and with the new . [Contributed by Éric Araujo in bpo-46142.]

  • Converting between and in bases other than 2 [binary], 4, 8 [octal], 16 [hexadecimal], or 32 such as base 10 [decimal] now raises a if the number of digits in string form is above a limit to avoid potential denial of service attacks due to the algorithmic complexity. This is a mitigation for CVE-2020-10735. This limit can be configured or disabled by environment variable, command line flag, or APIs. See the documentation. The default limit is 4300 digits in string form.

New Modules

  • : For parsing TOML. See PEP 680 for more details. [Contributed by Taneli Hukkinen in bpo-40059.]

  • : WSGI-specific types for static type checking. [Contributed by Sebastian Rittau in bpo-42012.]

Improved Modules

asyncio

  • Added the class, an holding a group of tasks that will wait for all of them upon exit. For new code this is recommended over using and directly. [Contributed by Yury Selivanov and others in gh-90908.]

  • Added , an asynchronous context manager for setting a timeout on asynchronous operations. For new code this is recommended over using directly. [Contributed by Andrew Svetlov in gh-90927.]

  • Added the class, which exposes the machinery used by . [Contributed by Andrew Svetlov in gh-91218.]

  • Added the class to the synchronization primitives in the asyncio library, and the related exception. [Contributed by Yves Duprat and Andrew Svetlov in gh-87518.]

  • Added keyword argument all_errors to so that multiple connection errors can be raised as an .

  • Added the method for upgrading existing stream-based connections to TLS. [Contributed by Ian Good in bpo-34975.]

  • Added raw datagram socket functions to the event loop: , and . These have implementations in and . [Contributed by Alex Grönholm in bpo-46805.]

  • Added and methods to . These are primarily intended for internal use, notably by .

contextlib

  • Added non parallel-safe context manager to change the current working directory and then restore it on exit. Simple wrapper around . [Contributed by Filipe Laíns in bpo-25625]

dataclasses

  • Change field default mutability check, allowing only defaults which are instead of any object which is not an instance of , or . [Contributed by Eric V. Smith in bpo-44674.]

datetime

  • Add , a convenience alias for . [Contributed by Kabir Kwatra in gh-91973.]

  • , and can now be used to parse most ISO 8601 formats [barring only those that support fractional hours and minutes]. [Contributed by Paul Ganssle in gh-80010.]

enum

  • Renamed

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    76 to [
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    76 kept as an alias].

  • Added , with members that can be used as [and must be] strings.

  • Added , which only modifies the of members while returning their literal values [rather than names] for and [used by , and s].

  • Changed , and to now inherit from , so their output now matches [both

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    92 and
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    93 return
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    94, whereas before
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    92 returned
    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    96.

  • Changed [the default for , and s] of enums with mixed-in types [e.g. , ] to also include the class name in the output, not just the member’s key. This matches the existing behavior of , returning e.g.

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    03 for an enum
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    04 instead of just
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    05.

  • Added a new boundary class parameter to enums and the enum with its options, to control how to handle out-of-range flag values.

  • Added the enum decorator and the enum with its options, to check enum classes against several specific constraints.

  • Added the and decorators, to ensure the decorated object is/is not converted to an enum member.

  • Added the decorator, which works like except for enums. Use this instead of .

  • Added the enum decorator, which adjusts and to show values as members of their module rather than the enum class. For example,

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    18 for the member of rather than
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    21.

  • Enhanced to support , iteration and / on its members. For example, the following now works:

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    26

  • Changed and so that members are now defined before is called; now includes methods, etc., from mixed-in data types.

  • Changed to only consider primary values [power of two] canonical while composite values [

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    32,
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    33,
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    34, etc.] are considered aliases; inverted flags are coerced to their positive equivalent.

fcntl

  • On FreeBSD, the

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    35 and
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    36 flags respectively are supported, the former equals to
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    37 usage while the latter set the
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    38 flag in addition.

fractions

  • Support PEP 515-style initialization of from string. [Contributed by Sergey B Kirpichev in bpo-44258.]

  • now implements an

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    41 method, so that an
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    42 check passes. [Contributed by Mark Dickinson in bpo-44547.]

functools

  • now supports and as annotations to the dispatch argument.:

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    

    [Contributed by Yurii Karabas in bpo-46014.]

hashlib

  • and now prefer libb2 over Python’s vendored copy. [Contributed by Christian Heimes in bpo-47095.]

  • The internal

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    48 module with SHA3 and SHAKE algorithms now uses tiny_sha3 instead of the Keccak Code Package to reduce code and binary size. The module prefers optimized SHA3 and SHAKE implementations from OpenSSL. The change affects only installations without OpenSSL support. [Contributed by Christian Heimes in bpo-47098.]

  • Add , a helper function for efficient hashing of files or file-like objects. [Contributed by Christian Heimes in gh-89313.]

IDLE and idlelib

  • Apply syntax highlighting to

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    51 files. [Contributed by Alex Waygood and Terry Jan Reedy in bpo-45447.]

  • Include prompts when saving Shell with inputs and outputs. [Contributed by Terry Jan Reedy in gh-95191.]

inspect

  • Add to return all members without triggering dynamic lookup via the descriptor protocol. [Contributed by Weipeng Hong in bpo-30533.]

  • Add for checking if the type of an object is a . [Contributed by Hakan Çelik in bpo-29418.]

  • Change the frame-related functions in the module to return new and class instances [backwards compatible with the previous -like interfaces] that includes the extended PEP 657 position information [end line number, column and end column]. The affected functions are:

    • ,

    [Contributed by Pablo Galindo in gh-88116.]

locale

  • Add to get the current locale encoding. It is similar to

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    64 but ignores the .

logging

  • Added to return a mapping from logging level names [e.g.

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    66] to the values of their corresponding [e.g.
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    67, by default]. [Contributed by Andrei Kulakovin in gh-88024.]

  • Added a method to , to match . It is called automatically during handler initialization and when emitting an event, if there is no active socket. [Contributed by Kirill Pinchuk in gh-88457.]

math

  • Add : return 2 raised to the power of x. [Contributed by Gideon Mitchell in bpo-45917.]

  • Add : return the cube root of x. [Contributed by Ajith Ramachandran in bpo-44357.]

  • The behaviour of two corner cases was changed, for consistency with the IEEE 754 specification. The operations

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    74 and
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    75 now return
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    76. Previously they raised . [Contributed by Mark Dickinson in bpo-44339.]

  • The value is now always available. [Contributed by Victor Stinner in bpo-46917.]

operator

  • A new function

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    79 has been added, such that
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    80. [Contributed by Antony Lee in bpo-44019.]

os

  • On Windows, now uses

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    82, instead of
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    83 which is deprecated. [Contributed by Dong-hee Na in bpo-44611.]

pathlib

  • and return only directories if pattern ends with a pathname components separator: or . [Contributed by Eisuke Kawasima in bpo-22276 and bpo-33392.]

re

  • Atomic grouping [

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    88] and possessive quantifiers [
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    89,
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    90,
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    91,
    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    92] are now supported in regular expressions. [Contributed by Jeffrey C. Jacobs and Serhiy Storchaka in bpo-433030.]

shutil

  • Add optional parameter dir_fd in . [Contributed by Serhiy Storchaka in bpo-46245.]

socket

  • Add CAN Socket support for NetBSD. [Contributed by Thomas Klausner in bpo-30512.]

  • has an option to raise, in case of failure to connect, an containing all errors instead of only raising the last error. [Contributed by Irit Katriel in bpo-29980.]

sqlite3

  • You can now disable the authorizer by passing to . [Contributed by Erlend E. Aasland in bpo-44491.]

  • Collation name can now contain any Unicode character. Collation names with invalid characters now raise instead of . [Contributed by Erlend E. Aasland in bpo-44688.]

  • exceptions now include the SQLite extended error code as and the SQLite error name as . [Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in bpo-16379 and bpo-24139.]

  • Add and to for setting and getting SQLite limits by connection basis. [Contributed by Erlend E. Aasland in bpo-45243.]

  • now sets based on the default threading mode the underlying SQLite library has been compiled with. [Contributed by Erlend E. Aasland in bpo-45613.]

  • C callbacks now use unraisable exceptions if callback tracebacks are enabled. Users can now register an to improve their debug experience. [Contributed by Erlend E. Aasland in bpo-45828.]

  • Fetch across rollback no longer raises . Instead we leave it to the SQLite library to handle these cases. [Contributed by Erlend E. Aasland in bpo-44092.]

  • Add and to for serializing and deserializing databases. [Contributed by Erlend E. Aasland in bpo-41930.]

  • Add to for creating aggregate window functions. [Contributed by Erlend E. Aasland in bpo-34916.]

  • Add to . allows incremental I/O operations on blobs. [Contributed by Aviv Palivoda and Erlend E. Aasland in bpo-24905.]

string

  • Add and to , which respectively return all valid placeholders, and whether any invalid placeholders are present. [Contributed by Ben Kehoe in gh-90465.]

sys

  • now derives the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    24 and
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    25 fields from the
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    26 [the exception instance], so when an exception is modified while it is being handled, the changes are reflected in the results of subsequent calls to
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    27. [Contributed by Irit Katriel in bpo-45711.]

  • Add which returns the active exception instance [equivalent to

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    29]. [Contributed by Irit Katriel in bpo-46328.]

  • Add the flag. [Contributed by Victor Stinner in gh-57684.]

sysconfig

  • Three new [posix_venv, nt_venv and venv] were added and are used when Python creates new virtual environments or when it is running from a virtual environment. The first two schemes [posix_venv and nt_venv] are OS-specific for non-Windows and Windows, the venv is essentially an alias to one of them according to the OS Python runs on. This is useful for downstream distributors who modify . Third party code that creates new virtual environments should use the new venv installation scheme to determine the paths, as does . [Contributed by Miro Hrončok in bpo-45413.]

tempfile

  • objects now fully implement the methods of or [depending on file mode]. This lets them work correctly with APIs that expect file-like objects, such as compression modules. [Contributed by Carey Metcalfe in gh-70363.]

threading

  • On Unix, if the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    36 function is available in the C library [glibc 2.30 and newer], the method now uses the monotonic clock [] for the timeout, rather than using the system clock [], to not be affected by system clock changes. [Contributed by Victor Stinner in bpo-41710.]

time

  • On Unix, now uses the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    41 or
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    42 function, if available, which has a resolution of 1 nanosecond [10-9 seconds], rather than using
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    43 which has a resolution of 1 microsecond [10-6 seconds]. [Contributed by Benjamin Szőke and Victor Stinner in bpo-21302.]

  • On Windows 8.1 and newer, now uses a waitable timer based on high-resolution timers which has a resolution of 100 nanoseconds [10-7 seconds]. Previously, it had a resolution of 1 millisecond [10-3 seconds]. [Contributed by Benjamin Szőke, Dong-hee Na, Eryk Sun and Victor Stinner in bpo-21302 and bpo-45429.]

tkinter

  • Added method

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    45 which returns the exact version of the Tcl library as a named tuple similar to . [Contributed by Serhiy Storchaka in gh-91827.]

traceback

  • Add to allow users to override which frames appear in the traceback, and how they are formatted. [Contributed by Ammar Askar in bpo-44569.]

  • Add , which prints the formatted instance to a file. [Contributed by Irit Katriel in bpo-33809.]

typing

For major changes, see .

  • Add and . is useful for asking a type checker to confirm that a line of code is not reachable. At runtime, it raises an . [Contributed by Jelle Zijlstra in gh-90633.]

  • Add . This is useful for asking a type checker what type it has inferred for a given expression. At runtime it prints the type of the received value. [Contributed by Jelle Zijlstra in gh-90572.]

  • Add . This is useful for asking a type checker to confirm that the type it has inferred for a given expression matches the given type. At runtime it simply returns the received value. [Contributed by Jelle Zijlstra in gh-90638.]

  • types can now be generic. [Contributed by Samodya Abeysiriwardane in gh-89026.]

  • types can now be generic. [Contributed by Serhiy Storchaka in bpo-43923.]

  • Allow subclassing of . This is useful for avoiding type checker errors related to highly dynamic class, such as mocks. [Contributed by Shantanu Jain in gh-91154.]

  • The decorator now sets the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    60 attributed on the decorated object. [Contributed by Jelle Zijlstra in gh-90500.]

  • The function can be used for introspecting the overloads of a function. can be used to clear all registered overloads of a function. [Contributed by Jelle Zijlstra in gh-89263.]

  • The method of subclasses is now preserved. [Contributed by Adrian Garcia Badarasco in gh-88970.]

  • The representation of empty tuple types [

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    65] is simplified. This affects introspection, e.g.
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    66 now evaluates to
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    67 instead of
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    68. [Contributed by Serhiy Storchaka in gh-91137.]

  • Loosen runtime requirements for type annotations by removing the callable check in the private

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    69 function. [Contributed by Gregory Beauregard in gh-90802.]

  • now supports evaluating strings as forward references in . [Contributed by Niklas Rosenstein in gh-85542.]

  • no longer adds to parameters with

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    4 as a default. [Contributed by Nikita Sobolev in gh-90353.]

  • now supports evaluating bare stringified annotations. [Contributed by Gregory Beauregard in gh-90711.]

  • no longer modifies external classes and functions. It also now correctly marks classmethods as not to be type checked. [Contributed by Nikita Sobolev in gh-90729.]

unicodedata

  • The Unicode database has been updated to version 14.0.0. [Contributed by Benjamin Peterson in bpo-45190].

unittest

  • Added methods and of class , method of class and function . [Contributed by Serhiy Storchaka in bpo-45046.]

venv

  • When new Python virtual environments are created, the venv is used to determine the paths inside the environment. When Python runs in a virtual environment, the same installation scheme is the default. That means that downstream distributors can change the default sysconfig install scheme without changing behavior of virtual environments. Third party code that also creates new virtual environments should do the same. [Contributed by Miro Hrončok in bpo-45413.]

warnings

  • now accepts arguments for , providing a more concise way to locally ignore warnings or convert them to errors. [Contributed by Zac Hatfield-Dodds in bpo-47074.]

zipfile

  • Added support for specifying member name encoding for reading metadata in a ’s directory and file headers. [Contributed by Stephen J. Turnbull and Serhiy Storchaka in bpo-28080.]

  • Added for creating new directories inside ZIP archives. [Contributed by Sam Ezeh in gh-49083.]

  • Added , and to . [Contributed by Miguel Brito in gh-88261.]

Optimizations

This section covers specific optimizations independent of the project, which is covered in its own section.

  • The compiler now optimizes simple on string literals containing only the format codes

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    91,
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    92 and
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    93 and makes it as fast as a corresponding expression. [Contributed by Serhiy Storchaka in bpo-28307.]

  • Integer division [

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    94] is better tuned for optimization by compilers. It is now around 20% faster on x86-64 when dividing an by a value smaller than
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    96. [Contributed by Gregory P. Smith and Tim Peters in gh-90564.]

  • is now nearly 30% faster for integers smaller than

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    96. [Contributed by Stefan Behnel in gh-68264.]

  • Resizing lists is streamlined for the common case, speeding up

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    99 by ≈15% and simple s by up to 20-30% [Contributed by Dennis Sweeney in gh-91165.]

  • Dictionaries don’t store hash values when all keys are Unicode objects, decreasing size. For example,

    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    01 is reduced from 352 bytes to 272 bytes [23% smaller] on 64-bit platforms. [Contributed by Inada Naoki in bpo-46845.]

  • Using is now orders of magnitude faster when transferring large files over UDP, with speeds over 100 times higher for a ≈60 MiB file. [Contributed by msoxzw in gh-91487.]

  • functions and are now ≈10 times faster for large arguments [with a larger speedup for larger k]. [Contributed by Serhiy Storchaka in bpo-37295.]

  • The functions , and now consume iterators in one pass rather than converting them to a first. This is twice as fast and can save substantial memory. [Contributed by Raymond Hettinger in gh-90415.]

  • now normalizes pure-ASCII strings in constant time. [Contributed by Dong-hee Na in bpo-44987.]

Faster CPython

CPython 3.11 is on average than CPython 3.10 when measured with the pyperformance benchmark suite, and compiled with GCC on Ubuntu Linux. Depending on your workload, the speedup could be up to 10-60% faster.

This project focuses on two major areas in Python: faster startup and faster runtime. Other optimizations not under this project are listed in .

Faster Startup

Frozen imports / Static code objects

Python caches bytecode in the directory to speed up module loading.

Previously in 3.10, Python module execution looked like this:

Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate

In Python 3.11, the core modules essential for Python startup are “frozen”. This means that their code objects [and bytecode] are statically allocated by the interpreter. This reduces the steps in module execution process to this:

Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
0

Interpreter startup is now 10-15% faster in Python 3.11. This has a big impact for short-running programs using Python.

[Contributed by Eric Snow, Guido van Rossum and Kumar Aditya in numerous issues.]

Faster Runtime

Cheaper, lazy Python frames

Python frames are created whenever Python calls a Python function. This frame holds execution information. The following are new frame optimizations:

  • Streamlined the frame creation process.

  • Avoided memory allocation by generously re-using frame space on the C stack.

  • Streamlined the internal frame struct to contain only essential information. Frames previously held extra debugging and memory management information.

Old-style frame objects are now created only when requested by debuggers or by Python introspection functions such as

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
12 or
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
13. For most user code, no frame objects are created at all. As a result, nearly all Python functions calls have sped up significantly. We measured a 3-7% speedup in pyperformance.

[Contributed by Mark Shannon in bpo-44590.]

Inlined Python function calls

During a Python function call, Python will call an evaluating C function to interpret that function’s code. This effectively limits pure Python recursion to what’s safe for the C stack.

In 3.11, when CPython detects Python code calling another Python function, it sets up a new frame, and “jumps” to the new code inside the new frame. This avoids calling the C interpreting function altogether.

Most Python function calls now consume no C stack space. This speeds up most of such calls. In simple recursive functions like fibonacci or factorial, a 1.7x speedup was observed. This also means recursive functions can recurse significantly deeper [if the user increases the recursion limit]. We measured a 1-3% improvement in pyperformance.

[Contributed by Pablo Galindo and Mark Shannon in bpo-45256.]

PEP 659: Specializing Adaptive Interpreter

PEP 659 is one of the key parts of the faster CPython project. The general idea is that while Python is a dynamic language, most code has regions where objects and types rarely change. This concept is known as type stability.

At runtime, Python will try to look for common patterns and type stability in the executing code. Python will then replace the current operation with a more specialized one. This specialized operation uses fast paths available only to those use cases/types, which generally outperform their generic counterparts. This also brings in another concept called inline caching, where Python caches the results of expensive operations directly in the bytecode.

The specializer will also combine certain common instruction pairs into one superinstruction. This reduces the overhead during execution.

Python will only specialize when it sees code that is “hot” [executed multiple times]. This prevents Python from wasting time for run-once code. Python can also de-specialize when code is too dynamic or when the use changes. Specialization is attempted periodically, and specialization attempts are not too expensive. This allows specialization to adapt to new circumstances.

[PEP written by Mark Shannon, with ideas inspired by Stefan Brunthaler. See PEP 659 for more information. Implementation by Mark Shannon and Brandt Bucher, with additional help from Irit Katriel and Dennis Sweeney.]

Operation

Form

Specialization

Operation speedup [up to]

Contributor[s]

Binary operations

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
14

Binary add, multiply and subtract for common types such as

Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
39,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
16, and
Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
04 take custom fast paths for their underlying types.

10%

Mark Shannon, Dong-hee Na, Brandt Bucher, Dennis Sweeney

Subscript

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
18

Subscripting container types such as

Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
69,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
20 and
Traceback [most recent call last]:
  File "calculation.py", line 54, in 
    result = [x / y / z] * [a / b / c]
              ~~~~~~^~~
ZeroDivisionError: division by zero
5 directly index the underlying data structures.

Subscripting custom

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
22 is also inlined similar to .

10-25%

Irit Katriel, Mark Shannon

Store subscript

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
23

Similar to subscripting specialization above.

10-25%

Dennis Sweeney

Calls

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
24
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
25

Calls to common builtin [C] functions and types such as

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
26 and
Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
04 directly call their underlying C version. This avoids going through the internal calling convention.

20%

Mark Shannon, Ken Jin

Load global variable

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
28
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
26

The object’s index in the globals/builtins namespace is cached. Loading globals and builtins require zero namespace lookups.

Mark Shannon

Load attribute

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
30

Similar to loading global variables. The attribute’s index inside the class/object’s namespace is cached. In most cases, attribute loading will require zero namespace lookups.

Mark Shannon

Load methods for call

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
31

The actual address of the method is cached. Method loading now has no namespace lookups – even for classes with long inheritance chains.

10-20%

Ken Jin, Mark Shannon

Store attribute

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
32

Similar to load attribute optimization.

2% in pyperformance

Mark Shannon

Unpack Sequence

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
33

Specialized for common containers such as

Traceback [most recent call last]:
  File "query.py", line 37, in 
    magic_arithmetic['foo']
  File "query.py", line 18, in magic_arithmetic
    return add_counts[x] / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user[user1] + query_user[user2]
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
69 and
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
20. Avoids internal calling convention.

8%

Brandt Bucher

A similar optimization already existed since Python 3.8. 3.11 specializes for more forms and reduces some overhead.

A similar optimization already existed since Python 3.10. 3.11 specializes for more forms. Furthermore, all attribute loads should be sped up by bpo-45947.

Misc

  • Objects now require less memory due to lazily created object namespaces. Their namespace dictionaries now also share keys more freely. [Contributed Mark Shannon in bpo-45340 and bpo-40116.]

  • A more concise representation of exceptions in the interpreter reduced the time required for catching an exception by about 10%. [Contributed by Irit Katriel in bpo-45711.]

FAQ

Q: How should I write my code to utilize these speedups?


A: You don’t have to change your code. Write Pythonic code that follows common best practices. The Faster CPython project optimizes for common code patterns we observe.



Q: Will CPython 3.11 use more memory?


A: Maybe not. We don’t expect memory use to exceed 20% more than 3.10. This is offset by memory optimizations for frame objects and object dictionaries as mentioned above.



Q: I don’t see any speedups in my workload. Why?


A: Certain code won’t have noticeable benefits. If your code spends most of its time on I/O operations, or already does most of its computation in a C extension library like numpy, there won’t be significant speedup. This project currently benefits pure-Python workloads the most.


Furthermore, the pyperformance figures are a geometric mean. Even within the pyperformance benchmarks, certain benchmarks have slowed down slightly, while others have sped up by nearly 2x!



Q: Is there a JIT compiler?


A: No. We’re still exploring other optimizations.

About

Faster CPython explores optimizations for . The main team is funded by Microsoft to work on this full-time. Pablo Galindo Salgado is also funded by Bloomberg LP to work on the project part-time. Finally, many contributors are volunteers from the community.

CPython bytecode changes

The bytecode now contains inline cache entries, which take the form of the newly-added instructions. Many opcodes expect to be followed by an exact number of caches, and instruct the interpreter to skip over them at runtime. Populated caches can look like arbitrary instructions, so great care should be taken when reading or modifying raw, adaptive bytecode containing quickened data.

New opcodes

  • , and , used in generators and co-routines.

  • , which avoids needing special caller-side code for closures.

  • , for use in certain loops where handling interrupts is undesirable.

  • , to create .

  • and , to handle the added in PEP 654.

  • , for use in exception handlers.

  • , a no-op, for internal tracing, debugging and optimization checks.

Replaced opcodes

Replaced Opcode[s]

New Opcode[s]

Notes

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
47

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
48

Replaced all numeric binary/in-place opcodes with a single opcode

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
50

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
51

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
52

Decouples argument shifting for methods from handling of keyword arguments; allows better specialization of calls

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
57

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
58

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
59

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
60

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
61

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
62

Stack manipulation instructions

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
65

Now performs check but doesn’t jump

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
67

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
68

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
69

See ;

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
73,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
74,
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
75 and
class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
76 variants for each direction

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
77

class Movie[TypedDict, total=False]:
   title: Required[str]
   year: int
78

block setup

All jump opcodes are now relative, including the existing and . The argument is now an offset from the current instruction rather than an absolute location.

Changed/removed opcodes

  • Changed and to no longer push an additional boolean value to indicate success/failure. Instead,

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    4 is pushed on failure in place of the tuple of extracted values.

  • Changed opcodes that work with exceptions to reflect them now being represented as one item on the stack instead of three [see gh-89874].

  • Removed

    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    86,
    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    87,
    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    88,
    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    89 and
    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    90.

Deprecated

This section lists Python APIs that have been deprecated in Python 3.11.

Deprecated C APIs are .

Language/Builtins

  • Chaining descriptors [introduced in bpo-19072] is now deprecated. It can no longer be used to wrap other descriptors such as . The core design of this feature was flawed and caused a number of downstream problems. To “pass-through” a , consider using the

    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    94 attribute that was added in Python 3.10. [Contributed by Raymond Hettinger in gh-89519.]

  • Octal escapes in string and bytes literals with values larger than

    class Movie[TypedDict, total=False]:
       title: Required[str]
       year: int
    
    95 [255 in decimal] now produce a . In a future Python version, they will raise a and eventually a . [Contributed by Serhiy Storchaka in gh-81548.]

  • The delegation of to is now deprecated. Calling

    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    01 when
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    02 implements
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    00 but not or now raises a . [Contributed by Zackery Spytz in bpo-44977.]

Modules

  • PEP 594 led to the deprecations of the following modules slated for removal in Python 3.13:

    [Contributed by Brett Cannon in bpo-47061 and Victor Stinner in gh-68966.]

  • The , and modules have been deprecated since at least Python 3.6. Their documentation and deprecation warnings have now been updated to note they will be removed in Python 3.12. [Contributed by Hugo van Kemenade in bpo-47022.]

  • The package and tool are now deprecated and may not be able to parse Python 3.10 or newer. See PEP 617, introducing the new PEG parser, for details. [Contributed by Victor Stinner in bpo-40360.]

  • Undocumented modules

    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    30,
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    31 and
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    32 are now deprecated. [Contributed by Serhiy Storchaka in bpo-47152.]

Standard Library

  • The following have been deprecated in since Python 3.2. Their deprecation warnings have now been updated to note they will be removed in Python 3.12:

    • the

      class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      34 class

    • the

      class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      35 property

    • the

      class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      36 method

    [Contributed by Hugo van Kemenade in bpo-45173.]

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    37 has been deprecated in the docstring since Python 3.2, and is not listed in the documentation. It now emits a and will be removed in Python 3.13. Use or instead. [Contributed by Hugo van Kemenade in bpo-46607.]

  • The older set of functions were deprecated in favor of the replacements added in Python 3.9 and will be removed in a future Python version, due to not supporting resources located within package subdirectories:

  • The function is deprecated and will be removed in Python 3.13. Use , and functions instead. [Contributed by Victor Stinner in gh-90817.]

  • The function is deprecated and will be removed in Python 3.13. Use

    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    55 instead. [Contributed by Victor Stinner in gh-90817.]

  • Stricter rules will now be applied for numerical group references and group names in . Only sequences of ASCII digits will now be accepted as a numerical reference, and the group name in patterns and replacement strings can only contain ASCII letters, digits and underscores. For now, a deprecation warning is raised for syntax violating these rules. [Contributed by Serhiy Storchaka in gh-91760.]

  • In the module, the

    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    58 function and the corresponding
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    59 and
    class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    60 flags are deprecated, as they were undocumented and lacked an obvious purpose. They will be removed in Python 3.13. [Contributed by Serhiy Storchaka and Miro Hrončok in gh-92728.]

  • has been deprecated since Python 3.1; it now emits a deprecation warning and will be removed in Python 3.13. Use instead [it was earlier incorrectly marked as deprecated, and its docstring is now corrected]. [Contributed by Hugo van Kemenade in bpo-45837.]

  • , which exists solely to provide compatibility support between Python 2 and Python 3 code, is now deprecated. Its removal is currently unplanned, but users are encouraged to use instead wherever possible. [Contributed by Alex Waygood in gh-92332.]

  • The keyword argument syntax for constructing types is now deprecated. Support will be removed in Python 3.13. [Contributed by Jingchen Ye in gh-90224.]

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    66 is deprecated and will be removed in Python 3.13. It is untested, undocumented, and not used by itself. [Contributed by Dong-hee Na in bpo-42255.]

  • The behavior of returning a value from a and test methods [other than the default

    Traceback [most recent call last]:
      File "calculation.py", line 54, in 
        result = [x / y / z] * [a / b / c]
                  ~~~~~~^~~
    ZeroDivisionError: division by zero
    
    4 value] is now deprecated.

  • Deprecated the following not-formally-documented functions, scheduled for removal in Python 3.13:

    • class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      72

    • class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      73

    • class MyLock:
          def __enter__[self] -> Self:
              self.lock[]
              return self
      
          ...
      
      class MyInt:
          @classmethod
          def fromhex[cls, s: str] -> Self:
              return cls[int[s, 16]]
      
          ...
      
      74

    Use methods instead:

    [Contributed by Erlend E. Aasland in bpo-5846.]

Pending Removal in Python 3.12

The following Python APIs have been deprecated in earlier Python releases, and will be removed in Python 3.12.

C APIs pending removal are .

  • The module

  • The module

  • The

  • The module

  • The namespace

  • The namespace

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    84

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    90

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    91

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    92

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    93

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    94

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    95

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    97

  • class MyLock:
        def __enter__[self] -> Self:
            self.lock[]
            return self
    
        ...
    
    class MyInt:
        @classmethod
        def fromhex[cls, s: str] -> Self:
            return cls[int[s, 16]]
    
        ...
    
    99

  • def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    00

  • def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    04

  • def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    05

  • environment variable

  • The following deprecated aliases in :

    Deprecated alias

    Method Name

    Deprecated in

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    08

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    10

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    12

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    14

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    16

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    18

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    20

    3.1

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    22

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    24

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    26

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    28

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    30

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    32

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    34

    3.2

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    36

    3.5

Removed

This section lists Python APIs that have been removed in Python 3.11.

Removed C APIs are .

  • Removed the

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    38 enabling legacy generator-based coroutines to be compatible with / code. The function has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10. Use instead. [Contributed by Illia Volochii in bpo-43216.]

  • Removed

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    42 used for wrapping legacy generator-based coroutine objects in the debug mode. [Contributed by Illia Volochii in bpo-43216.]

  • Due to significant security concerns, the reuse_address parameter of , disabled in Python 3.9, is now entirely removed. This is because of the behavior of the socket option

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    44 in UDP. [Contributed by Hugo van Kemenade in bpo-45129.]

  • Removed the

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    45 module, deprecated in Python 3.9. Also removed the related, similarly-deprecated functions:

    • def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      47

    • def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      48

    • def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      49

    • def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      50

    The function remains available.

    [Contributed by Victor Stinner in bpo-45085.]

  • Removed the

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    53 command deprecated in Python 3.9. Use
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    54 [wheel packages] instead. [Contributed by Hugo van Kemenade in bpo-45124.]

  • Removed the methods of , and , deprecated since Python 3.9. [Contributed by Hugo van Kemenade in bpo-45132.]

  • Removed the deprecated functions

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    60,
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    61,
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    62 and
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    63. Also removed the
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    64 function, the
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    65 and
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    66 methods, and the codeset parameter of
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    67 and
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    68, since they are only used for the
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    69 functions. [Contributed by Dong-hee Na and Serhiy Storchaka in bpo-44235.]

  • Removed from the module:

    • The

      def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      71 function, deprecated since Python 3.0; use or instead.

    • The

      def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      74 function, deprecated since Python 3.5; use the function or the object directly.

    • The undocumented

      def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      77 and
      def run_query[sql: LiteralString] -> ...
          ...
      
      def caller[
          arbitrary_string: str,
          query_string: LiteralString,
          table_name: LiteralString,
      ] -> None:
          run_query["SELECT * FROM students"]       # ok
          run_query[query_string]                   # ok
          run_query["SELECT * FROM " + table_name]  # ok
          run_query[arbitrary_string]               # type checker error
          run_query[                                # type checker error
              f"SELECT * FROM students WHERE name = {arbitrary_string}"
          ]
      
      78 methods, deprecated since Python 3.5; use the method instead.

    [Contributed by Hugo van Kemenade in bpo-45320.]

  • Removed the method from , because it was not used and added by mistake in previous versions. [Contributed by Nikita Sobolev in bpo-46483.]

  • Removed the

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    82 class in the module, as it is unusable without the external
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    84 package. [Contributed by Dong-hee Na in bpo-35800.]

  • Removed the deprecated

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    85 method of
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    86. [Contributed by Erlend E. Aasland in bpo-38371.]

  • Removed namespace package support from discovery. It was introduced in Python 3.4 but has been broken since Python 3.7. [Contributed by Inada Naoki in bpo-23882.]

  • Removed the undocumented private

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    88 method, previously known as
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    89 in Python 3.7. Its docstring said: “You probably don’t want to use this function. It exists mainly to be used in Python’s test suite.” [Contributed by Victor Stinner in bpo-46852.]

  • The

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    90 configure flag [and corresponding
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    91 macro] have been removed.

  • Pynche — The Pythonically Natural Color and Hue Editor — has been moved out of

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    92 and is being developed independently from the Python source tree.

Porting to Python 3.11

This section lists previously described changes and other bugfixes in the Python API that may require changes to your Python code.

Porting notes for the C API are .

  • , , and no longer accept

    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    97 [“universal newline”] in the file mode. In Python 3, “universal newline” mode is used by default whenever a file is opened in text mode, and the
    def run_query[sql: LiteralString] -> ...
        ...
    
    def caller[
        arbitrary_string: str,
        query_string: LiteralString,
        table_name: LiteralString,
    ] -> None:
        run_query["SELECT * FROM students"]       # ok
        run_query[query_string]                   # ok
        run_query["SELECT * FROM " + table_name]  # ok
        run_query[arbitrary_string]               # type checker error
        run_query[                                # type checker error
            f"SELECT * FROM students WHERE name = {arbitrary_string}"
        ]
    
    97 flag has been deprecated since Python 3.3. The to these functions controls how universal newlines work. [Contributed by Victor Stinner in bpo-37330.]

  • node positions are now validated when provided to and other related functions. If invalid positions are detected, a will be raised. [Contributed by Pablo Galindo in gh-93351]

  • Prohibited passing non- executors to following a deprecation in Python 3.8. [Contributed by Illia Volochii in bpo-43234.]

  • : The and classes now use , instead of using , if no locale is specified. [Contributed by Victor Stinner in bpo-46659.]

  • The module now reads the

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    10 configuration file with the
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    11 encoding. [Contributed by Srinivas Reddy Thatiparthy [శ్రీనివాస్ రెడ్డి తాటిపర్తి] in bpo-41137.]

  • The population parameter of must be a sequence, and automatic conversion of s to s is no longer supported. Also, if the sample size is larger than the population size, a is raised. [Contributed by Raymond Hettinger in bpo-40465.]

  • The random optional parameter of was removed. It was previously an arbitrary random function to use for the shuffle; now, [its previous default] will always be used.

  • In , global inline flags [e.g.

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    19] can now only be used at the start of regular expressions. Using them elsewhere has been deprecated since Python 3.6. [Contributed by Serhiy Storchaka in bpo-47066.]

  • In the module, several long-standing bugs where fixed that, in rare cases, could cause capture groups to get the wrong result. Therefore, this could change the captured output in these cases. [Contributed by Ma Lin in bpo-35859.]

Build Changes

  • CPython now has PEP 11 for cross compiling to the WebAssembly platforms Emscripten [

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    21, i.e. Python in the browser] and WebAssembly System Interface [WASI] [
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    22]. The effort is inspired by previous work like Pyodide. These platforms provide a limited subset of POSIX APIs; Python standard libraries features and modules related to networking, processes, threading, signals, mmap, and users/groups are not available or don’t work. [Emscripten contributed by Christian Heimes and Ethan Smith in gh-84461 and WASI contributed by Christian Heimes in gh-90473; platforms promoted in gh-95085]

  • Building Python now requires:

    • A C11 compiler. are not required. [Contributed by Victor Stinner in bpo-46656.]

    • Support for IEEE 754 floating point numbers. [Contributed by Victor Stinner in bpo-46917.]

    • Support for , as the

      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      23 macro has been removed. [Contributed by Victor Stinner in bpo-46656.]

    • A C99

      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      24 header file providing the
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      25,
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      26,
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      27,
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      28,
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      29, and
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      30 functions [contributed by Victor Stinner in bpo-45440]; and a
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      31 constant or the
      # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      32 function [Contributed by Victor Stinner in bpo-46640].

  • The package now requires Tcl/Tk version 8.5.12 or newer. [Contributed by Serhiy Storchaka in bpo-46996.]

  • Build dependencies, compiler flags, and linker flags for most stdlib extension modules are now detected by configure. libffi, libnsl, libsqlite3, zlib, bzip2, liblzma, libcrypt, Tcl/Tk, and uuid flags are detected by pkg-config [when available]. now requires a pkg-config command to detect development settings for Tcl/Tk headers and libraries. [Contributed by Christian Heimes and Erlend Egeberg Aasland in bpo-45847, bpo-45747, and bpo-45763.]

  • libpython is no longer linked against libcrypt. [Contributed by Mike Gilbert in bpo-45433.]

  • CPython can now be built with the ThinLTO option via passing

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    35 to , i.e.
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    37. [Contributed by Dong-hee Na and Brett Holman in bpo-44340.]

  • Freelists for object structs can now be disabled. A new configure option

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    38 can be used to disable all freelists except empty tuple singleton. [Contributed by Christian Heimes in bpo-45522.]

  • # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    39 and
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    40 have been improved and tied up. Extension modules can now be built through
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    41. All except some test modules can be linked statically into a main binary or library. [Contributed by Brett Cannon and Christian Heimes in bpo-45548, bpo-45570, bpo-45571, and bpo-43974.]

    Note

    Use the environment variables

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    42 and
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    43 to manually specify the location of Tcl/Tk headers and libraries. The configure options
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    44 and
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    45 have been removed.

    On RHEL 7 and CentOS 7 the development packages do not provide

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    46 and
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    47; use
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    48. The directory
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    49 contains
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    50 files and instructions on how to build Python with RHEL 7’s and CentOS 7’s Tcl/Tk and OpenSSL.

  • CPython will now use 30-bit digits by default for the Python implementation. Previously, the default was to use 30-bit digits on platforms with

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    52, and 15-bit digits otherwise. It’s still possible to explicitly request use of 15-bit digits via either the option to the configure script or [for Windows] the
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    54 variable in
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    55, but this option may be removed at some point in the future. [Contributed by Mark Dickinson in bpo-45569.]

C API Changes

New Features

  • Add a new function to get type’s short name. [Contributed by Hai Shi in bpo-42035.]

  • Add a new function to get type’s qualified name. [Contributed by Hai Shi in bpo-42035.]

  • Add new and functions to the limited C API to suspend and resume tracing and profiling. [Contributed by Victor Stinner in bpo-43760.]

  • Added the constant which bears the same value as . [Contributed by Gabriele N. Tornetta in bpo-43931.]

  • and APIs are now part of the limited API and the stable ABI:

    • # The create_model decorator is defined by a library.
      @typing.dataclass_transform[]
      def create_model[cls: Type[T]] -> Type[T]:
          cls.__init__ = ...
          cls.__eq__ = ...
          cls.__ne__ = ...
          return cls
      
      # The create_model decorator can now be used to create new model classes:
      @create_model
      class CustomerModel:
          id: int
          name: str
      
      c = CustomerModel[id=327, name="Eric Idle"]
      
      69

    • and type slots

    [Contributed by Christian Heimes in bpo-45459.]

  • Added the function, used to get the module in which a method was defined, in cases where this information is not available directly [via ]. [Contributed by Petr Viktorin in bpo-46613.]

  • Add new functions to pack and unpack C double [serialize and deserialize]: , , , , and . [Contributed by Victor Stinner in bpo-46906.]

  • Add new functions to get frame object attributes: , , , .

  • Added two new functions to get and set the active exception instance: and . These are alternatives to and which work with the legacy 3-tuple representation of exceptions. [Contributed by Irit Katriel in bpo-46343.]

  • Added the member. [Contributed by Victor Stinner in gh-57684.]

Porting to Python 3.11

  • Some macros have been converted to static inline functions to avoid macro pitfalls. The change should be mostly transparent to users, as the replacement functions will cast their arguments to the expected types to avoid compiler warnings due to static type checks. However, when the limited C API is set to >=3.11, these casts are not done, and callers will need to cast arguments to their expected types. See PEP 670 for more details. [Contributed by Victor Stinner and Erlend E. Aasland in gh-89653.]

  • no longer uses the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    24 and
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    25 arguments, the interpreter now derives those values from the exception instance [the
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    26 argument]. The function still steals references of all three arguments. [Contributed by Irit Katriel in bpo-45711.]

  • now derives the

    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    24 and
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    25 fields of the result from the exception instance [the
    class Movie[TypedDict]:
       title: str
       year: NotRequired[int]
    
    m1: Movie = {"title": "Black Panther", "year": 2018}  # OK
    m2: Movie = {"title": "Star Wars"}  # OK [year is not required]
    m3: Movie = {"year": 2022}  # ERROR [missing required field title]
    
    26 field]. [Contributed by Irit Katriel in bpo-45711.]

  • has a new

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    03 field to indicate whether or not the frozen module is a package. Previously, a negative value in the
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    04 field was the indicator. Now only non-negative values be used for
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    04. [Contributed by Kumar Aditya in bpo-46608.]

  • now takes

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    07 as its second parameter, instead of
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    08. See PEP 523 for more details of how to use this function pointer type.

  • and now take an additional

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    11 argument. Using these functions should be avoided, if at all possible. To get a custom code object: create a code object using the compiler, then get a modified version with the
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    12 method.

  • no longer has the

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    14,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    15,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    16 and
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    17 fields. Instead, use , , and respectively to access them via the C API. [Contributed by Brandt Bucher in bpo-46841 and Ken Jin in gh-92154 and gh-94936.]

  • The old trashcan macros [

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    22/
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    23] are now deprecated. They should be replaced by the new macros
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    24 and
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    25.

    A tp_dealloc function that has the old macros, such as:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    1

    should migrate to the new macros as follows:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    2

    Note that

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    24 has a second argument which should be the deallocation function it is in.

    To support older Python versions in the same codebase, you can define the following macros and use them throughout the code [credit: these were copied from the

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    27 codebase]:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    3

  • The function now raises an error if a type is defined with the flag set but has no traverse function []. [Contributed by Victor Stinner in bpo-44263.]

  • Heap types with the flag can now inherit the PEP 590 vectorcall protocol. Previously, this was only possible for . [Contributed by Erlend E. Aasland in bpo-43908]

  • Since is changed to a inline static function,

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    33 must be replaced with
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    34: see the function [available since Python 3.9]. For backward compatibility, this macro can be used:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    4

    [Contributed by Victor Stinner in bpo-39573.]

  • Since is changed to a inline static function,

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    37 must be replaced with
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    38: see the function [available since Python 3.9]. For backward compatibility, this macro can be used:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    5

    [Contributed by Victor Stinner in bpo-39573.]

  • >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    40 no longer includes the header files
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    41,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    42,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    43 and
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    44 when the
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    45 macro is set to
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    46 [Python 3.11] or higher. C extensions should explicitly include the header files after
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    47. [Contributed by Victor Stinner in bpo-45434.]

  • The non-limited API files

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    48,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    49,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    50,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    51,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    52,
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    53 and
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    54 have been moved to the
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    55 directory. Moreover, the
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    56 header file was removed. These files must not be included directly, as they are already included in
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    57: . If they have been included directly, consider including
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    57 instead. [Contributed by Victor Stinner in bpo-35134.]

  • The

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    59 macro has been excluded from the limited C API. It was never usable there, because it used internal structures which are not available in the limited C API. [Contributed by Victor Stinner in bpo-46007.]

  • The following frame functions and type are now directly available with

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    47, it’s no longer needed to add
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    61:

    [Contributed by Victor Stinner in gh-93937.]

  • The structure members have been removed from the public C API.

    While the documentation notes that the fields are subject to change at any time, they have been stable for a long time and were used in several popular extensions.

    In Python 3.11, the frame struct was reorganized to allow performance optimizations. Some fields were removed entirely, as they were details of the old implementation.

    fields:

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      73: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      75: removed.

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      76: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      78: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      80: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      82: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      84: removed.

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      85: use . Code using
      >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      85 with
      >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      88 should use instead; it may be faster.

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      90: use

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      92: use .

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      94: removed.

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      95: no public API [renamed to
      >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      96].

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      97: no public API.

    • >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      98: use
      >>> from functools import singledispatch
      >>> @singledispatch
      ... def fun[arg, verbose=False]:
      ...     if verbose:
      ...         print["Let me just say,", end=" "]
      ...     print[arg]
      ...
      >>> @fun.register
      ... def _[arg: int | float, verbose=False]:
      ...     if verbose:
      ...         print["Strength in numbers, eh?", end=" "]
      ...     print[arg]
      ...
      >>> from typing import Union
      >>> @fun.register
      ... def _[arg: Union[list, set], verbose=False]:
      ...     if verbose:
      ...         print["Enumerate this:"]
      ...     for i, elem in enumerate[arg]:
      ...         print[i, elem]
      ...
      
      99.

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      00: use
      Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      01.

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      02: no public API [renamed to
      Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      03].

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      04: removed.

    The Python frame object is now created lazily. A side effect is that the

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    73 member must not be accessed directly, since its value is now also computed lazily. The function must be called instead.

    Debuggers that accessed the

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    92 directly must call instead. They no longer need to call
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    09 or
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    10, in fact they should not call those functions. The necessary updating of the frame is now managed by the virtual machine.

    Code defining

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    79 on Python 3.8 and older:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    6

    Code defining

    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    63 on Python 3.8 and older:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    7

    Or use the pythoncapi_compat project to get these two functions on older Python versions.

  • Changes of the structure members:

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      14: removed, use [function added to Python 3.9 by bpo-40429]. Warning: the function returns a , need to call .

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      17: changed, use and [functions added to Python 3.11 by bpo-43760].

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      20: removed, use
      Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      21 instead.

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      22: removed.

    Code defining

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    15 on Python 3.8 and older:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    8

    Code defining

    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    58 and
    # The create_model decorator is defined by a library.
    @typing.dataclass_transform[]
    def create_model[cls: Type[T]] -> Type[T]:
        cls.__init__ = ...
        cls.__eq__ = ...
        cls.__ne__ = ...
        return cls
    
    # The create_model decorator can now be used to create new model classes:
    @create_model
    class CustomerModel:
        id: int
        name: str
    
    c = CustomerModel[id=327, name="Eric Idle"]
    
    59 on Python 3.10 and older:

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    9

    Or use the pythoncapi_compat project to get these functions on old Python functions.

  • Distributors are encouraged to build Python with the optimized Blake2 library libb2.

  • The field must now be set to 1 for initialization to use to initialize . Otherwise, initialization will recalculate the path and replace any values added to

    Traceback [most recent call last]:
      File "query.py", line 37, in 
        magic_arithmetic['foo']
      File "query.py", line 18, in magic_arithmetic
        return add_counts[x] / 25
               ^^^^^^^^^^^^^
      File "query.py", line 24, in add_counts
        return 25 + query_user[user1] + query_user[user2]
                    ^^^^^^^^^^^^^^^^^
      File "query.py", line 32, in query_user
        return 1 + query_count[db, response['a']['b']['c']['user'], retry=True]
                                   ~~~~~~~~~~~~~~~~~~^^^^^
    TypeError: 'NoneType' object is not subscriptable
    
    33.

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    30 no longer calculates the initial search path, and will not fill any values into . To calculate default paths and then modify them, finish initialization and use to retrieve as a Python list object and modify it directly.

Deprecated

  • Deprecate the following functions to configure the Python initialization:

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      37

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      45

    Use the new API of the instead [PEP 587]. [Contributed by Victor Stinner in gh-88279.]

  • Deprecate the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    47 member of the . Use instead. [Contributed by Inada Naoki in bpo-46864.]

Pending Removal in Python 3.12

The following C APIs have been deprecated in earlier Python releases, and will be removed in Python 3.12.

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    58

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    59

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    61

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    62

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    65

Removed

  • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    66 and
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    67 have been removed. [Contributed by Mark Shannon in bpo-40222.]

  • Remove the following math macros using the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    68 variable:

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      69

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      70

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      71

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      72

    • Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      73

    [Contributed by Victor Stinner in bpo-45412.]

  • Remove

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    74 and
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    75 macros, deprecated since Python 3.3. Use
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    76 or
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    77 [
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    78 string], and
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    79 functions instead. [Contributed by Victor Stinner in bpo-41123.]

  • Remove the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    80 header file. It only contains private functions. C extensions should only include the main
    >>> from functools import singledispatch
    >>> @singledispatch
    ... def fun[arg, verbose=False]:
    ...     if verbose:
    ...         print["Let me just say,", end=" "]
    ...     print[arg]
    ...
    >>> @fun.register
    ... def _[arg: int | float, verbose=False]:
    ...     if verbose:
    ...         print["Strength in numbers, eh?", end=" "]
    ...     print[arg]
    ...
    >>> from typing import Union
    >>> @fun.register
    ... def _[arg: Union[list, set], verbose=False]:
    ...     if verbose:
    ...         print["Enumerate this:"]
    ...     for i, elem in enumerate[arg]:
    ...         print[i, elem]
    ...
    
    40 header file. [Contributed by Victor Stinner in bpo-45434.]

  • Remove the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    82 macro. It was used by the
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    83 macro. [Contributed by Victor Stinner in bpo-45440.]

  • The following items are no longer available when is defined:

    • the

      Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
      
      89 macro

    These are not part of the .

    [Contributed by Victor Stinner in bpo-45474.]

  • Exclude from the limited C API. It never worked since the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    91 structure is opaque in the limited C API. [Contributed by Victor Stinner in bpo-35134.]

  • Remove the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    92 macro. It was exposed in the public C API by mistake, it must only be used by Python internally. Use the
    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    93 member instead. [Contributed by Victor Stinner in bpo-40170.]

  • Remove the

    Read __pycache__ -> Unmarshal -> Heap allocated code object -> Evaluate
    
    94 macro [moved to the internal C API]. [Contributed by Victor Stinner in bpo-45412.]

  • Remove the encoder APIs, as they have been deprecated since Python 3.3, are little used and are inefficient relative to the recommended alternatives.

Chủ Đề