Skip to content

Instantly share code, notes, and snippets.

@atsuoishimoto
Created May 30, 2018 06:44
Show Gist options
  • Select an option

  • Save atsuoishimoto/96f12ef26c6bf66ae30965805b621ed0 to your computer and use it in GitHub Desktop.

Select an option

Save atsuoishimoto/96f12ef26c6bf66ae30965805b621ed0 to your computer and use it in GitHub Desktop.
check if global variable used
import dis, builtins
def checkglobal(f):
for op in dis.Bytecode(f):
if op.opname == 'LOAD_GLOBAL':
if not hasattr(builtins, op.argval):
print(f"Referring global variable {op.argval}")
return f
@checkglobal
def test():
x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment