FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-74929: Rudimentary docs for PEP 667 by gvanrossum · Pull Request #118581 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 8 additions & 1 deletion Doc/c-api/frame.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,19 @@ See also :ref:`Reflection <reflection>`.

.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)

Get the *frame*'s :attr:`~frame.f_locals` attribute (:class:`dict`).
Get the *frame*'s :attr:`~frame.f_locals` attribute.
If the frame refers to a function or comprehension, this returns
a write-through proxy object that allows modifying the locals.
In all other cases (classes, modules) it returns the :class:`dict`
representing the frame locals directly.

Return a :term:`strong reference`.

.. versionadded:: 3.11

.. versionchanged:: 3.13
Return a proxy object for functions and comprehensions.


.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)

Expand Down
7 changes: 6 additions & 1 deletion Doc/reference/datamodel.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,12 @@ Special read-only attributes

* - .. attribute:: frame.f_locals
- The dictionary used by the frame to look up
:ref:`local variables <naming>`
:ref:`local variables <naming>`.
If the frame refers to a function or comprehension,
this may return a write-through proxy object.

.. versionchanged:: 3.13
Return a proxy for functions and comprehensions.
Comment on lines +1345 to +1349

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

And apparently this also applies for type parameter scopes? Though I have no idea if that was deliberate:

>>> import sys
>>> type T[X: type(sys._getframe().f_locals)] = ...
>>> T.__type_params__[0].__bound__
<class 'FrameLocalsProxy'>


* - .. attribute:: frame.f_globals
- The dictionary used by the frame to look up
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Interpreter improvements:
Performance improvements are modest -- we expect to be improving this
over the next few releases.

* :pep:`667`: :attr:`FrameType.f_locals <frame.f_locals>` when used in
a function now returns a write-through proxy to the frame's locals,
rather than a ``dict``. See the PEP for corresponding C API changes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
rather than a ``dict``. See the PEP for corresponding C API changes
rather than a :class:`dict`. See the PEP for corresponding C API changes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think that would be a case of over-linking. Surely readers who know what f_locals is will be familiar with dict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, I don't feel strongly, feel free to ignore

and deprecations.

New typing features:

* :pep:`696`: Type parameters (:data:`typing.TypeVar`, :data:`typing.ParamSpec`,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Implement PEP 667 - converted ``frame.f_locals`` to a write through proxy
Implement PEP 667: converted :attr:`FrameType.f_locals <frame.f_locals>`
and :c:func:`PyFrame_GetLocals` to return a write-through proxy object
when the frame refers to a function or comprehension.

Back | FazBrowse Home | New Git URL