diff --git a/immutables/_map.c b/immutables/_map.c index 7e510fd1..61ca2b96 100644 --- a/immutables/_map.c +++ b/immutables/_map.c @@ -3414,7 +3414,11 @@ PyTypeObject _Map_Type = { .tp_iter = (getiterfunc)map_tp_iter, .tp_dealloc = (destructor)map_tp_dealloc, .tp_getattro = PyObject_GenericGetAttr, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC + #ifdef Py_TPFLAGS_MAPPING + | Py_TPFLAGS_MAPPING + #endif + , .tp_richcompare = map_tp_richcompare, .tp_traverse = (traverseproc)map_tp_traverse, .tp_clear = (inquiry)map_tp_clear, diff --git a/tests/conftest.py b/tests/conftest.py index 9eb9e611..210f55b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +import sys # We need the mypy pytest plugin to do the test collection for our # typing tests. @@ -11,3 +12,6 @@ pytest_plugins = [ 'mypy.test.data', ] + +if sys.version_info < (3, 10): + collect_ignore = ["test_pattern_matching.py"] diff --git a/tests/test_pattern_matching.py b/tests/test_pattern_matching.py new file mode 100644 index 00000000..340d6de2 --- /dev/null +++ b/tests/test_pattern_matching.py @@ -0,0 +1,38 @@ +import unittest + +from immutables.map import Map as PyMap + + +class BaseMapTest: + + Map = None + + def test_map_can_be_matched(self): + match self.Map(a=1, b=2): # noqa: E999 + case {"a": 1 as matched}: + matched = matched + case _: + assert False + + assert matched == 1 + + +class PyMapTest(BaseMapTest, unittest.TestCase): + + Map = PyMap + + +try: + from immutables._map import Map as CMap +except ImportError: + CMap = None + + +@unittest.skipIf(CMap is None, 'C Map is not available') +class CMapTest(BaseMapTest, unittest.TestCase): + + Map = CMap + + +if __name__ == "__main__": + unittest.main()