[Python-Dev] Dict suppressing exceptions
mcherm at mcherm.com
Fri Aug 11 23:02:56 CEST 2006
Martin v. Löwis writes:
> Now I looked at it, and think that the recipe is broken.
Not broken, but perhaps wrongheaded. The recipe went out of its way
to ensure that it would raise an exception of enum values from different
enumerations were compared. There's nothing out there saying that this
is a bad thing to do.
I propose that we institute a new policy. The policy should state:
__eq__ methods should always return True or False. They should
only raise an exception if there is some internal error within
one of the objects being compared -- they should never raise
an exception because the other object is of an unexpected type.
On the other hand, __lt__, __gt__ and friends SHOULD raise an
exception when the object being compared is of some type for
which the ordering does not make sense (e.g.: unicode vs
byte-string or complex vs anything).
I think we should note this policy someplace official -- perhaps
in the Language Reference where __eq__ and __lt__ are defined. But
I do not think that these changes should be made until Py3K.
What do others think? Is this the "right" approach?
-- Michael Chermside
More information about the Python-Dev