From 0c937b3ed6d2eeca84fa4aca1a9aef685db65abc Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 22 Jul 2014 12:14:52 +0300 Subject: Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix when contain an id in form " at 0x...". --- Lib/ctypes/__init__.py | 2 +- Lib/reprlib.py | 2 +- Lib/test/test_reprlib.py | 2 +- Lib/test/test_weakref.py | 8 ++++++++ Lib/test/test_xmlrpc.py | 2 +- Lib/weakref.py | 4 ++-- Lib/xmlrpc/client.py | 4 ++-- Misc/NEWS | 3 +++ 8 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index e34c646..785bd18 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -353,7 +353,7 @@ class CDLL(object): self._handle = handle def __repr__(self): - return "<%s '%s', handle %x at %x>" % \ + return "<%s '%s', handle %x at %#x>" % \ (self.__class__.__name__, self._name, (self._handle & (_sys.maxsize*2 + 1)), id(self) & (_sys.maxsize*2 + 1)) diff --git a/Lib/reprlib.py b/Lib/reprlib.py index f803360..b7fda23 100644 --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -136,7 +136,7 @@ class Repr: # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except Exception: - return '<%s instance at %x>' % (x.__class__.__name__, id(x)) + return '<%s instance at %#x>' % (x.__class__.__name__, id(x)) if len(s) > self.maxother: i = max(0, (self.maxother-3)//2) j = max(0, self.maxother-3-i) diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py index ae67f06..d65494a 100644 --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -123,7 +123,7 @@ class ReprTests(unittest.TestCase): eq(r(i2), expected) i3 = ClassWithFailingRepr() - eq(r(i3), (""%id(i3))) + eq(r(i3), (""%id(i3))) s = r(ClassWithFailingRepr) self.assertTrue(s.startswith("') + + def test_make_weak_keyed_dict_repr(self): + dict = weakref.WeakKeyDictionary() + self.assertRegex(repr(dict), '') + from test import mapping_tests class WeakValueDictionaryTestCase(mapping_tests.BasicTestMappingProtocol): diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 120c54f..c184da3 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -287,7 +287,7 @@ class DateTimeTestCase(unittest.TestCase): def test_repr(self): d = datetime.datetime(2007,1,2,3,4,5) t = xmlrpclib.DateTime(d) - val ="" % id(t) + val ="" % id(t) self.assertEqual(repr(t), val) def test_decode(self): diff --git a/Lib/weakref.py b/Lib/weakref.py index f6a40ca..f780e7a 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -144,7 +144,7 @@ class WeakValueDictionary(collections.MutableMapping): return o is not None def __repr__(self): - return "" % id(self) + return "" % id(self) def __setitem__(self, key, value): if self._pending_removals: @@ -348,7 +348,7 @@ class WeakKeyDictionary(collections.MutableMapping): return len(self.data) - len(self._pending_removals) def __repr__(self): - return "" % id(self) + return "" % id(self) def __setitem__(self, key, value): self.data[ref(key, self._remove)] = value diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 567554d..d46f32c 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -354,7 +354,7 @@ class DateTime: return self.value def __repr__(self): - return "" % (self.value, id(self)) + return "" % (self.value, id(self)) def decode(self, data): self.value = str(data).strip() @@ -846,7 +846,7 @@ class MultiCall: self.__call_list = [] def __repr__(self): - return "" % id(self) + return "" % id(self) __str__ = __repr__ diff --git a/Misc/NEWS b/Misc/NEWS index e542d50..6c64bcf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,9 @@ Core and Builtins Library ------- +- Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix + when contain an id in form " at 0x...". + - Issue #22018: signal.set_wakeup_fd() now raises an OSError instead of a ValueError on ``fstat()`` failure. -- cgit v0.12