Is nan in (nan,) correct?

Chris Angelico rosuav at gmail.com
Thu Mar 5 18:25:05 EST 2015


On Fri, Mar 6, 2015 at 10:11 AM,  <sohcahtoa82 at gmail.com> wrote:
> I would argue that if `a is b` then it is obvious that `a == b`

This is not true for float("nan"), though. The question is, is your
above statement a valid optimization for the 'in' operator, or not?
And no, it isn't, because it's not perfectly safe. However, there are
other invariants that mean that 'in' has to allow object identity to
count; for instance:

for elem in collection:
    assert elem in collection

should never assert-fail.

ChrisA



More information about the Python-list mailing list