dict_items = type({}.items())
## misc ##
mappingproxy = type(type.__dict__)
+def _get_framelocalsproxy():
+ return type(sys._getframe().f_locals)
+framelocalsproxy = _get_framelocalsproxy()
+del _get_framelocalsproxy
generator = type((lambda: (yield))())
## coroutine ##
async def _coro(): pass
__reversed__ = None
Mapping.register(mappingproxy)
+Mapping.register(framelocalsproxy)
class MappingView(Sized):
except ImportError:
_testcapi = None
+from collections.abc import Mapping
from test import support
from test.support import import_helper, threading_helper
from test.support.script_helper import assert_python_ok
with self.assertRaises(TypeError):
copy.deepcopy(d)
+ def test_is_mapping(self):
+ x = 1
+ d = sys._getframe().f_locals
+ self.assertIsInstance(d, Mapping)
+ match d:
+ case {"x": value}:
+ self.assertEqual(value, 1)
+ kind = "mapping"
+ case _:
+ kind = "other"
+ self.assertEqual(kind, "mapping")
class TestFrameCApi(unittest.TestCase):
def test_basic(self):
--- /dev/null
+``FrameLocalsProxy`` now subclasses ``collections.abc.Mapping`` and can be
+matched as a mapping in ``match`` statements
.tp_as_mapping = &framelocalsproxy_as_mapping,
.tp_getattro = PyObject_GenericGetAttr,
.tp_setattro = PyObject_GenericSetAttr,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_MAPPING,
.tp_traverse = framelocalsproxy_visit,
.tp_clear = framelocalsproxy_tp_clear,
.tp_richcompare = framelocalsproxy_richcompare,