Instance Exception Oddity: Implicit and Explicit not the same?
Peter Otten
__peter__ at web.de
Tue Dec 9 06:46:52 EST 2003
RT Lange wrote:
> but if o is an instance of an E subclass (hence isinstance(o, E) is still
> true),
> shouldn't the first form raise an exception with type E (not E's subclass)
> and value o?
Again:
"If it is an instance of the class, the *instance* *becomes* the *exception*
*value*"
Or, directly from the source:
/* if the value was not an instance, or is not an instance
whose class is (or is derived from) type, then use the
value as an argument to instantiation of the type
class.
*/
(comment in function PyErr_NormalizeException() in error.c)
As clear as you can get. I cannot comment on the rationale of that design
decision, though. I would replace the
raise E, args # disallow in 3.0?
form completely with
raise E(args)
which would avoid the ambiguity altogether.
Peter
PS: I think you owe me an answer to Aahz' pending question now :-)
More information about the Python-list
mailing list