Skip to content

Instantly share code, notes, and snippets.

@zhudotexe
Created November 3, 2021 21:31
Show Gist options
  • Select an option

  • Save zhudotexe/0487e3a7e483e3b930431e2f7ea3720d to your computer and use it in GitHub Desktop.

Select an option

Save zhudotexe/0487e3a7e483e3b930431e2f7ea3720d to your computer and use it in GitHub Desktop.
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