Skip to content

Latest commit

 

History

History
1137 lines (871 loc) · 46.6 KB

3.13.rst

File metadata and controls

1137 lines (871 loc) · 46.6 KB

What's New In Python 3.13

Editor:TBD

This article explains the new features in Python 3.13, compared to 3.12.

For full details, see the :ref:`changelog <changelog>`.

Note

Prerelease users should be aware that this document is currently in draft form. It will be updated substantially as Python 3.13 moves towards release, so it's worth checking back even after reading earlier versions.

Summary -- Release highlights

New Features

Other Language Changes

  • Allow the count argument of :meth:`str.replace` to be a keyword. (Contributed by Hugo van Kemenade in :gh:`106487`.)
  • Compiler now strip indents from docstrings. This will reduce the size of :term:`bytecode cache <bytecode>` (e.g. .pyc file). For example, cache file size for sqlalchemy.orm.session in SQLAlchemy 2.0 is reduced by about 5%. This change will affect tools using docstrings, like :mod:`doctest`. (Contributed by Inada Naoki in :gh:`81283`.)
  • The :func:`compile` built-in can now accept a new flag, ast.PyCF_OPTIMIZED_AST, which is similar to ast.PyCF_ONLY_AST except that the returned AST is optimized according to the value of the optimize argument. (Contributed by Irit Katriel in :gh:`108113`).

New Modules

  • None yet.

Improved Modules

ast

array

  • Add 'w' type code (Py_UCS4) that can be used for Unicode strings. It can be used instead of 'u' type code, which is deprecated. (Contributed by Inada Naoki in :gh:`80480`.)

dbm

io

The :class:`io.IOBase` finalizer now logs the close() method errors with :data:`sys.unraisablehook`. Previously, errors were ignored silently by default, and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python built on debug mode <debug-build>`. (Contributed by Victor Stinner in :gh:`62948`.)

opcode

  • Move opcode.ENABLE_SPECIALIZATION to _opcode.ENABLE_SPECIALIZATION. This field was added in 3.12, it was never documented and is not intended for external usage. (Contributed by Irit Katriel in :gh:`105481`.)
  • Removed opcode.is_pseudo, opcode.MIN_PSEUDO_OPCODE and opcode.MAX_PSEUDO_OPCODE, which were added in 3.12, were never documented or exposed through dis, and were not intended to be used externally.

pathlib

sqlite3

tkinter

traceback

typing

Optimizations

Deprecated

Pending Removal in Python 3.14

Pending Removal in Python 3.15

  • :class:`typing.NamedTuple`:
    • The undocumented keyword argument syntax for creating NamedTuple classes (NT = NamedTuple("NT", x=int)) is deprecated, and will be disallowed in 3.15. Use the class-based syntax or the functional syntax instead.
    • When using the functional syntax to create a NamedTuple class, failing to pass a value to the 'fields' parameter (NT = NamedTuple("NT")) is deprecated. Passing None to the 'fields' parameter (NT = NamedTuple("NT", None)) is also deprecated. Both will be disallowed in Python 3.15. To create a NamedTuple class with 0 fields, use class NT(NamedTuple): pass or NT = NamedTuple("NT", []).
  • :class:`typing.TypedDict`: When using the functional syntax to create a TypedDict class, failing to pass a value to the 'fields' parameter (TD = TypedDict("TD")) is deprecated. Passing None to the 'fields' parameter (TD = TypedDict("TD", None)) is also deprecated. Both will be disallowed in Python 3.15. To create a TypedDict class with 0 fields, use class TD(TypedDict): pass or TD = TypedDict("TD", {}).
  • :mod:`wave`: Deprecate the getmark(), setmark() and getmarkers() methods of the :class:`wave.Wave_read` and :class:`wave.Wave_write` classes. They will be removed in Python 3.15. (Contributed by Victor Stinner in :gh:`105096`.)
  • Passing any arguments to :func:`threading.RLock` is now deprecated. C version allows any numbers of args and kwargs, but they are just ignored. Python version does not allow any arguments. All arguments will be removed from :func:`threading.RLock` in Python 3.15. (Contributed by Nikita Sobolev in :gh:`102029`.)

Pending Removal in Python 3.16

Pending Removal in Future Versions

The following APIs were deprecated in earlier Python versions and will be removed, although there is currently no date scheduled for their removal.

Removed

Porting to Python 3.13

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

  • The old trashcan macros Py_TRASHCAN_SAFE_BEGIN and Py_TRASHCAN_SAFE_END were removed. They should be replaced by the new macros Py_TRASHCAN_BEGIN and Py_TRASHCAN_END.

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

    static void
    mytype_dealloc(mytype *p)
    {
        PyObject_GC_UnTrack(p);
        Py_TRASHCAN_SAFE_BEGIN(p);
        ...
        Py_TRASHCAN_SAFE_END
    }
    

    should migrate to the new macros as follows:

    static void
    mytype_dealloc(mytype *p)
    {
        PyObject_GC_UnTrack(p);
        Py_TRASHCAN_BEGIN(p, mytype_dealloc)
        ...
        Py_TRASHCAN_END
    }
    

    Note that Py_TRASHCAN_BEGIN has a second argument which should be the deallocation function it is in.

Build Changes

C API Changes

New Features

Porting to Python 3.13

Deprecated

Removed

Pending Removal in Python 3.14

Pending Removal in Python 3.15

Pending Removal in Future Versions

The following APIs were deprecated in earlier Python versions and will be removed, although there is currently no date scheduled for their removal.