-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-80878: Fix inspect.getclosurevars when an attribute shadows a global #91833
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
base: main
Are you sure you want to change the base?
Conversation
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
2ea0d74
to
efb53ea
Compare
Every change to Python requires a NEWS entry. Please, add it using the blurb_it Web app or the blurb command-line tool. |
e714aa3
to
c5854b5
Compare
90d95c2
to
551e037
Compare
Tagging @ericvsmith since they commented on #80878. I think this PR will be a quick review. |
@@ -1599,6 +1599,31 @@ def test_builtins_as_module(self): | |||
expected = inspect.ClosureVars({}, {}, {"path":os.path}, {"print"}) | |||
self.assertEqual(inspect.getclosurevars(f), expected) | |||
|
|||
def test_attr_shadows_globals(self): |
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.
Should add a test that exercises the STORE_GLOBAL opcode.
global_vars[name] = global_ns[name] | ||
except KeyError: | ||
|
||
for instrn in dis.get_instructions(func): |
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.
I feel a bit uneasy about relying on dis
here because the bytecode format may change. Also, this may make it harder to use inspect.py
on alternative implementations such as PyPy.
I don't have a better idea for implementing getclosurevars
correctly though.
Fixes #80878