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

Chris Barker chris.barker at noaa.gov
Fri Feb 14 18:14:53 CET 2014

On Fri, Feb 14, 2014 at 1:29 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

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

This is actually a pretty common case -- the question here is: Is this
really None? or does None have a special meaning. It sounds like this is a
wrapper for a PostgreSQL range object, in which case None isn't really
right, there must be a +-infinity concept there -- how does postgress
handle it? (is this a generic range, or a datetime range? I'm not up on it).
If this means what I think it does, None is really a hack, both because of
al lteh specia case code required for sorting, comparing, etc, but also
because it's missing information -- the two ends of the range should really
have different meanings.

I've dealt with this for Python datetime via a pari fo custom InfDateTime
objects one for plu infiinity, one for minus. Then we can use these in
ranges and the reest of teh code can jsut do simple comparisons, sorting

Of course, floating point numbers have inf and -inf, which is really useful.

I hadn't though of Nick's generic AlwaysLess or AlwaysGreater type -- if
that means what I think it does -- i,e, it would compare appropriately to
ANY other object, that would actually be a nice addition to
the standard library. I had been thinking that the standard
library datetime could use these, but why not just use generic ones?

(though it could get a bit tricky -- what would AlwaysGreater >
float('inf") evaluate to?



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140214/9bbb39cf/attachment.html>

More information about the Python-Dev mailing list