Author mark.dickinson
Recipients christian.heimes, mark.dickinson, mikecurtis
Date 2008-11-11.10:52:48
SpamBayes Score 0.0
Marked as misclassified No
Message-id <>
This is indeed interesting.  For what it's worth, I think
the Python 3.0 behaviour is the right one, here.  Perhaps
it's worth adding a test to Python 3.0 to make sure that
this behaviour doesn't accidentally disappear, or at least
to make sure that someone thinks about it before making
the behaviour disappear.

But in general I don't think the fact that NaNs are weird
should get in the way of optimizations.  In other words,
I'm not sure that Python should be asked to guarantee
anything more than "b == b" returning False when b is
a NaN.  It wouldn't seem unreasonable to consider
behaviour of nans in containers (sets, lists, dicts)
as undefined when it comes to equality and identity

There are other questionable things going on when NaNs
are put into containers.  For example:

>>> a = float('nan')
>>> b = [a]
>>> a in b

A strict reading of the definition of 'in' would say
that "a in b" should return False here, since a is not
equal to any element of b.  But I presume that the 'in'
operator does identity checks under the hood before
testing for equality.  'Fixing' this so that nans did
the right thing might slow down a lot of other code
just to handle one peculiar special case correctly.

Michael, is this adversely affecting real-world code?
If not, I'd be inclined to say that it's not worth
changing Python's behaviour here.
Date User Action Args
2008-11-11 10:52:52mark.dickinsonsetrecipients: + mark.dickinson, christian.heimes, mikecurtis
2008-11-11 10:52:51mark.dickinsonsetmessageid: <>
2008-11-11 10:52:50mark.dickinsonlinkissue4296 messages
2008-11-11 10:52:48mark.dickinsoncreate