A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-March/021816.html below:

R: [Python-Dev] Deprecating string exceptions

R: [Python-Dev] Deprecating string exceptionsMartin v. Loewis martin@v.loewis.de
28 Mar 2002 00:18:29 +0100
"Samuele Pedroni" <pedroni@inf.ethz.ch> writes:

> But this is legal in 2.2
> 
> >>> class Z(str,Exception):
> ...  pass
> ...
> >>> Z.__bases__
> (<type 'str'>, <class exceptions.Exception at 0x00757700>)
> >>> Z.__base__
> <type 'str'>
> 
> so the issue is more subtle or I'm missing something?

The issue is more subtle: raising an instance of Z counts as raising a
string, so you cannot catch with with "except Z", but you can catch
it with the identical object.

However, this is not the issue reported in bug #518846: Magnus Heino
does not want to inherit from str, and his class does not inherit from
Exception, either.

Also, I believe that using your class Z as an exception class should
not be supported: a "proper" exception should not just merely inherit
from Exception - it should have Exception as its only root class (Z
has both object and Exception as root classes).

So yes, funny things can happen, but they are all accidental, and may
stop happening without notice.

Regards,
Martin



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4