New submission from Larry Hastings <la...@hastings.org>:

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

----------
components: Library (Lib)
messages: 413897
nosy: larry, rhettinger
priority: normal
severity: normal
stage: test needed
status: open
title: functools.partial objects should set __signature__ and _annotations__
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46846>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to