@@ -488,29 +488,33 @@ framelocalsproxy_length(PyObject *self)
488488 return size ;
489489}
490490
491- static PyObject *
491+ static int
492492framelocalsproxy_contains (PyObject * self , PyObject * key )
493493{
494494 PyFrameObject * frame = ((PyFrameLocalsProxyObject * )self )-> frame ;
495495
496496 if (PyUnicode_CheckExact (key )) {
497497 int i = framelocalsproxy_getkeyindex (frame , key , true);
498498 if (i >= 0 ) {
499- Py_RETURN_TRUE ;
499+ return 1 ;
500500 }
501501 }
502502
503503 PyObject * extra = ((PyFrameObject * )frame )-> f_extra_locals ;
504504 if (extra != NULL ) {
505- int result = PyDict_Contains (extra , key );
506- if (result < 0 ) {
507- return NULL ;
508- } else if (result > 0 ) {
509- Py_RETURN_TRUE ;
510- }
505+ return PyDict_Contains (extra , key );
511506 }
512507
513- Py_RETURN_FALSE ;
508+ return 0 ;
509+ }
510+
511+ static PyObject * framelocalsproxy___contains__ (PyObject * self , PyObject * key )
512+ {
513+ int result = framelocalsproxy_contains (self , key );
514+ if (result < 0 ) {
515+ return NULL ;
516+ }
517+ return PyBool_FromLong (result );
514518}
515519
516520static PyObject *
@@ -604,14 +608,18 @@ static PyNumberMethods framelocalsproxy_as_number = {
604608 .nb_inplace_or = framelocalsproxy_inplace_or ,
605609};
606610
611+ static PySequenceMethods framelocalsproxy_as_sequence = {
612+ .sq_contains = framelocalsproxy_contains ,
613+ };
614+
607615static PyMappingMethods framelocalsproxy_as_mapping = {
608616 framelocalsproxy_length , // mp_length
609617 framelocalsproxy_getitem , // mp_subscript
610618 framelocalsproxy_setitem , // mp_ass_subscript
611619};
612620
613621static PyMethodDef framelocalsproxy_methods [] = {
614- {"__contains__" , framelocalsproxy_contains , METH_O | METH_COEXIST ,
622+ {"__contains__" , framelocalsproxy___contains__ , METH_O | METH_COEXIST ,
615623 NULL },
616624 {"__getitem__" , framelocalsproxy_getitem , METH_O | METH_COEXIST ,
617625 NULL },
@@ -639,6 +647,7 @@ PyTypeObject PyFrameLocalsProxy_Type = {
639647 .tp_dealloc = (destructor )framelocalsproxy_dealloc ,
640648 .tp_repr = & framelocalsproxy_repr ,
641649 .tp_as_number = & framelocalsproxy_as_number ,
650+ .tp_as_sequence = & framelocalsproxy_as_sequence ,
642651 .tp_as_mapping = & framelocalsproxy_as_mapping ,
643652 .tp_getattro = PyObject_GenericGetAttr ,
644653 .tp_setattro = PyObject_GenericSetAttr ,
0 commit comments