Stu schrieb am 12.08.2017 um 21:06:
> I tried compiling a .pyx file from pygame and hit "Invalid index type".
>
>
https://github.com/pygame/pygame/blob/master/src/pypm.pyx
>
> It seems like it works in cython 0.20, but not in 0.21
>
>
> Any idea what I need to fix ?
>
> Here is the error -
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> if num_events >= 1:
> for ev_no in range(num_events):
> events.append(
> [
> [
> buffer[ev_no].message & 0xFF,
> ^
> ------------------------------------------------------------
>
> pypm.pyx:697:34: Invalid index type 'PmError'
It's inferring the loop variable "ev_no" as enum type "PmError" because
that's what the type of "num_events" is. You can work around that with an
explicit cast like this:
for ev_no in range(<int>num_events):
although I'd rather type the "num_events" variable as "int" right away,
given your numeric comparison right above that line. Taking the range of an
enum value, especially an extern enum, has a bit of a code smell for me.
That being said, it could be argued that enum types as loop variables are
not something that Cython should ever infer itself. I'll see if I can do
something about it.
Stefan