From 8af150216acfc2a900c648ade713df947b903970 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Tue, 9 Feb 2021 15:32:01 -0500 Subject: Make __repr__ more similar to other mapping types (#58) --- immutables/_map.c | 14 ++------------ immutables/map.py | 6 ++---- tests/test_map.py | 11 ++++------- tests/test_none_keys.py | 8 ++++---- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/immutables/_map.c b/immutables/_map.c index 9f0a586..7e510fd 100644 --- a/immutables/_map.c +++ b/immutables/_map.c @@ -3194,14 +3194,14 @@ map_py_repr(BaseMapObject *m) if (MapMutation_Check(m)) { if (_PyUnicodeWriter_WriteASCIIString( - &writer, "", m); - if (addr == NULL) { - goto error; - } - if (_PyUnicodeWriter_WriteStr(&writer, addr) < 0) { - Py_DECREF(addr); - goto error; - } - Py_DECREF(addr); - Py_ReprLeave((PyObject *)m); return _PyUnicodeWriter_Finish(&writer); diff --git a/immutables/map.py b/immutables/map.py index 7c16139..fe9dbaf 100644 --- a/immutables/map.py +++ b/immutables/map.py @@ -649,8 +649,7 @@ class Map: items = [] for key, val in self.items(): items.append("{!r}: {!r}".format(key, val)) - return ''.format( - ', '.join(items), id(self)) + return 'immutables.Map({{{}}})'.format(', '.join(items)) def __dump__(self): # pragma: no cover buf = [] @@ -818,8 +817,7 @@ class MapMutation: items = [] for key, val in self.__root.items(): items.append("{!r}: {!r}".format(key, val)) - return ''.format( - ', '.join(items), id(self)) + return 'immutables.MapMutation({{{}}})'.format(', '.join(items)) def __len__(self): return self.__count diff --git a/tests/test_map.py b/tests/test_map.py index b6ee7f1..4a473b3 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -845,11 +845,10 @@ class BaseMapTest: def test_repr_1(self): h = self.Map() - self.assertTrue(repr(h).startswith('