Matthew Einhorn schrieb am 16.04.2015 um 19:23:
> I abstracted the example code I posted above based on a similar issue we
> were having in Kivy where gcc failed. Kivy has Cython code, hence the issue
> of installing Kivy with 0.22.
I understand that developers need Cython to work on kivy. I was just
wondering why users need Cython in order to *install* kivy. Usually,
shipping the generated (and tested) C sources avoids that.
> Regarding the issue, we decided to fix it in Kivy by making them all except
> -1. But I'm wondering now, if the parent class declares with `except -1`,
> would a derived class be able to overwrite it with `except *`? I'm not sure
> if we need that, but am just wondering about that case.
In this case, calling
(<BaseClass>x).method()
would propagate an exception only if method() returns -1, but
(<ChildClass>x).method()
would always check for an exception and propagate it. Now, if "x" is
actually of type ChildClass, then it could expect that calling code would
always check for an exception and return, say, -2 in that case. This is not
covered by the first case above, and the exception would fail to propagate
whenever calling code thinks it's calling the base type method.
The other direction could work, though. Meaning, if you tighten the
exception propagation exception from "except *" in the base class (always
check) to "except -1" in the child class, then code that thinks it's
calling the base class method would always check for an exception, and code
that knows that it's calling the child method would explicitly check for
the error return value and thus avoid redundant checks.
However, that being said, "except *" cannot actually be used in
non-external functions/methods (i.e. in the actual implementation), as
Cython wouldn't know what to return in the case of an error.
Stefan