On Wed, Jul 27, 2022 at 1:07 PM Chris Angelico <ros...@gmail.com> wrote:

> with all the variants of keyword and positional args. Being able to
> say "this function has the same signature as that one, plus it accepts
> consumed_arg" or "same, but without added_arg" would be extremely
> useful, and short of some fairly detailed messing around, not easy at
> the moment.
>

I would suggest checking out python-makefun, which can do many
transformations on the signature of the method:
https://smarie.github.io/python-makefun/ The wrapt library also does some
of this, though the process for adding or removing fields is more
convoluted than with makefun.

It might be interesting to put this in the standard library (e.g. expanding
functools.wraps), though there are third party libraries that do a
reasonable job.


> So rather than proposals for weird magic objects that do weird things
> as function arguments, I'd much rather see proposals to fix the
> reported signature, which would largely solve the problem without
> magic. (Or technically, without *more* magic; the only magic needed is
> "if the function has a __wrapped__ attribute, use the signature from
> that", which already exists in many tools.)
>

Note that per PEP 362, tools should also respect the __signature__ magic
attribute (and that should override the signature of .__wrapped__ when both
are present).

Best wishes,
Lucas
_______________________________________________
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/RIWRVBOPBI33DIVEGCCGAG2I6YQTZ6VT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to