@@ -3850,7 +3850,6 @@ mapmut_tp_richcompare(PyObject *v, PyObject *w, int op)
38503850 }
38513851}
38523852
3853-
38543853static PyObject *
38553854mapmut_py_finalize (MapMutationObject * self , PyObject * args )
38563855{
@@ -3868,6 +3867,24 @@ mapmut_py_finalize(MapMutationObject *self, PyObject *args)
38683867 return (PyObject * )o ;
38693868}
38703869
3870+ static PyObject *
3871+ mapmut_py_enter (MapMutationObject * self , PyObject * args )
3872+ {
3873+ Py_INCREF (self );
3874+ return (PyObject * )self ;
3875+ }
3876+
3877+ static PyObject *
3878+ mapmut_py_exit (MapMutationObject * self , PyObject * args )
3879+ {
3880+ PyObject * ret = mapmut_py_finalize (self , NULL );
3881+ if (ret == NULL ) {
3882+ return NULL ;
3883+ }
3884+ Py_DECREF (ret );
3885+ Py_RETURN_FALSE ;
3886+ }
3887+
38713888static int
38723889mapmut_tp_ass_sub (MapMutationObject * self , PyObject * key , PyObject * val )
38733890{
@@ -3951,6 +3968,8 @@ static PyMethodDef MapMutation_methods[] = {
39513968 {"get" , (PyCFunction )map_py_get , METH_VARARGS , NULL },
39523969 {"pop" , (PyCFunction )mapmut_py_pop , METH_VARARGS , NULL },
39533970 {"finalize" , (PyCFunction )mapmut_py_finalize , METH_NOARGS , NULL },
3971+ {"__enter__" , (PyCFunction )mapmut_py_enter , METH_NOARGS , NULL },
3972+ {"__exit__" , (PyCFunction )mapmut_py_exit , METH_VARARGS , NULL },
39543973 {NULL , NULL }
39553974};
39563975
0 commit comments