[Python-Dev] Dict suppressing exceptions

"Martin v. Löwis" martin at v.loewis.de
Fri Aug 11 23:54:19 CEST 2006


Michael Chermside schrieb:
> 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.

And it's actually fine for three-way compare: different enums don't
naturally arrange.

> 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.

That policy is currently difficult to implement, but reasonable
(difficult because it is quite some code to write).

>    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).

Right; same for three-way compare.

> What do others think? Is this the "right" approach?

For the moment, the first section gets augmented by "issue a
warning if you think the user is comparing things incorrectly".

Regards,
Martin


More information about the Python-Dev mailing list