Comparisons and sorting of a numeric class....

Chris Angelico rosuav at gmail.com
Tue Jan 6 14:35:49 CET 2015


On Wed, Jan 7, 2015 at 12:30 AM, Andrew Robinson
<andrew3 at r3dsolutions.com> wrote:
> Why this is so important to Guido, I don't know ... but it's making it VERY
> difficult to add named aliases of False which will still be detected as
> False and type-checkable as a bool.  If my objects don't type check right --
> they will likely break some people's legacy code...  and I really don't even
> care to create a new instance of the bool object in memory which is what
> Guido seems worried about, rather I'm really only after the ability to
> detect the subclass wrapper name as distinct from bool False or bool True
> with the 'is' operator.  If there were a way to get the typecheck to match,
> I wouldn't mind making a totally separate class which returned the False
> instance; eg: something like an example I modified from searching on the
> web:

Okay, so why not just go with your own class, and deal with the
question of the type check? Simple solution: Instead of fiddling with
__gt__/__lt__, create your own method, and use your own comparison
function to sort these things.

ChrisA



More information about the Python-list mailing list