Answer the question
In order to leave comments, you need to log in
How to combine function signatures so that help displays multiple options?
There are several overloaded functions:
@singledispatch
def get():
"""main docstring"""
...
@get.register(str)
def _get_str(s):
"""str docstring"""
print('str')\
@get.register(int)
def _get_int(i):
print('int')
get(1) # int
get('s') # str
help(get)
Help on function get in module __main__:
get()
main docstring
get.__signature__ = inspect.signature(_get_str)
help(get)
Help on function get in module __main__:
get(s)
main docstring
Help on function get in module __main__:
get()
main docstring
get(s)
str docstring
get(i)
Answer the question
In order to leave comments, you need to log in
@singledispatch
def get(date):
"""main docstring"""
print('main')
@get.register(datetime.date)
def _get_str(s):
"""str docstring"""
print('date')
get.__doc__ = '\n'.join([
get.__doc__,
f'\b\b{get.__name__}{inspect.signature(_get_str)}',
_get_str.__doc__,
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question