I wouldn't call it tricky, it's actually quite straightforward:
import inspect
def extract_default(function, parameter):
sig = inspect.signature(function)
param = sig.parameters[parameter]
return param.default
def do_something(count=5):
print(count)
def do_something_twice(count=None):
if count is None:
count = extract_default(do_something, "count")
do_something(count)
do_something(count)
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/KVEGN4CKKK2SJX4GT67MNCHGZYHNHDKJ/
Code of Conduct: http://python.org/psf/codeofconduct/