This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author larry
Recipients larry, rhettinger
Date 2022-02-24.09:39:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645695561.69.0.398852174273.issue46846@roundup.psfhosted.org>
In-reply-to
Content
I ran across an interesting bug in issue #46761.  If you call functools.update_wrapper on a functools.partial object, inspect.signature will return the wrong (original) signature for the partial object.

We're still figuring that one out.  And, of course, it's telling that the bug has been there for a long time.  I suspect this isn't something that has inconvenienced a lot of people.

But: I suggest that it's time functools.partial participated in signature stuff.  Specifically, I think functools.partial should generate a new and correct __signature__ for the partial object.  And I propose it should also generate a new and correct __annotations__ for the partial, by removing all entries for parameters that are filled in by the partial object.

Right now inspect.signature has special support for functools.partial objects.  It finds the underlying function, and .  Which means there's code in both modules that has to understand the internals of partial objects.  Just from a code hygiene perspective, it'd be better if all that logic lived under functools.

I wonder if functools.partial objects should generally do a better job of impersonating the original function.  Should they adopt the same __name__?  __file__?  __qualname__?  My intuition is, it'd be nice if it did.  But I might be forgetting something important.

(I suspect everything I said about functools.partial also applies to functools.partialmethod.)
History
Date User Action Args
2022-02-24 09:39:21larrysetrecipients: + larry, rhettinger
2022-02-24 09:39:21larrysetmessageid: <1645695561.69.0.398852174273.issue46846@roundup.psfhosted.org>
2022-02-24 09:39:21larrylinkissue46846 messages
2022-02-24 09:39:21larrycreate