Comparisons and sorting of a numeric class....

Ian Kelly ian.g.kelly at gmail.com
Fri Jan 23 13:13:26 EST 2015


On Fri, Jan 23, 2015 at 10:45 AM, Rustom Mody <rustompmody at gmail.com> wrote:
> No disagreement with the 'hack'
> As for "no use case for equal but distinct tokens" - thats a strange
> view given this thread

If you want equal but distinct, you can give them distinct values and
define an __eq__ method that compares them as equal. Because of this
though I do take some issue with the Planet example in the docs:

https://docs.python.org/3/library/enum.html#planet

If any planets happened to have the same mass and radius (which I
realize would be unlikely in this case), the example would fail. Using
the value of the enum for both identity and data conflates the two
concepts and leads to pitfalls.



More information about the Python-list mailing list