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: Implement `Signature.__repr__`
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: cool-RR, python-dev, terry.reedy, yselivanov
Priority: normal Keywords:

Created on 2014-01-24 14:05 by cool-RR, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg209112 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-01-24 19:48
Signature.__repr__ already exits. It is inherited from object. So you must be proposing to override the inherited method. For what purpose? With what outcome?

Without reading the signature PEP, I believe the current difference between str and repr is intentional, not accidental. Example:
>>> repr(s)
'<inspect.Signature object at 0x02E7BC08>'
>>> str(s)
'(self, a)'

If so, this issue should be closed unless you can provide an excellent reason to break code the expects the current behavior.
msg209114 - (view) Author: Ram Rachum (cool-RR) * Date: 2014-01-24 19:55
My impression is that the `__repr__` method of any object is intended to describe that object, hopefully in a succinct way, possibly in a REPL-friendly way (like `list.__repr__`  for example) but if not then at least human-friendly. This is for easy introspection. When I come across a Signature object in the shell, I want to immediately get a good feel for what it contains without exploring `vars(sig)` manully.

If you have a `Signature` object, why not have its `__repr__` return something like '<Signature f: alpha, beta=3, *args, **kwargs>`? This would do an awesome job at helping me understand what kind of signature object I'm looking at.
msg209455 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-01-27 18:10
Ram, yes, I agree. Something like '<Signature f: alpha, beta=3, *args, **kwargs>' should work.
msg209456 - (view) Author: Ram Rachum (cool-RR) * Date: 2014-01-27 18:12
If you'd like to expand this issue's scope to all the objects related to Signature, I think that'll be good. All objects need good introspection strings.
msg214966 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-27 16:42
New changeset 3f9a81297b39 by Yury Selivanov in branch 'default':
inspect.signature: Improve repr of Signature and Parameter. Closes #20378
http://hg.python.org/cpython/rev/3f9a81297b39
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64577
2014-03-27 16:42:21python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg214966

resolution: fixed
stage: test needed -> resolved
2014-01-27 18:12:54cool-RRsetmessages: + msg209456
2014-01-27 18:10:49yselivanovsetassignee: yselivanov
messages: + msg209455
2014-01-24 19:55:33cool-RRsetmessages: + msg209114
2014-01-24 19:48:49terry.reedysetnosy: + terry.reedy, yselivanov

messages: + msg209112
stage: test needed
2014-01-24 14:05:52cool-RRcreate