@@ -9393,22 +9393,19 @@ super_repr(PyObject *self)
93939393 su -> type ? su -> type -> tp_name : "NULL" );
93949394}
93959395
9396- // if `method` is non-NULL, we are looking for a method descriptor,
9397- // and setting `*method` to 1 means we found one.
9396+ /* Do a super lookup without executing descriptors or falling back to getattr
9397+ on the super object itself.
9398+
9399+ May return NULL with or without an exception set, like PyDict_GetItemWithError. */
93989400static PyObject *
9399- do_super_lookup (superobject * su , PyTypeObject * su_type , PyObject * su_obj ,
9400- PyTypeObject * su_obj_type , PyObject * name , int * method )
9401+ _super_lookup_descr (PyTypeObject * su_type , PyTypeObject * su_obj_type , PyObject * name )
94019402{
94029403 PyObject * mro , * res ;
94039404 Py_ssize_t i , n ;
9404- int temp_su = 0 ;
9405-
9406- if (su_obj_type == NULL )
9407- goto skip ;
94089405
94099406 mro = su_obj_type -> tp_mro ;
94109407 if (mro == NULL )
9411- goto skip ;
9408+ return NULL ;
94129409
94139410 assert (PyTuple_Check (mro ));
94149411 n = PyTuple_GET_SIZE (mro );
@@ -9420,7 +9417,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
94209417 }
94219418 i ++ ; /* skip su->type (if any) */
94229419 if (i >= n )
9423- goto skip ;
9420+ return NULL ;
94249421
94259422 /* keep a strong reference to mro because su_obj_type->tp_mro can be
94269423 replaced during PyDict_GetItemWithError(dict, name) */
@@ -9433,22 +9430,6 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
94339430 res = PyDict_GetItemWithError (dict , name );
94349431 if (res != NULL ) {
94359432 Py_INCREF (res );
9436- if (method && _PyType_HasFeature (Py_TYPE (res ), Py_TPFLAGS_METHOD_DESCRIPTOR )) {
9437- * method = 1 ;
9438- }
9439- else {
9440- descrgetfunc f = Py_TYPE (res )-> tp_descr_get ;
9441- if (f != NULL ) {
9442- PyObject * res2 ;
9443- res2 = f (res ,
9444- /* Only pass 'obj' param if this is instance-mode super
9445- (See SF ID #743627) */
9446- (su_obj == (PyObject * )su_obj_type ) ? NULL : su_obj ,
9447- (PyObject * )su_obj_type );
9448- Py_SETREF (res , res2 );
9449- }
9450- }
9451-
94529433 Py_DECREF (mro );
94539434 return res ;
94549435 }
@@ -9460,6 +9441,45 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
94609441 i ++ ;
94619442 } while (i < n );
94629443 Py_DECREF (mro );
9444+ return NULL ;
9445+ }
9446+
9447+ // if `method` is non-NULL, we are looking for a method descriptor,
9448+ // and setting `*method = 1` means we found one.
9449+ static PyObject *
9450+ do_super_lookup (superobject * su , PyTypeObject * su_type , PyObject * su_obj ,
9451+ PyTypeObject * su_obj_type , PyObject * name , int * method )
9452+ {
9453+ PyObject * res ;
9454+ int temp_su = 0 ;
9455+
9456+ if (su_obj_type == NULL ) {
9457+ goto skip ;
9458+ }
9459+
9460+ res = _super_lookup_descr (su_type , su_obj_type , name );
9461+ if (res != NULL ) {
9462+ if (method && _PyType_HasFeature (Py_TYPE (res ), Py_TPFLAGS_METHOD_DESCRIPTOR )) {
9463+ * method = 1 ;
9464+ }
9465+ else {
9466+ descrgetfunc f = Py_TYPE (res )-> tp_descr_get ;
9467+ if (f != NULL ) {
9468+ PyObject * res2 ;
9469+ res2 = f (res ,
9470+ /* Only pass 'obj' param if this is instance-mode super
9471+ (See SF ID #743627) */
9472+ (su_obj == (PyObject * )su_obj_type ) ? NULL : su_obj ,
9473+ (PyObject * )su_obj_type );
9474+ Py_SETREF (res , res2 );
9475+ }
9476+ }
9477+
9478+ return res ;
9479+ }
9480+ else if (PyErr_Occurred ()) {
9481+ return NULL ;
9482+ }
94639483
94649484 skip :
94659485 if (su == NULL ) {
@@ -9557,6 +9577,18 @@ _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *me
95579577 return res ;
95589578}
95599579
9580+ PyObject *
9581+ _PySuper_LookupDescr (PyTypeObject * su_type , PyObject * su_obj , PyObject * name )
9582+ {
9583+ PyTypeObject * su_obj_type = supercheck (su_type , su_obj );
9584+ if (su_obj_type == NULL ) {
9585+ return NULL ;
9586+ }
9587+ PyObject * res = _super_lookup_descr (su_type , su_obj_type , name );
9588+ Py_DECREF (su_obj_type );
9589+ return res ;
9590+ }
9591+
95609592static PyObject *
95619593super_descr_get (PyObject * self , PyObject * obj , PyObject * type )
95629594{
0 commit comments