10000 [3.13] GH-109975: Copyedit 3.13 What's New: Porting to Python 3.13 (G… · python/cpython@779a35b · GitHub
[go: up one dir, main page]

Skip to content

Commit 779a35b

Browse files
[3.13] GH-109975: Copyedit 3.13 What's New: Porting to Python 3.13 (GH-124341) (#124357)
GH-109975: Copyedit 3.13 What's New: Porting to Python 3.13 (GH-124341) Copyedit Porting to Python 3.13 (cherry picked from commit 2f6d410) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent de8dc92 commit 779a35b

File tree

1 file changed

+104
-85
lines changed

1 file changed

+104
-85
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 104 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ old generation, instead of collecting one or more generations.
510510

511511
The behavior of :func:`!gc.collect` changes slightly:
512512

513-
* ``gc.collect(1)``: Performs an increment of GC,
513+
* ``gc.collect(1)``: Performs an increment of garbage collection,
514514
rather than collecting generation 1.
515515
* Other calls to :func:`!gc.collect` are unchanged.
516516

@@ -2248,6 +2248,19 @@ Changed C APIs
22482248
non-ASCII keyword parameter names.
22492249
(Contributed by Serhiy Storchaka in :gh:`110815`.)
22502250

2251+
* The :c:func:`!PyCode_GetFirstFree` function is now unstable API
2252+
and is now named :c:func:`PyUnstable_Code_GetFirstFree`.
2253+
(Contributed by Bogdan Romanyuk in :gh:`115781`.)
2254+
2255+
* The :c:func:`PyDict_GetItem`, :c:func:`PyDict_GetItemString`,
2256+
:c:func:`PyMapping_HasKey`, :c:func:`PyMapping_HasKeyString`,
2257+
:c:func:`PyObject_HasAttr`, :c:func:`PyObject_HasAttrString`,
2258+
and :c:func:`PySys_GetObject` functions,
2259+
each of which clears all errors which occurred when calling them
2260+
now reports these errors using :func:`sys.unraisablehook`.
2261+
You may replace them with other functions as recommended in the documentation.
2262+
(Contributed by Serhiy Storchaka in :gh:`106672`.)
2263+
22512264
* Add support for the ``%T``, ``%#T``, ``%N`` and ``%#N`` formats
22522265
to :c:func:`PyUnicode_FromFormat`:
22532266

@@ -2553,63 +2566,75 @@ that may require changes to your code.
25532566
Changes in the Python API
25542567
-------------------------
25552568

2556-
* An :exc:`OSError` is now raised by :func:`getpass.getuser` for any failure to
2557-
retrieve a username, instead of :exc:`ImportError` on non-Unix platforms or
2558-
:exc:`KeyError` on Unix platforms where the password database is empty.
2569+
.. _pep667-porting-notes-py:
25592570

2560-
* The :mod:`threading` module now expects the :mod:`!_thread` module to have
2561-
an ``_is_main_interpreter`` attribute. It is a function with no
2562-
arguments that returns ``True`` if the current interpreter is the
2563-
main interpreter.
2571+
* :ref:`PEP 667 <whatsnew313-locals-semantics>` introduces several changes
2572+
to the semantics of :func:`locals` and :attr:`f_locals <frame.f_locals>`:
2573+
2574+
* Calling :func:`locals` in an :term:`optimized scope` now produces an
2575+
independent snapshot on each call, and hence no longer implicitly updates
2576+
previously returned references. Obtaining the legacy CPython behaviour now
2577+
requires explicit calls to update the initially returned dictionary with the
2578+
results of subsequent calls to :func:`!locals`. Code execution functions that
2579+
implicitly target :func:`!locals` (such as ``exec`` and ``eval``) must be
2580+
passed an explicit namespace to access their results in an optimized scope.
2581+
(Changed as part of :pep:`667`.)
2582+
2583+
* Calling :func:`locals` from a comprehension at module or class scope
2584+
(including via ``exec`` or ``eval``) once more behaves as if the comprehension
2585+
were running as an independent nested function (i.e. the local variables from
2586+
the containing scope are not included). In Python 3.12, this had changed
2587+
to include the local variables from the containing scope when implementing
2588+
:pep:`709`. (Changed as part of :pep:`667`.)
2589+
2590+
* Accessing :attr:`FrameType.f_locals <frame.f_locals>` in an
2591+
:term:`optimized scope` now returns a write-through proxy rather than a
2592+
snapshot that gets updated at ill-specified times. If a snapshot is desired,
2593+
it must be created explicitly with ``dict`` or the proxy's ``.copy()`` method.
2594+
(Changed as part of :pep:`667`.)
2595+
2596+
* :class:`functools.partial` now emits a :exc:`FutureWarning`
2597+
when used as a method.
2598+
The behavior will change in future Python versions.
2599+
Wrap it in :func:`staticmethod` if you want to preserve the old behavior.
2600+
(Contributed by Serhiy Storchaka in :gh:`121027`.)
25642601

2565-
Any library or application that provides a custom ``_thread`` module
2566-
must provide :func:`!_is_main_interpreter`, just like the module's
2567-
other "private" attributes.
2568-
(See :gh:`112826`.)
2602+
* The :ref:`garbage collector is now incremental <whatsnew313-incremental-gc>`,
2603+
which means that the behavior of :func:`gc.collect` changes slightly:
25692604

2570-
* :class:`mailbox.Maildir` now ignores files with a leading dot.
2571-
(Contributed by Zackery Spytz in :gh:`65559`.)
2605+
* ``gc.collect(1)``: Performs an increment of garbage collection,
2606+
rather than collecting generation 1.
2607+
* Other calls to :func:`!gc.collect` are unchanged.
25722608

2573-
* :meth:`pathlib.Path.glob` and :meth:`~pathlib.Path.rglob` now return both
2574-
files and directories if a pattern that ends with "``**``" is given, rather
2575-
than directories only. Users may add a trailing slash to match only
2576-
directories.
2609+
* An :exc:`OSError` is now raised by :func:`getpass.getuser`
2610+
for any failure to retrieve a username,
2611+
instead of :exc:`ImportError` on non-Unix platforms
2612+
or :exc:`KeyError` on Unix platforms where the password database is empty.
25772613

2578-
* The value of the :attr:`!mode` attribute of :class:`gzip.GzipFile` was
2579-
changed from integer (``1`` or ``2``) to string (``'rb'`` or ``'wb'``).
2614+
* The value of the :attr:`!mode` attribute of :class:`gzip.GzipFile`
2615+
is now a string (``'rb'`` or ``'wb'``) instead of an integer (``1`` or ``2``).
25802616
The value of the :attr:`!mode` attribute of the readable file-like object
2581-
returned by :meth:`zipfile.ZipFile.open` was changed from ``'r'`` to ``'rb'``.
2617+
returned by :meth:`zipfile.ZipFile.open` is now ``'rb'`` instead of ``'r'``.
25822618
(Contributed by Serhiy Storchaka in :gh:`115961`.)
25832619

2584-
* :class:`functools.partial` now emits a :exc:`FutureWarning` when it is
2585-
used as a method.
2586-
Its behavior will be changed in future Python versions.
2587-
Wrap it in :func:`staticmethod` if you want to preserve the old behavior.
2588-
(Contributed by Serhiy Storchaka in :gh:`121027`.)
2620+
* :class:`mailbox.Maildir` now ignores files with a leading dot (``.``).
2621+
(Contributed by Zackery Spytz in :gh:`65559`.)
25892622

2590-
.. _pep667-porting-notes-py:
2623+
* :meth:`pathlib.Path.glob` and :meth:`~pathlib.Path.rglob` now return both
2624+
files and directories if a pattern that ends with "``**``" is given,
2625+
rather than directories only.
2626+
Add a trailing slash to keep the previous behavior and only match directories.
2627+
2628+
* The :mod:`threading` module now expects the :mod:`!_thread` module
2629+
to have an :func:`!_is_main_interpreter` function.
2630+
This function takes no arguments and returns ``True``
2631+
if the current interpreter is the main interpreter.
2632+
2633+
Any library or application that provides a custom :mod:`!_thread` module
2634+
must provide :func:`!_is_main_interpreter`,
2635+
just like the module's other "private" attributes.
2636+
(:gh:`112826`.)
25912637

2592-
* Calling :func:`locals` in an :term:`optimized scope` now produces an
2593-
independent snapshot on each call, and hence no longer implicitly updates
2594-
previously returned references. Obtaining the legacy CPython behaviour now
2595-
requires explicit calls to update the initially returned dictionary with the
2596-
results of subsequent calls to :func:`!locals`. Code execution functions that
2597-
implicitly target :func:`!locals` (such as ``exec`` and ``eval``) must be
2598-
passed an explicit namespace to access their results in an optimized scope.
2599-
(Changed as part of :pep:`667`.)
2600-
2601-
* Calling :func:`locals` from a comprehension at module or class scope
2602-
(including via ``exec`` or ``eval``) once more behaves as if the comprehension
2603-
were running as an independent nested function (i.e. the local variables from
2604-
the containing scope are not included). In Python 3.12, this had changed
2605-
to include the local variables from the containing scope when implementing
2606-
:pep:`709`. (Changed as part of :pep:`667`.)
2607-
2608-
* Accessing :attr:`FrameType.f_locals <frame.f_locals>` in an
2609-
:term:`optimized scope` now returns a write-through proxy rather than a
2610-
snapshot that gets updated at ill-specified times. If a snapshot is desired,
2611-
it must be created explicitly with ``dict`` or the proxy's ``.copy()`` method.
2612-
(Changed as part of :pep:`667`.)
26132638

26142639
Changes in the C API
26152640
--------------------
@@ -2671,45 +2696,39 @@ Changes in the C API
26712696
added in Python 3.8 and the old macros were deprecated in Python 3.11.
26722697
(Contributed by Irit Katriel in :gh:`105111`.)
26732698

2674-
* Functions :c:func:`PyDict_GetItem`, :c:func:`PyDict_GetItemString`,
2675-
:c:func:`PyMapping_HasKey`, :c:func:`PyMapping_HasKeyString`,
2676-
:c:func:`PyObject_HasAttr`, :c:func:`PyObject_HasAttrString`, and
2677-
:c:func:`PySys_GetObject`, which clear all errors which occurred when calling
2678-
them, now report them using :func:`sys.unraisablehook`.
2679-
You may replace them with other functions as
2680-
recommended in the documentation.
2681-
(Contributed by Serhiy Storchaka in :gh:`106672`.)
2682-
2683-
* :c:func:`!PyCode_GetFirstFree` is an unstable API now and has been renamed
2684-
to :c:func:`PyUnstable_Code_GetFirstFree`.
2685-
(Contributed by Bogdan Romanyuk in :gh:`115781`.)
2686-
26872699
.. _pep667-porting-notes-c:
26882700

2689-
* The effects of mutating the dictionary returned from :c:func:`PyEval_GetLocals` in an
2690-
:term:`optimized scope` have changed. New dict entries added this way will now *only* be
2691-
visible to subsequent :c:func:`PyEval_GetLocals` calls in that frame, as
2692-
:c:func:`PyFrame_GetLocals`, :func:`locals`, and
2693-
:attr:`FrameType.f_locals <frame.f_locals>` no longer access the same underlying cached
2694-
dictionary. Changes made to entries for actual variable names and names added via the
2695-
write-through proxy interfaces will be overwritten on subsequent calls to
2696-
:c:func:`PyEval_GetLocals` in that frame. The recommended code update depends on how the
2697-
function was being used, so refer to the deprecation notice on the function for details.
2698-
(Changed as part of :pep:`667`.)
2699-
2700-
* Calling :c:func:`PyFrame_GetLocals` in an :term:`optimized scope` now returns a
2701-
write-through proxy rather than a snapshot that gets updated at ill-specified times.
2702-
If a snapshot is desired, it must be created explicitly (e.g. with :c:func:`PyDict_Copy`)
2703-
or by calling the new :c:func:`PyEval_GetFrameLocals` API. (Changed as part of :pep:`667`.)
2704-
2705-
* :c:func:`!PyFrame_FastToLocals` and :c:func:`!PyFrame_FastToLocalsWithError`
2706-
no longer have any effect. Calling these functions has been redundant since
2707-
Python 3.11, when :c:func:`PyFrame_GetLocals` was first introduced.
2708-
(Changed as part of :pep:`667`.)
2709-
2710-
* :c:func:`!PyFrame_LocalsToFast` no longer has any effect. Calling this function
2711-
is redundant now that :c:func:`PyFrame_GetLocals` returns a write-through proxy
2712-
for :term:`optimized scopes <optimized scope>`. (Changed as part of :pep:`667`.)
2701+
* :ref:`PEP 667 <whatsnew313-locals-semantics>` introduces several changes
2702+
to frame-related functions:
2703+
2704+
* The effects of mutating the dictionary returned from
2705+
:c:func:`PyEval_GetLocals` in an :term:`optimized scope` have changed.
2706+
New dict entries added this way will now *only* be visible to
2707+
subsequent :c:func:`PyEval_GetLocals` calls in that frame,
2708+
as :c:func:`PyFrame_GetLocals`, :func:`locals`,
2709+
and :attr:`FrameType.f_locals <frame.f_locals>` no longer access
2710+
the same underlying cached dictionary.
2711+
Changes made to entries for actual variable names and names added via
2712+
the write-through proxy interfaces will be overwritten on subsequent calls
2713+
to :c:func:`PyEval_GetLocals` in that frame.
2714+
The recommended code update depends on how the function was being used,
2715+
so refer to the deprecation notice on the function for details.
2716+
2717+
* Calling :c:func:`PyFrame_GetLocals` in an :term:`optimized scope`
2718+
now returns a write-through proxy rather than a snapshot
2719+
that gets updated at ill-specified times.
2720+
If a snapshot is desired, it must be created explicitly
2721+
(e.g. with :c:func:`PyDict_Copy`),
2722+
or by calling the new :c:func:`PyEval_GetFrameLocals` API.
2723+
2724+
* :c:func:`!PyFrame_FastToLocals` and :c:func:`!PyFrame_FastToLocalsWithError`
2725+
no longer have any effect.
2726+
Calling these functions has been redundant since Python 3.11,
2727+
when :c:func:`PyFrame_GetLocals` was first introduced.
2728+
2729+
* :c:func:`!PyFrame_LocalsToFast` no longer has any effect.
2730+
Calling this function is redundant now that :c:func:`PyFrame_GetLocals`
2731+
returns a write-through proxy for :term:`optimized scopes <optimized scope>`.
27132732

27142733
Regression Test Changes
27152734
=======================

0 commit comments

Comments
 (0)
0