[Python-Dev] Exceptions *must*? be old-style classes?

"Martin v. Löwis" martin at v.loewis.de
Sun Jan 16 11:05:20 CET 2005


Alex Martelli wrote:
>>> What would happen if Exception were made a new-style class, enforce
>>> inheritance from Exception for all new-style exceptions, and allow all
>>> old-style exceptions as before.
>>
>>
>> string exceptions would break.
> 
> 
> Couldn't we just specialcase strings specifically, to keep 
> grandfathering them in?

Sure. That just wouldn't be the change that Simon described, anymore.

You don't specify in which way you would like to specialcase strings.
Two alternatives are possible:
1. Throwing strings is still allowed, and to catch them, you need
    the identical string (i.e. the current behaviour)
2. Throwing strings is allowed, and they can be caught by either
    the identical string, or by catching str
In the context of Simon's proposal, the first alternative would
be more meaningful, I guess.

> The "and so on" would presumably refer to whether special methods should 
> be looked up on the instance or the type.  

Perhaps. That type(exc) changes might also cause problems.

> It seems to me that if the new-style Exception is made very normally and 
> strings are grandfathered in, we ARE down to exoteric breakage cases 
> (potentially fixable by those new magic descriptors as above for 
> specialmethods).

This would be worth a try. Does anybody have a patch to implement it?

Regards,
Martin


More information about the Python-Dev mailing list