On Thu, 28 Jul 2022 at 00:08, Eric V. Smith <e...@trueblade.com> wrote:
>
> Sorry for top posting: I’m on the road.
>
> inspect.signature can help with this.
>

Technically true, and a good basis for a proposal, but try designing a
modified signature and you'll find that it's actually pretty hard.
What I'd like to see would be a way to decorate two key types of
change:

@functools.wraps_ish(func)
def wrapper(*a, consumed_arg="spam", **kw):
    return func(*a, **kw)

@functools.wraps_ish(func):
def wrapper(*a, **kw):
    return func(*a, added_arg=1, **kw)

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.

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.)

ChrisA
_______________________________________________
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/W6ITSZPEFG647XBYD5LCCKIWSGXL74Z4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to