Created
March 10, 2017 22:35
-
-
Save ssttuu/843906ed8b71cc65aa860f4230b177eb to your computer and use it in GitHub Desktop.
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
registered_methods = {} | |
class GetRegisteredMethodsMetaclass(type): | |
def __getattr__(self, item): | |
func = registered_methods.get(item) | |
if func: | |
return func | |
raise AttributeError('No registered method:', item) | |
class Registry(object): | |
__metaclass__ = GetRegisteredMethodsMetaclass | |
def wrapper(**kwargs_outer): | |
print 'in outside wrapper with kwargs', kwargs_outer | |
def decorator(f): | |
def union_the_kwargs_and_call(**the_kwargs): | |
the_kwargs.update(kwargs_outer) | |
return f(**the_kwargs) | |
registered_methods[f.__name__] = union_the_kwargs_and_call | |
return f | |
return decorator | |
@wrapper(test=1) | |
def curve_info(**kwargs): | |
print kwargs | |
return 1 | |
print 'Registry.curve_info: ', Registry.curve_info() | |
print 'Registry.curve_info: ', Registry.curve_info(my_kwargs='stu') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment