Noitul added the comment:
Look at this
https://github.com/python/cpython/blob/3.6/Lib/inspect.py#L1412
We are taking names from func.__code__.co_names, which also contains names of
object's attributes we visited. As a result, we may get more names unexpectedly
in 'globals',
Noitul added the comment:
Sorry for the misleading snippet above.
And how about this one:
>>> import inspect
>>> a = 0
>>> b = 1
>>> c = 2
>>> def abc():
New submission from Noitul :
>>> import inspect
>>> a = 0
>>> b = 1
>>> def abc():
>>> return a.b