[Python-Dev] python 3 niggle: None < 1 raises TypeError

Nick Coghlan ncoghlan at gmail.com
Fri Feb 14 10:29:05 CET 2014


On 14 February 2014 18:04, Chris Withers <chris at simplistix.co.uk> wrote:
>
> Am I missing something? How can I get this method down to a sane size?

The easiest way is usually to normalise the attributes to a sensible
numeric value depending on where you want "None" to sort (positive and
negative infinity floating point values often work well in the case of
numeric data, but a custom AlwaysLess or AlwaysGreater type works for
arbitrary data). You can either do that dynamically, or else cache the
normalised values when the attributes are set.

Python 2 used to guess, Python 3 makes developers decide how they want
None to be handled in the context of ordering operations.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list