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
Simplify locals() versionchanged notes
  • Loading branch information
ncoghlan committed May 20, 2024
commit ebcf2d0e2f72c80e8e61ca70f9518ee7b00277a1
45 changes: 8 additions & 37 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1098,46 +1098,17 @@ are always available. They are listed here in alphabetical order.
Calling ``locals()`` as part of a generator expression is equivalent to
calling it in a nested generator function.

.. versionchanged:: 3.13
As part of :pep:`667`, the semantics of mutating the mapping object
returned from this function are now formally defined. The behavior in
functions, generators, coroutines, comprehensions, and generator
expressions is now as described above. Aside from being defined, the
behaviour in other scopes remains unchanged from previous versions.

.. versionchanged:: 3.13
As part of :pep:`667`, the mapping returned when called in a function,
generator, coroutine, comprehension or generator expression is an
independent snapshot of the currently assigned local and locally
referenced nonlocal variables. In CPython specifically, the mapping
returned in these scopes could previously be implicitly refreshed by other
operations, such as calling ``locals()`` again. Obtaining the legacy
CPython behaviour now requires explicit calls to update the initially
returned dictionary with the results of subsequent calls to ``locals()``.
.. versionchanged:: 3.12
The behaviour of ``locals()`` in a comprehension has been updated as
described in :pep:`709`.

.. versionchanged:: 3.13
As part of :pep:`667`, calling ``locals()`` in a comprehension at module
or class scope (including via ``exec`` or ``eval``) once more behaves as if
the comprehension were running as an independent nested function (i.e.
the local variables from the containing scope are not included).
As part of :pep:`667`, the semantics of mutating the mapping objects
returned from this function are now defined. The behavior in
:term:`optimised scopes <optimised scope>` is now as described above.
Aside from being defined, the behaviour in other scopes remains
unchanged from previous versions.

.. versionchanged:: 3.12
As part of :pep:`709`, calling ``locals()`` in a comprehension at module
or class scope (including via ``exec`` or ``eval``) produces an independent
snapshot of the containing scope with the comprehension iteration
variable(s) included.

.. versionchanged:: 3.12
As part of :pep:`709`, calling ``locals()`` in a comprehension as part of a
function, generator, or coroutine returns the same ``locals()`` reference
as calls in the containing scope.

..
Possible simplification: change the 3.12 note to just "Changes to
behavior in comprehensions as described in :pep:`709`", and do somethine
similar for 3.13 and :pep:`667`. While the draft change notes are
comprehensive, they're also almost entirely in the "Who is really going
to care?" category.

.. function:: map(function, iterable, *iterables)

Expand Down
Loading