-
-
Save uranusjr/1e824ad86f02d0a262e2 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
import functools | |
class Api: | |
def __init__(self): | |
self.apis = [] | |
def register(self, f): | |
self.apis.append(f.__name__) | |
@functools.wraps(f) | |
def wrapper(*args, **kwargs): | |
f(*args, **kwargs) | |
return wrapper |
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 api | |
myapi = api.Api() | |
@myapi.register | |
def p(s, q=None): | |
print(s) | |
print(q) | |
@myapi.register | |
def b(): | |
print('b') | |
myapi2 = api.Api() | |
@myapi2.register | |
def c(): | |
print('c') | |
print(myapi.apis) | |
print(myapi2.apis) | |
p('s', q='q') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment