Adjusting the names of custom exceptions (since raising strings is deprecated)

Silfheed silfheed at gmail.com
Tue Aug 21 06:54:45 CEST 2007


Heyas

So this probably highlights my lack of understanding of how naming
works in python, but I'm currently using FailUnlessRaises in a unit
test and raising exceptions with a string exception.  It's working
pretty well, except that I get the deprecation warning that raising a
string exception is going to go away.  So my question is, how do I
mangle the name of my exception class enough that it doesnt stick the
name of the module before the name of the exception?

Namely I'd like to get the following

***
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
MyError: 'oops!'

instead of

***
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
__main__.MyError: 'oops!'

(or even test_thingie.MyError as is usually the case).


Creating a class in a separate file and then doing

***
from module import MyError
raise MyError


still gives

***
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
module.MyError


Anyway, any help appreciated.




More information about the Python-list mailing list