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.

classification
Title: Add inspect.Signature.from_callable()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: asvetlov, eric.snow, larry, python-dev, yselivanov
Priority: normal Keywords: patch

Created on 2013-03-07 07:51 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
signature-from-callable.diff eric.snow, 2013-03-07 07:51 review
Messages (10)
msg183636 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-03-07 07:51
While working on a subclass of inspect.Signature, I realized that inspect.signature is treated as the constructor.  So subclassing isn't so simple.  At first I considered adding an extra parameter to inspect.signature allowing different Signature classes.  Not much later it became clear that all that code should simply be in classmethod.  I've called it Signature.from_callable.  Patch attached.
msg183900 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2013-03-10 21:05
Agree in general, but you need to update the docs also.
msg207918 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-11 22:13
Hi Eric,

I'm not sure why do you want this. Having "Signature.from_callable" does not allow you to change behaviour of 'inspect.signature' function. More over, it creates a confusion about what API should be used - 'inspect.signature' or 'inspect.Signature.from_callable'.
msg207970 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-01-12 17:32
The difference is that inspect.signature is not friendly to Signature
subclasses.  Without from_callable you can't customize the behavior in
inspect.signature easily.
msg207971 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-12 17:41
> The difference is that inspect.signature is not friendly to Signature
> subclasses.  Without from_callable you can't customize the behavior in
> inspect.signature easily.

OK, suppose you have "Signature.from_callable".  You then create a subclass
MySignature, and override it. How can you customize 'inspect.signature' to 
use the MySignature class?
msg207972 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-12 17:53
Eric,

Moreover, 'Signature.from_function' and newly added 'Signature.from_builtin'
are private API, or implementation detail (they are not part of PEP, not
mentioned in the docs). If at some point it is needed to rewrite Signature 
in C, probably those two won't be a part of a new implementation.
msg207973 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-01-12 17:58
It's not about customizing inspect.signature.  It's about customizing the
nice behavior of that function, including what type it returns.
msg207974 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-12 18:09
OK, got it now.

Green light from me. Looking through the code, I saw that 'from_builtin' doesn't use the 'Signature._parameter_cls' (as in from_function). That's probably needs to be fixed as well, maybe in a separate issue.
msg214961 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-27 16:12
New changeset 8a4e44473fdd by Yury Selivanov in branch 'default':
inspect.Signature: Add 'Signature.from_callable' classmethod. Closes #17373
http://hg.python.org/cpython/rev/8a4e44473fdd
msg214965 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-03-27 16:26
Thanks, Yury!
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61575
2014-03-27 16:26:33eric.snowsetmessages: + msg214965
2014-03-27 16:12:02python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg214961

resolution: fixed
stage: patch review -> resolved
2014-02-25 01:01:49yselivanovsetassignee: yselivanov
2014-01-23 19:40:09yselivanovsetversions: + Python 3.5, - Python 3.4
2014-01-12 18:09:44yselivanovsetmessages: + msg207974
2014-01-12 17:58:42eric.snowsetmessages: + msg207973
2014-01-12 17:53:38yselivanovsetmessages: + msg207972
2014-01-12 17:41:55yselivanovsetmessages: + msg207971
2014-01-12 17:32:50eric.snowsetmessages: + msg207970
2014-01-11 22:13:58yselivanovsetnosy: + yselivanov
messages: + msg207918
2013-03-10 21:05:25asvetlovsetnosy: + asvetlov
messages: + msg183900
2013-03-07 07:51:49eric.snowcreate