Created
May 30, 2018 07:03
-
-
Save atsuoishimoto/6e9a6cd9ed60556032adc269ec78c22e to your computer and use it in GitHub Desktop.
detect when global variable used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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