Skip to content

Instantly share code, notes, and snippets.

@atsuoishimoto
Created May 30, 2018 07:03
Show Gist options
  • Save atsuoishimoto/6e9a6cd9ed60556032adc269ec78c22e to your computer and use it in GitHub Desktop.
Save atsuoishimoto/6e9a6cd9ed60556032adc269ec78c22e to your computer and use it in GitHub Desktop.
detect when global variable used
import types
class gdict(dict):
def __getitem__(self, key):
print(f'referring {key}')
return eval(key, globals())
def check(f):
return types.FunctionType(f.__code__, gdict())
@check
def test():
x
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment