exception question

Aahz aahz at pythoncraft.com
Mon Sep 1 10:49:06 EDT 2003


In article <lfp4lv8krqakeea3d0k0tcm86mb2mnf2v3 at 4ax.com>,
Gonçalo Rodrigues  <op73418 at mail.telepac.pt> wrote:
>
>For error processing I found convenient maintaining a dictionary where
>the keys are exception *classes* and the values are callables. Of
>course, for this to work, exception classes have to be hashable which
>I happily found that they were. So my question is, can I count on this
>behaviour? Or is this behaviour I should not count on? (I found
>nothing on the docs about it, thus the question).

If it's not documented, you can't count on it.  There's no intrinsic
reason exception classes would be made unhashable, *but* classes become
unhashable as soon as they implement __cmp__() or __eq__() *and* they
fail to implement __hash__().  So if someone ever asks to compare
exceptions, it could be an issue.

You may want to bring this issue up on python-dev.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

This is Python.  We don't care much about theory, except where it intersects 
with useful practice.  --Aahz




More information about the Python-list mailing list