[Python-ideas] Improving fn(arg=arg, name=name, wibble=wibble) code

Chris Angelico rosuav at gmail.com
Sat Sep 8 08:51:02 EDT 2018


On Sat, Sep 8, 2018 at 10:21 PM, Anders Hovmöller <boxed at killingar.net> wrote:
> It’s obvious but there is one easy way to shorten the code: using **kwargs. It’s way shorter but the down sides are:
>
> - the “real” function signature gets hidden so IDEs for example won’t pick it up
> - the error when you make a mistake when calling is not in your code anymore but one level down. This is confusing.
>
> One could imagine solving this specific case by having a type annotation of “this function has the types of that function”.  Maybe:
>
> def _open(*args: args_of_(sync_open), **kwargs: kwargs_of(sync_open) -> return_of(sync_open):
>
> But of course this only solves the case where there is a 1:1 mapping.

That can be done with functools.wraps().

ChrisA


More information about the Python-ideas mailing list