@@ -823,11 +823,7 @@ warn_explicit(PyThreadState *tstate, PyObject *category, PyObject *message,
823823
824824 /* Normalize message. */
825825 Py_INCREF (message ); /* DECREF'ed in cleanup. */
826- rc = PyObject_IsInstance (message , PyExc_Warning );
827- if (rc == -1 ) {
828- goto cleanup ;
829- }
830- if (rc == 1 ) {
826+ if (PyObject_TypeCheck (message , (PyTypeObject * )PyExc_Warning )) {
831827 text = PyObject_Str (message );
832828 if (text == NULL )
833829 goto cleanup ;
@@ -1124,26 +1120,25 @@ setup_context(Py_ssize_t stack_level,
11241120static PyObject *
11251121get_category (PyObject * message , PyObject * category )
11261122{
1127- int rc ;
1128-
1129- /* Get category. */
1130- rc = PyObject_IsInstance (message , PyExc_Warning );
1131- if (rc == -1 )
1132- return NULL ;
1133-
1134- if (rc == 1 )
1135- category = (PyObject * )Py_TYPE (message );
1136- else if (category == NULL || category == Py_None )
1137- category = PyExc_UserWarning ;
1123+ if (PyObject_TypeCheck (message , (PyTypeObject * )PyExc_Warning )) {
1124+ /* Ignore the category argument. */
1125+ return (PyObject * )Py_TYPE (message );
1126+ }
1127+ if (category == NULL || category == Py_None ) {
1128+ return PyExc_UserWarning ;
1129+ }
11381130
11391131 /* Validate category. */
1140- rc = PyObject_IsSubclass (category , PyExc_Warning );
1141- /* category is not a subclass of PyExc_Warning or
1142- PyObject_IsSubclass raised an error */
1143- if (rc == -1 || rc == 0 ) {
1132+ if (!PyType_Check (category )) {
1133+ PyErr_Format (PyExc_TypeError ,
1134+ "category must be a Warning subclass, not '%T'" ,
1135+ category );
1136+ return NULL ;
1137+ }
1138+ if (!PyType_IsSubtype ((PyTypeObject * )category , (PyTypeObject * )PyExc_Warning )) {
11441139 PyErr_Format (PyExc_TypeError ,
1145- "category must be a Warning subclass, not '%s '" ,
1146- Py_TYPE ( category ) -> tp_name );
1140+ "category must be a Warning subclass, not class '%N '" ,
1141+ ( PyTypeObject * ) category );
11471142 return NULL ;
11481143 }
11491144
0 commit comments