Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-74929: Rudimentary docs for PEP 667#118581

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gvanrossum merged 5 commits intopython:mainfromgvanrossum:whatsnew-f-locals
May 5, 2024

Conversation

gvanrossum
Copy link
Member

@gvanrossumgvanrossum commentedMay 4, 2024
edited
Loading

This isnot sufficient for the final 3.13 release, but it may have to do for beta 1:

  • What's new entry
  • Updated changelog entry (news blurb)
  • Mention the proxy for f_globals in the datamodel and Python frame object docs

This doesn't have any C API details (what's new refers to the PEP).

For some reason I cannot get the "versionchanged" note in the datamodel docs to show.@hugovk ?


📚 Documentation preview 📚:https://cpython-previews--118581.org.readthedocs.build/

@gaogaotiantian
Copy link
Member

There's a minor technicality here that might worth clarification.

importsysframe1= [sys._getframe()forain [0]][0]frame2=sys._getframe()assertframe1isframe2local1= [sys._getframe().f_localsforain [0]][0]local2=sys._getframe().f_localsassertlocal1!=local2

Whetherf_locals is a proxy or a dict technically does not entirely depend on theframe. It depends on when is theframe.f_locals call made - inside a comprehension or not.

As you can tell from the example above, theframe is exactly the same frame object, but thef_locals is different.

efimov-mikhail reacted with thumbs up emoji

@gvanrossum
Copy link
MemberAuthor

There's a minor technicality here that might worth clarification. [...]

That's very subtle. Is it explained in PEP 667? I'm not sure how to work this in the existing (pretty sparse) docs forf_locals.

@gaogaotiantian
Copy link
Member

Actually the final behavior we agreed on is slightly different from what PEP 667 proposed. PEP 667 also did not mention howf_locals should work with inline comprehensions. Can we modify PEP 667 after it was accepted? I don't know if we should dump all the details in thef_locals docs because it would be rare for the users to usef_locals inside the comprehension so no need to confuse them, but it would be nice to explain it well in PEP 667.

@gvanrossum
Copy link
MemberAuthor

Actually the final behavior we agreed on is slightly different from what PEP 667 proposed. PEP 667 also did not mention howf_locals should work with inline comprehensions. Can we modify PEP 667 after it was accepted? I don't know if we should dump all the details in thef_locals docs because it would be rare for the users to usef_locals inside the comprehension so no need to confuse them, but it would be nice to explain it well in PEP 667.

Assuming this is about clarifying something that the original text of the PEP did not specify precisely enough, and given that the PEP is brand new, I think it's okay to clarify in the PEP. Although in general PEPs are nowadays seen as historic documents, not as living specifications.

ncoghlan reacted with thumbs up emoji

@AlexWaygood
Copy link
Member

AlexWaygood commentedMay 4, 2024
edited
Loading

It's not something that has to be done in this PR, but if we think that there are some subtleties here that warrant detailed explanation and that the datamodel docs aren't the right place to do that, one option would be to add a howto similar to the one Larry added in 3.10 to explain the semantics of the__annotations__ attribute:https://docs.python.org/3/howto/annotations.html

It wouldn't really be a howto in the Diataxis sense of the term, but we don't really have a better place for that kind of in-depth article in the CPython docs currently, and there are lots of other articles in that directory that also don't meet Diataxis's strict definition of a "howto" article. And as@gvanrossum says, all the relevant information regarding the semantics here should ideally be findable in the CPython docs somewhere, without having to refer to the PEP, which is a historical document now that it has been accepted.

(But we can probably update the PEP as well, given that it'sonly just been accepted :-)

@gvanrossum
Copy link
MemberAuthor

@AlexWaygood@gaogaotiantian Are you two okay with me merging this? I'm all for iterating later, but I feel it's important to mention at least this much in the beta 1 docs, which I expect will reach a relatively big audience of people who are thinking of testing the beta.

@gaogaotiantian
Copy link
Member

Yes this feels okay for beta.

@@ -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
Member

Choose a reason for hiding this comment

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

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
MemberAuthor

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

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

Comment on lines +1345 to +1349
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.
Copy link
Member

Choose a reason for hiding this comment

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

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'>

@gvanrossumgvanrossumenabled auto-merge (squash)May 5, 2024 15:16
@gvanrossumgvanrossum merged commit9c13d9e intopython:mainMay 5, 2024
@gvanrossumgvanrossum deleted the whatsnew-f-locals branchMay 5, 2024 18:47
SonicField pushed a commit to SonicField/cpython that referenced this pull requestMay 8, 2024
This is *not* sufficient for the final 3.13 release, but it will do for beta 1:- What's new entry- Updated changelog entry (news blurb)- Mention the proxy for f_globals in the datamodel and Python frame object docsThis doesn't have any C API details (what's new refers to the PEP).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

@gaogaotiantiangaogaotiantiangaogaotiantian approved these changes

@markshannonmarkshannonAwaiting requested review from markshannon

Assignees
No one assigned
Labels
docsDocumentation in the Doc dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@gvanrossum@gaogaotiantian@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp