Created
November 3, 2021 21:31
-
-
Save zhudotexe/0487e3a7e483e3b930431e2f7ea3720d 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 inspect | |
| def show_sig(thing, scope): | |
| print(f"{scope}: {inspect.signature(thing)} - {inspect.ismethod(thing)=}") | |
| def deco_show_sig(func): | |
| show_sig(func, 'decorator') | |
| return func | |
| class Foo: | |
| @deco_show_sig | |
| def some_method(self, a, b): | |
| pass | |
| def other_method(self): | |
| def inner_method(): | |
| show_sig(self.some_method, 'inner') | |
| show_sig(self.some_method, 'method') | |
| inner_method() | |
| if __name__ == '__main__': | |
| Foo().other_method() | |
| # decorator: (self, a, b) - inspect.ismethod(thing)=False | |
| # method: (a, b) - inspect.ismethod(thing)=True | |
| # inner: (a, b) - inspect.ismethod(thing)=True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment