cpython: a444464a2e87 (original) (raw)
Mercurial > cpython
changeset 96059:a444464a2e87
Issue 22547: Implement informative __repr__ for inspect.BoundArguments
Yury Selivanov yselivanov@sprymix.com | |
---|---|
date | Thu, 14 May 2015 18:47:17 -0400 |
parents | 1cdcce187c43 |
children | 77ebd3720284 |
files | Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS |
diffstat | 3 files changed, 17 insertions(+), 0 deletions(-)[+] [-] Lib/inspect.py 7 Lib/test/test_inspect.py 7 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -2460,6 +2460,13 @@ class BoundArguments: def getstate(self): return {'_signature': self._signature, 'arguments': self.arguments}
- def repr(self):
args = [][](#l1.8)
for arg, value in self.arguments.items():[](#l1.9)
args.append('{}={!r}'.format(arg, value))[](#l1.10)
return '<{} at {:#x} ({})>'.format(self.__class__.__name__,[](#l1.11)
id(self), ', '.join(args))[](#l1.12)
+ class Signature: """A Signature object represents the overall signature of a function.
--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3149,6 +3149,13 @@ class TestBoundArguments(unittest.TestCa ba_pickled = pickle.loads(pickle.dumps(ba, ver)) self.assertEqual(ba, ba_pickled)
- def test_signature_bound_arguments_repr(self):
def foo(a, b, *, c:1={}, **kw) -> {42:'ham'}: pass[](#l2.8)
sig = inspect.signature(foo)[](#l2.9)
ba = sig.bind(20, 30, z={})[](#l2.10)
self.assertRegex(repr(ba),[](#l2.11)
r'<BoundArguments at 0x[a-fA-F0-9]+ \(a=20,.*\}\}\)>')[](#l2.12)
+ class TestSignaturePrivateHelpers(unittest.TestCase): def test_signature_get_bound_param(self):