[Pyrex] patch to avoid calling PyObject_TypeCheck in __Pyx_ArgTypeTest if object is None

Stefan Behnel behnel_ml at gkec.informatik.tu-darmstadt.de
Wed Apr 19 12:50:18 CEST 2006


Hi,

this is a small patch that avoids calling PyObject_TypeCheck() from within
__Pyx_ArgTypeTest in the case where obj is the not-allowed None value.

Possible drawback: calling __Pyx_ArgTypeTest(obj, NoneType, 0, "obj") will
result in the somewhat misleading error message "Argument 'obj' has incorrect
type (expected NoneType, got NoneType)". But then, that call would be a bug in
the program, not Pyrex. Currently, this bug would pass silently.

Stefan

--- Pyrex/Compiler/Nodes.py.orig        2006-04-19 12:23:26.000000000 +0200
+++ Pyrex/Compiler/Nodes.py     2006-04-19 12:25:10.000000000 +0200
@@ -3695,7 +3695,11 @@
         PyErr_Format(PyExc_SystemError, "Missing type object");
         return 0;
     }
-    if ((none_allowed && obj == Py_None) || PyObject_TypeCheck(obj, type))
+    if (obj == Py_None) {
+        if (none_allowed)
+            return 1;
+    }
+    else if (PyObject_TypeCheck(obj, type))
         return 1;
     PyErr_Format(PyExc_TypeError,
         "Argument '%s' has incorrect type (expected %s, got %s)",




More information about the Pyrex mailing list