@@ -741,6 +741,42 @@ class X(_A, B):
741741 x = X ()
742742 assert x .foo == "foo"
743743
744+ def test_slot_precedence (self ):
745+ MapAndSeq = CPyExtType ("MapAndSeq" ,
746+ '''
747+ static PyObject * mas_nb_add(PyObject *self, PyObject *other) {
748+ return PyUnicode_FromString("mas_nb_add");
749+ }
750+ static Py_ssize_t mas_sq_length(PyObject *self) {
751+ return 111;
752+ }
753+ static PyObject *mas_sq_item(PyObject *self, Py_ssize_t idx) {
754+ return PyUnicode_FromString("sq_item");
755+ }
756+ static PyObject * mas_sq_concat(PyObject *self, PyObject *other) {
757+ return PyUnicode_FromString("mas_sq_concat");
758+ }
759+ static Py_ssize_t mas_mp_length(PyObject *self) {
760+ return 222;
761+ }
762+ static PyObject * mas_mp_subscript(PyObject *self, PyObject *key) {
763+ return PyUnicode_FromString("mp_subscript");
764+ }
765+ ''' ,
766+ nb_add = 'mas_nb_add' ,
767+ sq_length = 'mas_sq_length' ,
768+ sq_item = 'mas_sq_item' ,
769+ sq_concat = 'mas_sq_concat' ,
770+ mp_length = 'mas_mp_length' ,
771+ mp_subscript = 'mas_mp_subscript' ,
772+ )
773+ obj = MapAndSeq ()
774+ # Note: len(obj) uses 'PyObject_Lenght' which does not use the attribute but first tries
775+ # 'sq_length' and falls back to 'mp_length'. Therefore, we just look at '__len__' here.
776+ assert obj .__len__ () == 222
777+ assert obj ['hello' ] == 'mp_subscript'
778+ assert obj + 'hello' == 'mas_nb_add'
779+
744780
745781class CBytes :
746782 def __bytes__ (self ):
0 commit comments