@@ -745,10 +745,9 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
745745 }
746746 // Short circuit if there aren't any arguments:
747747 Py_ssize_t nkwargs = PyTuple_GET_SIZE (kwargs );
748- Py_ssize_clean_t nattrs = nargs + nkwargs ;
748+ Py_ssize_t nattrs = nargs + nkwargs ;
749749 if (!nattrs ) {
750- PyObject * attrs = PyTuple_New (0 );
751- return attrs ;
750+ return PyTuple_New (0 );
752751 }
753752 // So far so good:
754753 PyObject * seen = NULL ;
@@ -803,7 +802,8 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
803802 }
804803 if (match_self ) {
805804 // Easy. Copy the subject itself, and move on to kwargs.
806- Py_INCREF (subject );
805+ Py_NewRef (subject );
806+ assert (PyTuple_GET_ITEM (attrs , 0 ) == NULL );
807807 PyTuple_SET_ITEM (attrs , 0 , subject );
808808 }
809809 else {
@@ -820,6 +820,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
820820 if (attr == NULL ) {
821821 goto fail ;
822822 }
823+ assert (PyTuple_GET_ITEM (attrs , i ) == NULL );
823824 PyTuple_SET_ITEM (attrs , i , attr );
824825 }
825826 }
@@ -832,6 +833,7 @@ _PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type,
832833 if (attr == NULL ) {
833834 goto fail ;
834835 }
836+ assert (PyTuple_GET_ITEM (attrs , nargs + i ) == NULL );
835837 PyTuple_SET_ITEM (attrs , nargs + i , attr );
836838 }
837839 Py_XDECREF (seen );
0 commit comments