Skip to content

gh-136492: Add FrameLocalsProxy to types #136546

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Jul 11, 2025

@@ -226,6 +226,13 @@ os.path
(Contributed by Petr Viktorin for :cve:`2025-4517`.)


types
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the section below tarfile?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, got my ABCs wrong.

'MethodDescriptorType', 'MethodType', 'MethodWrapperType',
'ModuleType', 'NoneType', 'NotImplementedType', 'SimpleNamespace',
'TracebackType', 'UnionType', 'WrapperDescriptorType',
'FrameLocalsProxyType', 'GeneratorType', 'GenericAlias',
Copy link
Member

Choose a reason for hiding this comment

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

A simple suggestion, but how about adding just FrameLocalsProxyType on a single line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was 50/50 on whether not we should keep this alphabetical. I'll change it.

@ZeroIntensity
Copy link
Member Author

Ugh, those test failures look like an existing bug on FrameLocalsProxy.

blockchainGuru1018

This comment was marked as spam.

@picnixz
Copy link
Member

picnixz commented Jul 11, 2025

@python/organization-owners Could you block blockchainGuru1018 for spam & misguided reviews? TiA.

@@ -333,6 +333,14 @@ Standard names are defined for the following types:
:attr:`tb.tb_frame <traceback.tb_frame>` if ``tb`` is a traceback object.


.. data:: FrameLocalsProxyType

The type of frame :func:`locals` proxy objects, as found on the
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's proper to link :func:`locals` here. locals() is a function that returns a snapshot (dict) of the local variables. That is a different path to local variables. frame.f_locals is designed to be different than locals(), it might be a bit confusing here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just used it to give context to what "locals" mean. I did the same for the C API docs. Should we change it there too?

.. data:: FrameLocalsProxyType

The type of frame :func:`locals` proxy objects, as found on the
:attr:`frame.f_locals` attribute. See :pep:`667` for more information.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we should refer to PEP 667 here - the PEP itself is a historical document and we are redirecting people to a different place in the PEP.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about a seealso note instead?

@gaogaotiantian
Copy link
Member

Ugh, those test failures look like an existing bug on FrameLocalsProxy.

Could you be more specific? Maybe raise an issue for that so I can fix it later?

@ZeroIntensity
Copy link
Member Author

Could you be more specific? Maybe raise an issue for that so I can fix it later?

There were a few things I had to skip in test_inspect. I think they're bugs, but I haven't investigated the test enough to be sure.

@gaogaotiantian
Copy link
Member

Okay now we need some typing expert to review this. @JelleZijlstra maybe?

@ZeroIntensity
Copy link
Member Author

I'd also appreciate it if @AA-Turner could take a look; he's done some recent work with types and _types.

@JelleZijlstra
Copy link
Member

You don't really need a static typing expert for the types module; it predates static typing and is useful even without static typing. The PR seems pretty straightforward to me.

------

* Added :data:`types.FrameLocalsProxyType` for representing the type of
the :attr:`frame.f_locals` attribute, as determined in :pep:`667`.
Copy link
Member

Choose a reason for hiding this comment

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

"determined" sounds a little odd here, maybe:

Suggested change
the :attr:`frame.f_locals` attribute, as determined in :pep:`667`.
the :attr:`frame.f_locals` attribute, as described in :pep:`667`.

}
no_signature = {'FrameLocalsProxyType'}
Copy link
Member

Choose a reason for hiding this comment

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

This should be fixable by adding a tp_doc to FrameLocalsProxy that includes the signature; see types.CellType in cellobject.c for an example.

@@ -5786,10 +5786,13 @@ def test_types_module_has_signatures(self):
'AsyncGeneratorType': {'athrow'},
'CoroutineType': {'throw'},
'GeneratorType': {'throw'},
'FrameLocalsProxyType': {'setdefault', 'pop', 'get'}
Copy link
Member

Choose a reason for hiding this comment

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

This should be fixable by converting these methods to Argument Clinic or manually adding a docstring with a signature.

Copy link
Member

Choose a reason for hiding this comment

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

To be clear I'm not asking you to necessarily fix this, though I think it'd be nice to reduce the size of the denylist in this test.

@@ -69,6 +69,7 @@ def _m(self): pass
EllipsisType = type(Ellipsis)
NoneType = type(None)
NotImplementedType = type(NotImplemented)
FrameLocalsProxyType = (lambda: type(sys._getframe().f_locals))()
Copy link
Member

Choose a reason for hiding this comment

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

Introspecting this class currently would make you think it is builtins.FrameLocalProxy:

>>> FrameLocalsProxyType = (lambda: type(sys._getframe().f_locals))()
>>> FrameLocalsProxyType.__module__
'builtins'
>>> FrameLocalsProxyType.__name__
'FrameLocalsProxy'

What do you think about changing its tp_name to types.FrameLocalsProxyType, so that the runtime __module__ and __name__ attributes are consistent with the place where you can actually find it? This is what types.SimpleNamespace already does.

Personally I'd ideally want to do this for all the types.* types, but there are compatibility concerns for some. Here though, given that the type is relatively new and private, maybe we can get away with changing its name and module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy