10000 gh-74929: PEP 667 general docs update by ncoghlan · Pull Request #119201 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-74929: PEP 667 general docs update #119201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move What's New entry to correct section, add credits
  • Loading branch information
ncoghlan committed May 20, 2024
commit a87f1d73a28198845f7512269b3388ffa988d669
50 changes: 27 additions & 23 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,33 @@ Improved Error Messages
through ``self.X`` from any function in its body. (Contributed by Irit Katriel
in :gh:`115775`.)


Defined mutation semantics for ``locals()``
-------------------------------------------

Historically, the semantics for mutating the return value of :func:`locals` have
been left to individual Python implementations to define.

Through :pep:`667`, Python 3.13 standardises the historical behaviour of CPython
for most code execution scopes, but changes
:term:`optimised scopes <optimised scope>` (functions, generators, coroutines,
comprehensions, and generator expressions) to explicitly return independent
snapshots of the currently assigned local variables, including locally
referenced nonlocal variables captured in closures.

To ensure debuggers and similar tools can reliably update local variables in
scopes affected by this change, :attr:`FrameType.f_locals <frame.f_locals>` now
returns a write-through proxy to the frame's local and locally referenced
nonlocal variables in these scopes, rather than returning an inconsistently
updated shared ``dict`` instance with undefined runtime semantics.

See :pep:`667` for more details, including related C API changes and
deprecations.

(PEP and implementation contributed by Mark Shannon and Tian Gao in
:gh:`74929`. Documentation updates provided by Guido van Rossum and
Alyssa Coghlan.)

Incremental Garbage Collection
------------------------------

Expand Down Expand Up @@ -371,29 +398,6 @@ pip 24.1b1 or newer is required to install packages with C extensions in the
free-threaded build.


Defined mutation semantics for ``locals()``
-------------------------------------------

Historically, the semantics for mutating the return value of :func:`locals` have
been left to individual Python implementations to define.

Through :pep:`667`, Python 3.13 standardises the historical behaviour of CPython
for most code execution scopes, but changes
:term:`optimised scopes <optimised scope>` (functions, generators, coroutines,
comprehensions, and generator expressions) to explicitly return independent
snapshots of the currently assigned local variables, including locally
referenced nonlocal variables captured in closures.

To ensure debuggers and similar tools can reliably update local variables in
scopes affected by this change, :attr:`FrameType.f_locals <frame.f_locals>` now
returns a write-through proxy to the frame's local and locally referenced
nonlocal variables in these scopes, rather than returning an inconsistently
updated shared ``dict`` instance with undefined runtime semantics.

See :pep:`667` for more details, including related C API changes and
deprecations.


Other Language Changes
======================

Expand Down
0