From 6140967d51cd7f0ce98bbce65f3f367b62eeb91a Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 3 Apr 2018 00:10:20 -0400 Subject: Make Map a subclass of collecitons.abc.Mapping --- immutables/__init__.py | 3 +++ immutables/_map.c | 2 +- immutables/map.py | 4 ++++ tests/test_map.py | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) 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): -- cgit v1.2.3