[issue36697] inspect.getclosurevars returns wrong globals dict

Eric V. Smith report at bugs.python.org
Tue Apr 23 06:10:33 EDT 2019


Eric V. Smith <eric at trueblade.com> added the comment:

That is interesting. See these examples. I'm starting a new interpreter each time:

>>> import inspect
>>> def abc(): pass
...
>>> inspect.getclosurevars(abc)
ClosureVars(nonlocals={}, globals={}, builtins={}, unbound=set())
>>>


>>> import inspect
>>> def abc(): a
...
>>> inspect.getclosurevars(abc)
ClosureVars(nonlocals={}, globals={}, builtins={}, unbound={'a'})
>>>

>>> import inspect
>>> a=0
>>> def abc(): a
...
>>> inspect.getclosurevars(abc)
ClosureVars(nonlocals={}, globals={'a': 0}, builtins={}, unbound=set())
>>>

>>> import inspect
>>> a=0
>>> def abc(): a.b
...
>>> inspect.getclosurevars(abc)
ClosureVars(nonlocals={}, globals={'a': 0}, builtins={}, unbound={'b'})
>>>

>>> import inspect
>>> a=0
>>> b=1
>>> def abc(): a.b
...
>>> inspect.getclosurevars(abc)
ClosureVars(nonlocals={}, globals={'a': 0, 'b': 1}, builtins={}, unbound=set())
>>> 

It's odd.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36697>
_______________________________________


More information about the Python-bugs-list mailing list