[Python-Dev] Re: Rich comparisons (original) (raw)
Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Mar 30 16:41:58 EST 2004
- Previous message: [Python-Dev] Rich comparisons shortcut
- Next message: [Python-Dev] PEP 318: Decorators last before colon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: Edward Loper
Tim Delaney's suggestion [1] seemed pretty reasonable. In particular: - Ensure that NaN is a singleton (like True and False). I.e., the float constructor checks if the float is NaN, and if so returns a singleton.
Did I say that? I know I thought about the possibility of NaN being a singleton subclass of float, but I don't remember posting it ...
It would be nice, but I don't think it's overly feasible.
Advantages: - We have an easy way to test if a variable is nan: "x is NaN" - nan will work "properly" as a dictionary key
This second statement is not correct. Since NaN would always compare non-equal with itself, it most definitely would not work as a dictionary key. My thoughts were that by having NaN as a separate class, it could raise if hash were called i.e. explicitly preventing it from being used as a dictionary key.
The important question is whether this would slow down other operations. As for cmp(), my understanding was that it should just return -1 if two unordered objects are not equal.
Nah - negative for <, 0 for ==, positive for >. And an exception if it's non-comparable (it used to be that cmp wasn't allowed to raise an exception, but this restriction was relaxed).
Tim Delaney
- Previous message: [Python-Dev] Rich comparisons shortcut
- Next message: [Python-Dev] PEP 318: Decorators last before colon
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]