@@ -9628,7 +9628,7 @@ FUNCNAME(PyObject *self, PyObject *other) \
96289628{ \
96299629 PyObject* stack[2]; \
96309630 PyThreadState *tstate = _PyThreadState_GET(); \
9631- int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
9631+ int do_other = /*(void*)TESTFUNC != (void*)slot_nb_power &&*/ !Py_IS_TYPE (self , Py_TYPE (other )) && \
96329632 Py_TYPE (other )-> tp_as_number != NULL && \
96339633 Py_TYPE (other )-> tp_as_number -> SLOTNAME == TESTFUNC ; \
96349634 if (Py_TYPE (self )-> tp_as_number != NULL && \
@@ -9813,13 +9813,46 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
98139813{
98149814 if (modulus == Py_None )
98159815 return slot_nb_power_binary (self , other );
9816- /* Three-arg power doesn't use __rpow__. But ternary_op
9817- can call this when the second argument's type uses
9818- slot_nb_power, so check before calling self.__pow__. */
9816+
9817+ /* The following code is a copy of SLOT1BINFULL, but for three arguments. */
9818+ PyObject * stack [3 ];
9819+ PyThreadState * tstate = _PyThreadState_GET ();
9820+ int do_other = !Py_IS_TYPE (self , Py_TYPE (other )) &&
9821+ Py_TYPE (other )-> tp_as_number != NULL &&
9822+ Py_TYPE (other )-> tp_as_number -> nb_power == slot_nb_power ;
98199823 if (Py_TYPE (self )-> tp_as_number != NULL &&
98209824 Py_TYPE (self )-> tp_as_number -> nb_power == slot_nb_power ) {
9821- PyObject * stack [3 ] = {self , other , modulus };
9822- return vectorcall_method (& _Py_ID (__pow__ ), stack , 3 );
9825+ PyObject * r ;
9826+ if (do_other && PyType_IsSubtype (Py_TYPE (other ), Py_TYPE (self ))) {
9827+ int ok = method_is_overloaded (self , other , & _Py_ID (__rpow__ ));
9828+ if (ok < 0 ) {
9829+ return NULL ;
9830+ }
9831+ if (ok ) {
9832+ stack [0 ] = other ;
9833+ stack [1 ] = self ;
9834+ stack [2 ] = modulus ;
9835+ r = vectorcall_maybe (tstate , & _Py_ID (__rpow__ ), stack , 3 );
9836+ if (r != Py_NotImplemented )
9837+ return r ;
9838+ Py_DECREF (r );
9839+ do_other = 0 ;
9840+ }
9841+ }
9842+ stack [0 ] = self ;
9843+ stack [1 ] = other ;
9844+ stack [2 ] = modulus ;
9845+ r = vectorcall_maybe (tstate , & _Py_ID (__pow__ ), stack , 3 );
9846+ if (r != Py_NotImplemented ||
9847+ Py_IS_TYPE (other , Py_TYPE (self )))
9848+ return r ;
9849+ Py_DECREF (r );
9850+ }
9851+ if (do_other ) {
9852+ stack [0 ] = other ;
9853+ stack [1 ] = self ;
9854+ stack [2 ] = modulus ;
9855+ return vectorcall_maybe (tstate , & _Py_ID (__rpow__ ), stack , 3 );
98239856 }
98249857 Py_RETURN_NOTIMPLEMENTED ;
98259858}
0 commit comments