bpo-40273: Reversible mappingproxy (FH-19513)
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index c9754a1..c29cf7a 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1118,6 +1118,13 @@
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy);
}
+static PyObject *
+mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
+{
+ _Py_IDENTIFIER(__reversed__);
+ return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__);
+}
+
/* WARNING: mappingproxy methods must not give access
to the underlying mapping */
@@ -1135,6 +1142,8 @@
PyDoc_STR("D.copy() -> a shallow copy of D")},
{"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("See PEP 585")},
+ {"__reversed__", (PyCFunction)mappingproxy_reversed, METH_NOARGS,
+ PyDoc_STR("D.__reversed__() -> reverse iterator")},
{0}
};