@@ -520,7 +520,7 @@ old generation, instead of collecting one or more generations.
520520
521521The behavior of :func: `!gc.collect ` changes slightly:
522522
523- * ``gc.collect(1) ``: Performs an increment of GC ,
523+ * ``gc.collect(1) ``: Performs an increment of garbage collection ,
524524 rather than collecting generation 1.
525525* Other calls to :func: `!gc.collect ` are unchanged.
526526
@@ -2250,6 +2250,19 @@ Changed C APIs
22502250 non-ASCII keyword parameter names.
22512251 (Contributed by Serhiy Storchaka in :gh: `110815 `.)
22522252
2253+ * The :c:func: `!PyCode_GetFirstFree ` function is now unstable API
2254+ and is now named :c:func: `PyUnstable_Code_GetFirstFree `.
2255+ (Contributed by Bogdan Romanyuk in :gh: `115781 `.)
2256+
2257+ * The :c:func: `PyDict_GetItem `, :c:func: `PyDict_GetItemString `,
2258+ :c:func: `PyMapping_HasKey `, :c:func: `PyMapping_HasKeyString `,
2259+ :c:func: `PyObject_HasAttr `, :c:func: `PyObject_HasAttrString `,
2260+ and :c:func: `PySys_GetObject ` functions,
2261+ each of which clears all errors which occurred when calling them
2262+ now reports these errors using :func: `sys.unraisablehook `.
2263+ You may replace them with other functions as recommended in the documentation.
2264+ (Contributed by Serhiy Storchaka in :gh: `106672 `.)
2265+
22532266* Add support for the ``%T ``, ``%#T ``, ``%N `` and ``%#N `` formats
22542267 to :c:func: `PyUnicode_FromFormat `:
22552268
@@ -2555,63 +2568,75 @@ that may require changes to your code.
25552568Changes in the Python API
25562569-------------------------
25572570
2558- * An :exc: `OSError ` is now raised by :func: `getpass.getuser ` for any failure to
2559- retrieve a username, instead of :exc: `ImportError ` on non-Unix platforms or
2560- :exc: `KeyError ` on Unix platforms where the password database is empty.
2571+ .. _pep667-porting-notes-py :
25612572
2562- * The :mod: `threading ` module now expects the :mod: `!_thread ` module to have
2563- an ``_is_main_interpreter `` attribute. It is a function with no
2564- arguments that returns ``True `` if the current interpreter is the
2565- main interpreter.
2573+ * :ref: `PEP 667 <whatsnew313-locals-semantics >` introduces several changes
2574+ to the semantics of :func: `locals ` and :attr: `f_locals <frame.f_locals> `:
2575+
2576+ * Calling :func: `locals ` in an :term: `optimized scope ` now produces an
2577+ independent snapshot on each call, and hence no longer implicitly updates
2578+ previously returned references. Obtaining the legacy CPython behaviour now
2579+ requires explicit calls to update the initially returned dictionary with the
2580+ results of subsequent calls to :func: `!locals `. Code execution functions that
2581+ implicitly target :func: `!locals ` (such as ``exec `` and ``eval ``) must be
2582+ passed an explicit namespace to access their results in an optimized scope.
2583+ (Changed as part of :pep: `667 `.)
2584+
2585+ * Calling :func: `locals ` from a comprehension at module or class scope
2586+ (including via ``exec `` or ``eval ``) once more behaves as if the comprehension
2587+ were running as an independent nested function (i.e. the local variables from
2588+ the containing scope are not included). In Python 3.12, this had changed
2589+ to include the local variables from the containing scope when implementing
2590+ :pep: `709 `. (Changed as part of :pep: `667 `.)
2591+
2592+ * Accessing :attr: `FrameType.f_locals <frame.f_locals> ` in an
2593+ :term: `optimized scope ` now returns a write-through proxy rather than a
2594+ snapshot that gets updated at ill-specified times. If a snapshot is desired,
2595+ it must be created explicitly with ``dict `` or the proxy's ``.copy() `` method.
2596+ (Changed as part of :pep: `667 `.)
2597+
2598+ * :class: `functools.partial ` now emits a :exc: `FutureWarning `
2599+ when used as a method.
2600+ The behavior will change in future Python versions.
2601+ Wrap it in :func: `staticmethod ` if you want to preserve the old behavior.
2602+ (Contributed by Serhiy Storchaka in :gh: `121027 `.)
25662603
2567- Any library or application that provides a custom ``_thread `` module
2568- must provide :func: `!_is_main_interpreter `, just like the module's
2569- other "private" attributes.
2570- (See :gh: `112826 `.)
2604+ * The :ref: `garbage collector is now incremental <whatsnew313-incremental-gc >`,
2605+ which means that the behavior of :func: `gc.collect ` changes slightly:
25712606
2572- * :class: `mailbox.Maildir ` now ignores files with a leading dot.
2573- (Contributed by Zackery Spytz in :gh: `65559 `.)
2607+ * ``gc.collect(1) ``: Performs an increment of garbage collection,
2608+ rather than collecting generation 1.
2609+ * Other calls to :func: `!gc.collect ` are unchanged.
25742610
2575- * :meth: ` pathlib.Path.glob ` and :meth: ` ~pathlib.Path.rglob ` now return both
2576- files and directories if a pattern that ends with "`` ** ``" is given, rather
2577- than directories only. Users may add a trailing slash to match only
2578- directories .
2611+ * An :exc: ` OSError ` is now raised by :func: ` getpass.getuser `
2612+ for any failure to retrieve a username,
2613+ instead of :exc: ` ImportError ` on non-Unix platforms
2614+ or :exc: ` KeyError ` on Unix platforms where the password database is empty .
25792615
2580- * The value of the :attr: `!mode ` attribute of :class: `gzip.GzipFile ` was
2581- changed from integer (``1 `` or ``2 ``) to string (``'rb' `` or ``'wb' ``).
2616+ * The value of the :attr: `!mode ` attribute of :class: `gzip.GzipFile `
2617+ is now a string (``'rb' `` or ``'wb' ``) instead of an integer (``1 `` or ``2 ``).
25822618 The value of the :attr: `!mode ` attribute of the readable file-like object
2583- returned by :meth: `zipfile.ZipFile.open ` was changed from ``'r ' `` to ``'rb ' ``.
2619+ returned by :meth: `zipfile.ZipFile.open ` is now ``'rb ' `` instead of ``'r ' ``.
25842620 (Contributed by Serhiy Storchaka in :gh: `115961 `.)
25852621
2586- * :class: `functools.partial ` now emits a :exc: `FutureWarning ` when it is
2587- used as a method.
2588- Its behavior will be changed in future Python versions.
2589- Wrap it in :func: `staticmethod ` if you want to preserve the old behavior.
2590- (Contributed by Serhiy Storchaka in :gh: `121027 `.)
2622+ * :class: `mailbox.Maildir ` now ignores files with a leading dot (``. ``).
2623+ (Contributed by Zackery Spytz in :gh: `65559 `.)
25912624
2592- .. _pep667-porting-notes-py :
2625+ * :meth: `pathlib.Path.glob ` and :meth: `~pathlib.Path.rglob ` now return both
2626+ files and directories if a pattern that ends with "``** ``" is given,
2627+ rather than directories only.
2628+ Add a trailing slash to keep the previous behavior and only match directories.
2629+
2630+ * The :mod: `threading ` module now expects the :mod: `!_thread ` module
2631+ to have an :func: `!_is_main_interpreter ` function.
2632+ This function takes no arguments and returns ``True ``
2633+ if the current interpreter is the main interpreter.
2634+
2635+ Any library or application that provides a custom :mod: `!_thread ` module
2636+ must provide :func: `!_is_main_interpreter `,
2637+ just like the module's other "private" attributes.
2638+ (:gh: `112826 `.)
25932639
2594- * Calling :func: `locals ` in an :term: `optimized scope ` now produces an
2595- independent snapshot on each call, and hence no longer implicitly updates
2596- previously returned references. Obtaining the legacy CPython behaviour now
2597- requires explicit calls to update the initially returned dictionary with the
2598- results of subsequent calls to :func: `!locals `. Code execution functions that
2599- implicitly target :func: `!locals ` (such as ``exec `` and ``eval ``) must be
2600- passed an explicit namespace to access their results in an optimized scope.
2601- (Changed as part of :pep: `667 `.)
2602-
2603- * Calling :func: `locals ` from a comprehension at module or class scope
2604- (including via ``exec `` or ``eval ``) once more behaves as if the comprehension
2605- were running as an independent nested function (i.e. the local variables from
2606- the containing scope are not included). In Python 3.12, this had changed
2607- to include the local variables from the containing scope when implementing
2608- :pep: `709 `. (Changed as part of :pep: `667 `.)
2609-
2610- * Accessing :attr: `FrameType.f_locals <frame.f_locals> ` in an
2611- :term: `optimized scope ` now returns a write-through proxy rather than a
2612- snapshot that gets updated at ill-specified times. If a snapshot is desired,
2613- it must be created explicitly with ``dict `` or the proxy's ``.copy() `` method.
2614- (Changed as part of :pep: `667 `.)
26152640
26162641Changes in the C API
26172642--------------------
@@ -2673,45 +2698,39 @@ Changes in the C API
26732698 added in Python 3.8 and the old macros were deprecated in Python 3.11.
26742699 (Contributed by Irit Katriel in :gh: `105111 `.)
26752700
2676- * Functions :c:func: `PyDict_GetItem `, :c:func: `PyDict_GetItemString `,
2677- :c:func: `PyMapping_HasKey `, :c:func: `PyMapping_HasKeyString `,
2678- :c:func: `PyObject_HasAttr `, :c:func: `PyObject_HasAttrString `, and
2679- :c:func: `PySys_GetObject `, which clear all errors which occurred when calling
2680- them, now report them using :func: `sys.unraisablehook `.
2681- You may replace them with other functions as
2682- recommended in the documentation.
2683- (Contributed by Serhiy Storchaka in :gh: `106672 `.)
2684-
2685- * :c:func: `!PyCode_GetFirstFree ` is an unstable API now and has been renamed
2686- to :c:func: `PyUnstable_Code_GetFirstFree `.
2687- (Contributed by Bogdan Romanyuk in :gh: `115781 `.)
2688-
26892701.. _pep667-porting-notes-c :
26902702
2691- * The effects of mutating the dictionary returned from :c:func: `PyEval_GetLocals ` in an
2692- :term: `optimized scope ` have changed. New dict entries added this way will now *only * be
2693- visible to subsequent :c:func: `PyEval_GetLocals ` calls in that frame, as
2694- :c:func: `PyFrame_GetLocals `, :func: `locals `, and
2695- :attr: `FrameType.f_locals <frame.f_locals> ` no longer access the same underlying cached
2696- dictionary. Changes made to entries for actual variable names and names added via the
2697- write-through proxy interfaces will be overwritten on subsequent calls to
2698- :c:func: `PyEval_GetLocals ` in that frame. The recommended code update depends on how the
2699- function was being used, so refer to the deprecation notice on the function for details.
2700- (Changed as part of :pep: `667 `.)
2701-
2702- * Calling :c:func: `PyFrame_GetLocals ` in an :term: `optimized scope ` now returns a
2703- write-through proxy rather than a snapshot that gets updated at ill-specified times.
2704- If a snapshot is desired, it must be created explicitly (e.g. with :c:func: `PyDict_Copy `)
2705- or by calling the new :c:func: `PyEval_GetFrameLocals ` API. (Changed as part of :pep: `667 `.)
2706-
2707- * :c:func: `!PyFrame_FastToLocals ` and :c:func: `!PyFrame_FastToLocalsWithError `
2708- no longer have any effect. Calling these functions has been redundant since
2709- Python 3.11, when :c:func: `PyFrame_GetLocals ` was first introduced.
2710- (Changed as part of :pep: `667 `.)
2711-
2712- * :c:func: `!PyFrame_LocalsToFast ` no longer has any effect. Calling this function
2713- is redundant now that :c:func: `PyFrame_GetLocals ` returns a write-through proxy
2714- for :term: `optimized scopes <optimized scope> `. (Changed as part of :pep: `667 `.)
2703+ * :ref: `PEP 667 <whatsnew313-locals-semantics >` introduces several changes
2704+ to frame-related functions:
2705+
2706+ * The effects of mutating the dictionary returned from
2707+ :c:func: `PyEval_GetLocals ` in an :term: `optimized scope ` have changed.
2708+ New dict entries added this way will now *only * be visible to
2709+ subsequent :c:func: `PyEval_GetLocals ` calls in that frame,
2710+ as :c:func: `PyFrame_GetLocals `, :func: `locals `,
2711+ and :attr: `FrameType.f_locals <frame.f_locals> ` no longer access
2712+ the same underlying cached dictionary.
2713+ Changes made to entries for actual variable names and names added via
2714+ the write-through proxy interfaces will be overwritten on subsequent calls
2715+ to :c:func: `PyEval_GetLocals ` in that frame.
2716+ The recommended code update depends on how the function was being used,
2717+ so refer to the deprecation notice on the function for details.
2718+
2719+ * Calling :c:func: `PyFrame_GetLocals ` in an :term: `optimized scope `
2720+ now returns a write-through proxy rather than a snapshot
2721+ that gets updated at ill-specified times.
2722+ If a snapshot is desired, it must be created explicitly
2723+ (e.g. with :c:func: `PyDict_Copy `),
2724+ or by calling the new :c:func: `PyEval_GetFrameLocals ` API.
2725+
2726+ * :c:func: `!PyFrame_FastToLocals ` and :c:func: `!PyFrame_FastToLocalsWithError `
2727+ no longer have any effect.
2728+ Calling these functions has been redundant since Python 3.11,
2729+ when :c:func: `PyFrame_GetLocals ` was first introduced.
2730+
2731+ * :c:func: `!PyFrame_LocalsToFast ` no longer has any effect.
2732+ Calling this function is redundant now that :c:func: `PyFrame_GetLocals `
2733+ returns a write-through proxy for :term: `optimized scopes <optimized scope> `.
27152734
27162735Regression Test Changes
27172736=======================
0 commit comments