
On Thu, 28 Jul 2022 at 00:08, Eric V. Smith <eric@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