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.
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:42 | admin | set | github: 61575 |
| 2014年03月27日 16:26:33 | eric.snow | set | messages: + msg214965 |
| 2014年03月27日 16:12:02 | python-dev | set | status: open -> closed nosy: + python-dev messages: + msg214961 resolution: fixed stage: patch review -> resolved |
| 2014年02月25日 01:01:49 | yselivanov | set | assignee: yselivanov |
| 2014年01月23日 19:40:09 | yselivanov | set | versions: + Python 3.5, - Python 3.4 |
| 2014年01月12日 18:09:44 | yselivanov | set | messages: + msg207974 |
| 2014年01月12日 17:58:42 | eric.snow | set | messages: + msg207973 |
| 2014年01月12日 17:53:38 | yselivanov | set | messages: + msg207972 |
| 2014年01月12日 17:41:55 | yselivanov | set | messages: + msg207971 |
| 2014年01月12日 17:32:50 | eric.snow | set | messages: + msg207970 |
| 2014年01月11日 22:13:58 | yselivanov | set | nosy:
+ yselivanov messages: + msg207918 |
| 2013年03月10日 21:05:25 | asvetlov | set | nosy:
+ asvetlov messages: + msg183900 |
| 2013年03月07日 07:51:49 | eric.snow | create | |