Last active
December 11, 2015 22:18
-
-
Save jcaxmacher/4668416 to your computer and use it in GitHub Desktop.
scope creep
This file contains 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
def inject(**vars): | |
def decorator(fn): | |
def fun(*args, **kwargs): | |
gls = globals().copy() | |
gls.update(vars) | |
new_fn = type(fn)(fn.__code__, gls) | |
return new_fn(*args, **kwargs) | |
return fun | |
return decorator | |
@inject(q=10, z=11) | |
def test(): | |
return q + z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure why any sane person would ever do this. But it is fun to know you can.