GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-44800: unobtrusively rename _PyInterpreterFrame to _Py_frame by ncoghlan · Pull Request #32024 · python/cpython

Conversation

@ncoghlan

@ncoghlan ncoghlan commented Mar 21, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • rename _PyInterpreterFrame to _Py_frame to help indicate that _Py_frame
    is an implementation optimisation for frame objects rather than a distinct concept
  • add a block comment to pycore_frame.h covering future naming conventions,
    as well as deviations from those conventions for historical reasons
  • convert a potentially confusing use of cframe as a variable name to just frame

https://bugs.python.org/issue44800

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ncoghlan added 10 commits March 21, 2022 20:02
@ncoghlan
bpo-44800: Rename _PyInterpreterFrame to _Py_frame
70d2322
@ncoghlan
Fix misleading use of 'cframe' name in typeobject.c
28402ec
@ncoghlan
f_frame is not public, don't mention in What's New
90664e6
@ncoghlan
Add NEWS entry
9dced1f
@ncoghlan
Fix another use of cframe in typeoject.c
f20b1f9
@ncoghlan
ReST is not Markdown
a8d3c9e
@ncoghlan
Compatibility workaround to match 3.11a6 API
32c224f
@ncoghlan
Update comments for scaled back proposal
dda99b3
@ncoghlan
No aliases to check now
c725c6b
@ncoghlan
Adjust NEWS entry
9526ce0
@ncoghlan
ncoghlan requested review from 1st1, iritkatriel and markshannon as code owners March 21, 2022 10:58
@bedevere-bot bedevere-bot added the awaiting core review label Mar 21, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 21, 2022
@ncoghlan
Fix typo in comment
0acb559
@ncoghlan ncoghlan mentioned this pull request Mar 21, 2022
bpo-44800: rename _PyInterpreterFrame to _Py_frame #31987
Closed
markshannon
markshannon reviewed Mar 21, 2022
View reviewed changes
Comment thread Misc/NEWS.d/next/Core and Builtins/2022-03-19-21-47-36.bpo-44800.XnGKoD.rst
@@ -0,0 +1,5 @@
Renamed ``_PyInterpreterFrame`` as ``_Py_frame`` to emphasise its close
association with ``PyFrameObject`` (they're conceptually the same thing, but

@markshannon markshannon Mar 21, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What does "conceptually the same thing" mean?
They aren't the same thing. What is the concept that makes them the same?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Mar 21, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The same thing that makes it OK to pass both PyFrameObject and _PyInterpreterFrame structs to functions that have names starting with _PyFrame: they're Python code evaluation frames either way, but you may be working with the underlying data storage directly, or you may be working with the full refcounted Python object.

The difference between the two is mechanical (how their memory allocation is managed) rather than conceptual.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markshannon markshannon Mar 21, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Your concepts are just that, your concepts. They are highly subjective.

PyFrameObjects and _PyInterpreterFrame are different things. One is a reference counted heap object, the other a stack frame. They have to managed quite differently, to me that means they are "conceptually distinct".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon

markshannon commented Mar 21, 2022

Copy link
Copy Markdown
Member

I really don't see why you think _Py_frame is a better name than _PyInterpreterFrame
Removing an adjective only makes a noun phrase clearer if that adjective is misleading.
Do you find Interpreter misleading?

Also, could you explain why the change to the name of the struct, and changes to the names of its fields must be in the same PR? They seem like independent changes to me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan
Merge remote-tracking branch 'origin/main' into bpo-44800-py-frame-mi…
763a615
…nimal-changes
@ncoghlan

ncoghlan commented Mar 21, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Yes, I find "Interpreter" misleading, and as I said on the Discourse thread, it was your own comment on the first bpo-44800 PR that made me understand why it was confusing me: “From the point of view of Python code, the frame object is the frame, not just a view of it.”

When the names are _PyInterpreterFrame and PyFrameObject, that reads to me like they're two conceptually distinct things, whereas _Py_frame and PyFrameObject reads like the latter is just a Python API wrapper around the former, which is their actual relationship.

I think the last part of your comment may have been aimed at the previous PR, as there aren't any struct field name changes in this one.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Mar 21, 2022

Copy link
Copy Markdown
Member

If Interpreter is misleading, what would be a better adjective?

whereas _Py_frame and PyFrameObject reads like the latter is just a Python API wrapper around the former

To you. Not to me. _Py_frame tells me nothing. Is it a Python stack frame, a C stack frame, a video frame, an audio frame, a compression frame, ... ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Mar 22, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The ship sailed on PyFrame years ago when PyFrameObject was first named, along with all the associated PyFrame and _PyFrame APIs.

The problem Python 3.11 has created is that suddenly a lot of those _PyFrame APIs don't take a PyFrameObject pointer anymore, they take a _PyInterpreterFrame pointer. This makes them look like they're now accepting a different Python type from the one you'd expect based on their prefix, when what has really happened is that the essential PyFrameObject data storage has been pulled out to a separate C struct as a performance optimisation. Even the GDB bindings in the repo are confused, referring to the inner struct as a PyFramePtr, while the full Python object is PyFrameObjectPtr.

However, the only differences between PyFrameObject and _PyInterpreterFrame are mechanical (i.e. how you work with them in code), rather than conceptual (i.e. what they represent: a frame of execution for Python code).

When the two C types are instead PyFrameObject and _Py_frame those inconsistencies disappear:

  • a C data struct with a Python object API wrapper around it is a thoroughly normal thing to do in hybrid Python/C programming
  • _PyFrame APIs accept either PyFrameObject or _Py_frame, depending on which level they work at
  • PyFramePtr in the GDB bindings points to a _Py_frame struct
  • _Py_frame * doesn't look like a Python object pointer (it's intentionally similar to PEP 3118's Py_buffer in that respect - oddly, PEP 7 doesn't provide any guidance on naming regular C structs vs Python types in the C API)

The only thing getting in the way of that conventional coding style is the redundant "interpreter" adjective in the name of the underlying C struct. (As far as preferred adjectives go, my preferred one is "execution frame", hence the use of that in the first bpo-44800 PR that prompted your observation about there being no conceptual distinction between the two frame structs: "From the point of view of Python code, the frame object is the frame, not just a view of it". That's the observation that persuaded me that the best adjective to use here is no adjective at all, since PyFrameObject doesn't use one)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Mar 25, 2022

Copy link
Copy Markdown
Contributor Author

@markshannon I'm willing to close this and make a replacement PR that just documents the status quo in pycore_frame.h, but I'd like a definitive rejection from you first, rather than getting the silent treatment again.

Specifically, I'm looking for confirmation that you don't believe that it is in any way confusing to have the "interpreter" adjective solely in the struct name, when it's absent from the names of all the functions that manipulate the struct, from the name of the Python object that wraps the struct, and from most of the variables and struct fields that reference the struct.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented Mar 25, 2022

Copy link
Copy Markdown
Member

I've said I don't like this change. I'm not sure what the "silent treatment" is, apart from not repeating myself.

You point out that some of the functions that take _PyInterpreterFrame have a PyFrame prefix, not a _PyInterpreterFrame.
I don't see how that is justification for this PR.
Renaming the internal functions that take a _PyInterpreterFrame would be a sensible change.
Want to do that? The functions in Include/internal/pycore_frame.h are mostly fair game.

Renaming _PyInterpreterFrame to something better is not unreasonable, although you haven't come up with a better name yet, IMO. FTR the name I initially proposed was "activation record", but it was decided that keeping "frame" in the name was less confusing.
Any name change is likely to break something, so the name would have to be much better to justify the change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Mar 26, 2022

Copy link
Copy Markdown
Contributor Author

Renaming the private APIs is something I tried in a previous iteration of the proposal - it gets even messier than renaming the types and fields did.

I'll switch to adding internal code level documentation of the status quo (including the requirement to be super careful with not keeping hold of pointers to interpreter frames beyond their known validity)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan ncoghlan closed this Mar 26, 2022
@ncoghlan

ncoghlan commented Apr 3, 2022

Copy link
Copy Markdown
Contributor Author

Replacement PR that just documents the status quo: #32281

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan ncoghlan mentioned this pull request Apr 16, 2022
Code readability: rename InterpreterFrame to _Py_framedata #88963
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon markshannon left review comments
@iritkatriel iritkatriel Awaiting requested review from iritkatriel
@1st1 1st1 Awaiting requested review from 1st1

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ncoghlan @markshannon @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.