That won't work with at least some builtins written in C, and maybe extension modules. I just checked 3.9 and str.count, and inspect.signature fails with ValueError: no signature found for builtin <method 'count' of 'str' objects>.

I don't know if Argument Clinic (AC) would improve this, or maybe it's outside of what AC can help with.

I've often wanted to call functions, including builtins, and say "just use the default", so I can see the need for a more reliable way of finding the defaults.

Eric

On 10/26/2020 5:25 AM, jan.t...@inter.de wrote:
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 -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KVEGN4CKKK2SJX4GT67MNCHGZYHNHDKJ/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/A52FIM7UIMMTAQD5GGZ474ORX5JSDPMS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to