]> granicus.if.org Git - python/commitdiff
Issue #22031: Reprs now always use hexadecimal format with the "0x" prefix
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Jul 2014 09:14:52 +0000 (12:14 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 22 Jul 2014 09:14:52 +0000 (12:14 +0300)
when contain an id in form " at 0x...".

Lib/ctypes/__init__.py
Lib/reprlib.py
Lib/test/test_reprlib.py
Lib/test/test_weakref.py
Lib/test/test_xmlrpc.py
Lib/weakref.py
Lib/xmlrpc/client.py
Misc/NEWS

index e34c646e2d11ac1b01441521018e87a545340f21..785bd188702ec539b975c9addd378aca3a82725a 100644 (file)
@@ -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))
index f8033604da28da12dcad7d164580be638e51904a..b7fda23bd8f7b28b32b820079ff7b1360ecff32c 100644 (file)
@@ -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)
index ae67f06bc4efe4937a5fa0c18255668f9acebddb..d65494a856277469e2890f7c1112e350094fbbbf 100644 (file)
@@ -123,7 +123,7 @@ class ReprTests(unittest.TestCase):
         eq(r(i2), expected)
 
         i3 = ClassWithFailingRepr()
-        eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
+        eq(r(i3), ("<ClassWithFailingRepr instance at %#x>"%id(i3)))
 
         s = r(ClassWithFailingRepr)
         self.assertTrue(s.startswith("<class "))
index cccb5152527358d895ab3f8d5ccefac9153e6eba..adb923f2a38a090a221c0b72e018764e68993f46 100644 (file)
@@ -1536,6 +1536,14 @@ class MappingTestCase(TestBase):
         self.assertEqual(len(d), 0)
         self.assertEqual(count, 2)
 
+    def test_make_weak_valued_dict_repr(self):
+        dict = weakref.WeakValueDictionary()
+        self.assertRegex(repr(dict), '<WeakValueDictionary at 0x.*>')
+
+    def test_make_weak_keyed_dict_repr(self):
+        dict = weakref.WeakKeyDictionary()
+        self.assertRegex(repr(dict), '<WeakKeyDictionary at 0x.*>')
+
 from test import mapping_tests
 
 class WeakValueDictionaryTestCase(mapping_tests.BasicTestMappingProtocol):
index 120c54f16cdbab786411e24d709ab677fd9e4f73..c184da305ad3fb57df35c5868d724fbc105f4bbd 100644 (file)
@@ -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 ="<DateTime '20070102T03:04:05' at %x>" % id(t)
+        val ="<DateTime '20070102T03:04:05' at %#x>" % id(t)
         self.assertEqual(repr(t), val)
 
     def test_decode(self):
index f6a40ca4bf7d613c452ffb2c4a0ac4905b385477..f780e7a4692aa56d57a36eb980ef373063a0defb 100644 (file)
@@ -144,7 +144,7 @@ class WeakValueDictionary(collections.MutableMapping):
         return o is not None
 
     def __repr__(self):
-        return "<WeakValueDictionary at %s>" % id(self)
+        return "<WeakValueDictionary at %#x>" % 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 "<WeakKeyDictionary at %s>" % id(self)
+        return "<WeakKeyDictionary at %#x>" % id(self)
 
     def __setitem__(self, key, value):
         self.data[ref(key, self._remove)] = value
index 567554da37e8c835f40239c84c4a2f022e60fac4..d46f32c8df7e7271da60d01dc7717051a0872fe3 100644 (file)
@@ -354,7 +354,7 @@ class DateTime:
         return self.value
 
     def __repr__(self):
-        return "<DateTime %r at %x>" % (self.value, id(self))
+        return "<DateTime %r at %#x>" % (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 "<MultiCall at %x>" % id(self)
+        return "<MultiCall at %#x>" % id(self)
 
     __str__ = __repr__
 
index e542d50ac826ea7c3d8631fbf66fc3ca4d249dda..6c64bcf30c7e88b52972c70fe121187df1daf589 100644 (file)
--- 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.