Skip to content

Latest commit

 

History

History
1503 lines (1150 loc) · 60.8 KB

3.13.rst

File metadata and controls

1503 lines (1150 loc) · 60.8 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

Important deprecations, removals or restrictions:

New Features

Other Language Changes

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

copy

dbm

doctest

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.

os

pathlib

pdb

  • Add ability to move between chained exceptions during post mortem debugging in :func:`~pdb.pm` using the new exceptions [exc_number] command for Pdb. (Contributed by Matthias Bussonnier in :gh:`106676`.)
  • Expressions/Statements whose prefix is a pdb command are now correctly identified and executed. (Contributed by Tian Gao in :gh:`108464`.)

sqlite3

tkinter

traceback

typing

venv

  • Add support for adding source control management (SCM) ignore files to a virtual environment's directory. By default, Git is supported. This is implemented as opt-in via the API which can be extended to support other SCMs (:class:`venv.EnvBuilder` and :func:`venv.create`), and opt-out via the CLI (using --without-scm-ignore-files). (Contributed by Brett Cannon in :gh:`108125`.)

Optimizations

Deprecated

Pending Removal in Python 3.14

Pending Removal in Python 3.15

  • :class:`http.server.CGIHTTPRequestHandler` will be removed along with its related --cgi flag to python -m http.server. It was obsolete and rarely used. No direct replacement exists. Anything is better than CGI to interface a web server with a request handler.
  • :class:`locale`: :func:`locale.getdefaultlocale` was deprecated in Python 3.11 and originally planned for removal in Python 3.13 (:gh:`90817`), but removal has been postponed to Python 3.15. Use :func:`locale.setlocale()`, :func:`locale.getencoding()` and :func:`locale.getlocale()` instead. (Contributed by Hugo van Kemenade in :gh:`111187`.)
  • :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

PEP 594: dead batteries

2to3

configparser

importlib

locale

  • Remove locale.resetlocale() function deprecated in Python 3.11: use locale.setlocale(locale.LC_ALL, "") instead. (Contributed by Victor Stinner in :gh:`104783`.)

logging

pathlib

  • Remove support for using :class:`pathlib.Path` objects as context managers. This functionality was deprecated and made a no-op in Python 3.9.

re

  • Remove undocumented, never working, and deprecated re.template function and re.TEMPLATE flag (and re.T alias). (Contributed by Serhiy Storchaka and Nikita Sobolev in :gh:`105687`.)

tkinter

  • Remove the :mod:`!tkinter.tix` module, deprecated in Python 3.6. The third-party Tix library which the module wrapped is unmaintained. (Contributed by Zachary Ware in :gh:`75552`.)

turtle

typing

  • Namespaces typing.io and typing.re, deprecated in Python 3.8, are now removed. The items in those namespaces can be imported directly from :mod:`typing`. (Contributed by Sebastian Rittau in :gh:`92871`.)
  • Remove support for the keyword-argument method of creating :class:`typing.TypedDict` types, deprecated in Python 3.11. (Contributed by Tomas Roun in :gh:`104786`.)

unittest

urllib

webbrowser

Others

  • None yet

CPython bytecode changes

  • The oparg of YIELD_VALUE is now 1 if the yield is part of a yield-from or await, and 0 otherwise. The oparg of RESUME was changed to add a bit indicating whether the except-depth is 1, which is needed to optimize closing of generators. (Contributed by Irit Katriel in :gh:`111354`.)

Porting to Python 3.13

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

Changes in the Python API

  • :meth:`!tkinter.Text.count` now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0. (Contributed by Serhiy Storchaka in :gh:`97928`.)

Build Changes

C API Changes

New Features

Porting to Python 3.13

  • Python.h no longer includes the <ieeefp.h> standard header. It was included for the finite() function which is now provided by the <math.h> header. It should now be included explicitly if needed. Remove also the HAVE_IEEEFP_H macro. (Contributed by Victor Stinner in :gh:`108765`.)

  • Python.h no longer includes the <unistd.h> standard header file. If needed, it should now be included explicitly. For example, it provides the functions: read(), write(), close(), isatty(), lseek(), getpid(), getcwd(), sysconf(), getpagesize(), alarm() and pause(). As a consequence, _POSIX_SEMAPHORES and _POSIX_THREADS macros are no longer defined by Python.h. The HAVE_UNISTD_H and HAVE_PTHREAD_H macros defined by Python.h can be used to decide if <unistd.h> and <pthread.h> header files can be included. (Contributed by Victor Stinner in :gh:`108765`.)

  • Python.h no longer includes these standard header files: <time.h>, <sys/select.h> and <sys/time.h>. If needed, they should now be included explicitly. For example, <time.h> provides the clock() and gmtime() functions, <sys/select.h> provides the select() function, and <sys/time.h> provides the futimes(), gettimeofday() and setitimer() functions. (Contributed by Victor Stinner in :gh:`108765`.)

  • Python.h no longer includes the <ctype.h> standard header file. If needed, it should now be included explicitly. For example, it provides isalpha() and tolower() functions which are locale dependent. Python provides locale independent functions, like :c:func:`!Py_ISALPHA` and :c:func:`!Py_TOLOWER`. (Contributed by Victor Stinner in :gh:`108765`.)

  • If the :c:macro:`Py_LIMITED_API` macro is defined, :c:macro:`!Py_BUILD_CORE`, :c:macro:`!Py_BUILD_CORE_BUILTIN` and :c:macro:`!Py_BUILD_CORE_MODULE` macros are now undefined by <Python.h>. (Contributed by Victor Stinner in :gh:`85283`.)

  • 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.

  • The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the string contains embedded null characters. To accept embedded null characters and truncate on purpose at the first null byte, PyUnicode_AsUTF8AndSize(unicode, NULL) can be used instead. (Contributed by Victor Stinner in :gh:`111089`.)

  • On Windows, Python.h no longer includes the <stddef.h> standard header file. If needed, it should now be included explicitly. For example, it provides offsetof() function, and size_t and ptrdiff_t types. Including <stddef.h> explicitly was already needed by all other platforms, the HAVE_STDDEF_H macro is only defined on Windows. (Contributed by Victor Stinner in :gh:`108765`.)

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.

Regression Test Changes