changeset: 89996:3f9a81297b39 user: Yury Selivanov date: Thu Mar 27 12:41:53 2014 -0400 files: Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS description: inspect.signature: Improve repr of Signature and Parameter. Closes #20378 diff -r bcc77493249c -r 3f9a81297b39 Lib/inspect.py --- a/Lib/inspect.py Thu Mar 27 12:21:20 2014 -0400 +++ b/Lib/inspect.py Thu Mar 27 12:41:53 2014 -0400 @@ -2192,8 +2192,8 @@ return formatted def __repr__(self): - return '<{} at {:#x} {!r}>'.format(self.__class__.__name__, - id(self), self.name) + return '<{} at {:#x} "{}">'.format(self.__class__.__name__, + id(self), self) def __eq__(self, other): # NB: We deliberately do not compare '_partial_kwarg' attributes @@ -2698,6 +2698,10 @@ def __setstate__(self, state): self._return_annotation = state['_return_annotation'] + def __repr__(self): + return '<{} at {:#x} "{}">'.format(self.__class__.__name__, + id(self), self) + def __str__(self): result = [] render_pos_only_separator = False diff -r bcc77493249c -r 3f9a81297b39 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Thu Mar 27 12:21:20 2014 -0400 +++ b/Lib/test/test_inspect.py Thu Mar 27 12:41:53 2014 -0400 @@ -1667,6 +1667,9 @@ with self.assertRaisesRegex(ValueError, 'follows default argument'): S((pkd, pk)) + self.assertTrue(repr(sig).startswith(' {42:'ham'}: pass foo_partial = functools.partial(foo, a=1) @@ -2575,6 +2578,7 @@ p.replace(kind=inspect.Parameter.VAR_POSITIONAL) self.assertTrue(repr(p).startswith('