Gabriel Jacobo, 09.05.2013 18:39:
> 2013/5/9 Robert Bradshaw
To reproduce this, it's enough to clone the ignifuga repo, rename the "src"
folder to "ignifuga", and then call
cython ignifuga/backends/sdl/GameLoop.pyx
I don't know why the folder is called "src" when the main package is
supposed to be called "ignifuga", but I guess that's not part of the
problem here, given that fixing the name shows the error.
There also seems to be some preprocessing in place, given that I get
additional compile errors like this:
"""
Error compiling Cython file:
------------------------------------------------------------
...
self._screen_w, self._screen_h = self.renderer.screenSize
self.paused = False
self.ticks_second = SDL_GetPerformanceFrequency()
#if DEBUG and (__LINUX__ or __OSX__ or __MINGW__)
self.fw = new FileWatcher()
^
------------------------------------------------------------
ignifuga/backends/sdl/GameLoop.pyx:29:22: Operation only allowed in c++
"""
I wonder why this doesn't just spell as a plain "if DEBUG ...", but I guess
there's a reason. In any case, removing these blocks from the source also
drops their compile errors, just leaving the one in question.
My debugger then tells me that "time" is defined in "cpython/datetime.pxd"
as an extension type, and declared extension types cannot be assigned to.
Looking around a bit more, I see several places that carelessly do "from
cpython cimport *", which obviously leads to massive namespace pollution
that spreads in a hard to controll way. It appears that while "from ...
import *" is just frowned upon in Python code (although heavily so by many
developers), it can actually lead to compile errors and maybe even serious
bugs in Cython code.
The reason why this appeared with 0.19 is that Cython gained its own
cpython/datetime.pxd with several low-level declarations that make this
module more easily accessible. One of those is for the "time" type. Your
star-imports now pick these declarations up and change the way Cython
analyses your code.
So, my advice: clean up your code to make it easier to understand for
yourself and more robust against changes in external code. Star-imports are
discouraged for good reason.
That being said, I still think it's a bad idea that the "cpython" package
uses "from lotsofstuff cimport *" for all underlying submodules. We ran
into this kind of problem at least once already (with "bool" IIRC), and I'm
sure it will keep reoccurring sporadically.
As a fix for this specific problem, I removed the line
from cpython.datetime cimport *
in cpython/__init__.pxd. That line is really wrong, given that "datetime"
is not a core C-API thing but an external module (like the "array" module).
Stefan