aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-04-03 00:10:20 -0400
committerYury Selivanov <yury@magic.io>2018-04-03 00:10:20 -0400
commit6140967d51cd7f0ce98bbce65f3f367b62eeb91a (patch)
tree7ec46c66fca39ef9055c3630b159dd91307add59
parent5804f0c47e60c7c2a0915cce2dbcfc7593881761 (diff)
downloadimmutables-6140967d51cd7f0ce98bbce65f3f367b62eeb91a.tar.gz
immutables-6140967d51cd7f0ce98bbce65f3f367b62eeb91a.zip
Make Map a subclass of collecitons.abc.Mapping
-rw-r--r--immutables/__init__.py3
-rw-r--r--immutables/_map.c2
-rw-r--r--immutables/map.py4
-rw-r--r--tests/test_map.py4
4 files changed, 12 insertions, 1 deletions
diff --git a/immutables/__init__.py b/immutables/__init__.py
index d598413..e900c2b 100644
--- a/immutables/__init__.py
+++ b/immutables/__init__.py
@@ -2,6 +2,9 @@ try:
from ._map import Map
except ImportError:
from .map import Map
+else:
+ import collections.abc as _abc
+ _abc.Mapping.register(Map)
__all__ = 'Map',
diff --git a/immutables/_map.c b/immutables/_map.c
index 3ed0393..be82cd9 100644
--- a/immutables/_map.c
+++ b/immutables/_map.c
@@ -3032,7 +3032,7 @@ static PyMappingMethods Map_as_mapping = {
PyTypeObject _Map_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "Map",
+ "immutables._map.Map",
sizeof(MapObject),
.tp_methods = Map_methods,
.tp_as_mapping = &Map_as_mapping,
diff --git a/immutables/map.py b/immutables/map.py
index b6d55dc..83c02bc 100644
--- a/immutables/map.py
+++ b/immutables/map.py
@@ -1,3 +1,4 @@
+import collections.abc
import reprlib
@@ -457,3 +458,6 @@ class Map:
buf = []
self.__root.dump(buf, 0)
return '\n'.join(buf)
+
+
+collections.abc.Mapping.register(Map)
diff --git a/tests/test_map.py b/tests/test_map.py
index 3e7633a..7af9513 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -1,3 +1,4 @@
+import collections.abc
import gc
import random
import unittest
@@ -795,6 +796,9 @@ class BaseMapTest:
with HaskKeyCrasher(error_on_hash=True):
hash(m)
+ def test_abc_1(self):
+ self.assertTrue(issubclass(self.Map, collections.abc.Mapping))
+
class PyMapTest(BaseMapTest, unittest.TestCase):