inspect: Remove "0x..." IDs from Signature objects' __repr__

Issue 24200.
This commit is contained in:
Yury Selivanov 2015-05-15 12:53:56 -04:00
parent 51b58325f9
commit f229bc5c53
2 changed files with 4 additions and 8 deletions

View File

@ -2346,8 +2346,7 @@ class Parameter:
return formatted return formatted
def __repr__(self): def __repr__(self):
return '<{} at {:#x} "{}">'.format(self.__class__.__name__, return '<{} "{}">'.format(self.__class__.__name__, self)
id(self), self)
def __hash__(self): def __hash__(self):
return hash((self.name, self.kind, self.annotation, self.default)) return hash((self.name, self.kind, self.annotation, self.default))
@ -2464,8 +2463,7 @@ class BoundArguments:
args = [] args = []
for arg, value in self.arguments.items(): for arg, value in self.arguments.items():
args.append('{}={!r}'.format(arg, value)) args.append('{}={!r}'.format(arg, value))
return '<{} at {:#x} ({})>'.format(self.__class__.__name__, return '<{} ({})>'.format(self.__class__.__name__, ', '.join(args))
id(self), ', '.join(args))
class Signature: class Signature:
@ -2835,8 +2833,7 @@ class Signature:
self._return_annotation = state['_return_annotation'] self._return_annotation = state['_return_annotation']
def __repr__(self): def __repr__(self):
return '<{} at {:#x} "{}">'.format(self.__class__.__name__, return '<{} {}>'.format(self.__class__.__name__, self)
id(self), self)
def __str__(self): def __str__(self):
result = [] result = []

View File

@ -3153,8 +3153,7 @@ class TestBoundArguments(unittest.TestCase):
def foo(a, b, *, c:1={}, **kw) -> {42:'ham'}: pass def foo(a, b, *, c:1={}, **kw) -> {42:'ham'}: pass
sig = inspect.signature(foo) sig = inspect.signature(foo)
ba = sig.bind(20, 30, z={}) ba = sig.bind(20, 30, z={})
self.assertRegex(repr(ba), self.assertRegex(repr(ba), r'<BoundArguments \(a=20,.*\}\}\)>')
r'<BoundArguments at 0x[a-fA-F0-9]+ \(a=20,.*\}\}\)>')
class TestSignaturePrivateHelpers(unittest.TestCase): class TestSignaturePrivateHelpers(unittest.TestCase):