[Python-Dev] python 3 niggle: None < 1 raises TypeError
Gustavo Carneiro
gjcarneiro at gmail.com
Mon Feb 17 14:29:36 CET 2014
On 17 February 2014 12:30, M.-A. Lemburg <mal at egenix.com> wrote:
> On 17.02.2014 13:19, Serhiy Storchaka wrote:
> > 17.02.14 13:56, M.-A. Lemburg написав(ла):
> >> Yes, but that's not the point. Unlike strings or other mixed types that
> >> you cannot compare, None is used as placeholder in data processing as
> >> special value to mean "no value available".
> >
> > Isn't float('nan') such placeholder?
>
> You can easily construct other such placeholders, but None was intended
> for this purpose:
>
> http://docs.python.org/2.7/c-api/none.html?highlight=none#Py_None
>
> """
> The Python None object, denoting lack of value. ...
> """
>
> >> You intentionally use such values in programming. It's not a bug to
> >> have None in a data list or as value of a variable.
> >
> > You can't have None in array('f'), you can't add or multiply by None.
> Relation operators don't looks
> > an exception here. Applying sorted() to a list which contains numbers
> and Nones makes as much sense
> > as applying sum() to it.
>
> Of course, you cannot apply any operations with None - it doesn't
> have a value -, but you can compare it to other objects and it provides
> a consistent behavior in Python 2. Python 3 is missing such an object.
>
I agree with you that Python 3 could use such an object. Just don't make
it the default. Leave None as it is.
Also I agree that my previous naming suggestions are bad. What we need is
only one (or two) additional object whose main semantic meaning is still
"no value", but which also adds a meaning of "comparable". Then it's a
matter of choosing a good name for it, with lots of bikeshedding involved.
Just lets not change None only because we're too lazy to discuss a proper
alternative name. Also this use case is not _that_ common, so it's ok if
it has a slightly longer name than None.
Also think of the implications of changing None at this point. It would
allow us to write programs that work Python >= 3.5 and Python <= 2.7, but
fail mysteriously in all other versions in between. What a mess that would
be...
--
Gustavo J. A. M. Carneiro
Gambit Research LLC
"The universe is always one step beyond logic." -- Frank Herbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140217/f2f40acc/attachment.html>
More information about the Python-Dev
mailing list