Skip to content

Latest commit

 

History

History
562 lines (414 loc) · 21.6 KB

3.13.rst

File metadata and controls

562 lines (414 loc) · 21.6 KB

What's New In Python 3.13

Release:|release|
Date: |today|

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

New Modules

  • None yet.

Improved Modules

array

  • Add 'w' type code 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`.)

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`.)

pathlib

traceback

typing

Optimizations

Deprecated

  • :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`.)
  • Creating a :class:`typing.NamedTuple` class using keyword arguments to denote the fields (NT = NamedTuple("NT", x=int, y=int)) is deprecated, and will be disallowed in Python 3.15. Use the class-based syntax or the functional syntax instead. (Contributed by Alex Waygood in :gh:`105566`.)
  • When using the functional syntax to create a :class:`typing.NamedTuple` class or a :class:`typing.TypedDict` class, failing to pass a value to the 'fields' parameter (NT = NamedTuple("NT") or TD = TypedDict("TD")) is deprecated. Passing None to the 'fields' parameter (NT = NamedTuple("NT", None) or TD = TypedDict("TD", 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", []). To create a TypedDict class with 0 fields, use class TD(TypedDict): pass or TD = TypedDict("TD", {}). (Contributed by Alex Waygood in :gh:`105566` and :gh:`105570`.)
  • :mod:`array`'s 'u' format code, deprecated in docs since Python 3.3, emits :exc:`DeprecationWarning` since 3.13 and will be removed in Python 3.16. Use the 'w' format code instead. (contributed by Hugo van Kemenade in :gh:`80480`)
  • :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType` and :func:`!ctypes.ARRAY` functions. Replace ctypes.SetPointerType(item_type, size) with item_type * size. (Contributed by Victor Stinner in :gh:`105733`.)

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