Skip to content

Commit 6140967

Browse files
committed
Make Map a subclass of collecitons.abc.Mapping
1 parent 5804f0c commit 6140967

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

immutables/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from ._map import Map
33
except ImportError:
44
from .map import Map
5+
else:
6+
import collections.abc as _abc
7+
_abc.Mapping.register(Map)
58

69

710
__all__ = 'Map',

immutables/_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,7 @@ static PyMappingMethods Map_as_mapping = {
30323032

30333033
PyTypeObject _Map_Type = {
30343034
PyVarObject_HEAD_INIT(NULL, 0)
3035-
"Map",
3035+
"immutables._map.Map",
30363036
sizeof(MapObject),
30373037
.tp_methods = Map_methods,
30383038
.tp_as_mapping = &Map_as_mapping,

immutables/map.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import collections.abc
12
import reprlib
23

34

@@ -457,3 +458,6 @@ def __dump__(self):
457458
buf = []
458459
self.__root.dump(buf, 0)
459460
return '\n'.join(buf)
461+
462+
463+
collections.abc.Mapping.register(Map)

tests/test_map.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import collections.abc
12
import gc
23
import random
34
import unittest
@@ -795,6 +796,9 @@ def test_hash_2(self):
795796
with HaskKeyCrasher(error_on_hash=True):
796797
hash(m)
797798

799+
def test_abc_1(self):
800+
self.assertTrue(issubclass(self.Map, collections.abc.Mapping))
801+
798802

799803
class PyMapTest(BaseMapTest, unittest.TestCase):
800804

0 commit comments

Comments
 (0)