[Python-Dev] Bug in Py_InitModule4
collinw at gmail.com
Thu Dec 29 16:46:28 CET 2005
While working with Subversion's python API bindings this morning, I
discovered a function in one of their modules illegally named "import"
(svn.client.import, for the curious). Because the extension module in
question is written in C, the interpreter doesn't flag the
otherwise-illegal identifier "import" at compile-time; if you try to
call the function at runtime, however, the interpreter raises a
SyntaxError, since svn.client.import is an illegal name.
My question is this: is there any interest in preventing situations
like this by including checks in Python/modsupport.c:Py_InitModule4 to
make sure that the PyMethodDef contains only valid identifiers, or is
this a case of "if it hurts when you do that, don't do that"? I can
see a case for both sides: on the one hand, it would be nice to
prevent people from accidentally creating inaccessible objects. On the
other hand, perhaps this is a job that should be given to tools like
SWIG, since they're the ones actually generating the bindings (in the
case of SVN).
I've already reported this to the SVN people, but if there's any
interest in a CPython-side solution, I'm more than willing to work up
a patch to modsupport.c.
More information about the Python-Dev