Meaning of None - was PEP 285: Adding a bool type

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Wed Apr 10 20:51:45 EDT 2002


On 10 Apr 2002 21:51:11 GMT, Bengt Richter <bokr at oz.net> wrote:
>On Wed, 10 Apr 2002 16:04:45 -0400, "Colin J. Williams" <cjw at sympatico.ca> wrote:
>[...html...]
>
>Logical operations 
>0 or  None, 1 or  None: None 1 
>0 and None, 1 and None: 0 None 
>              not None: 1 
>
>With a three value scheme, the results would 
>be the same for the first two, whereas the 
>result of `not None` would itself be None. 

Thanks for translating this beautiful proposal from the ugly HTML.  :-)

I had also proposed this as a way to properly define rich comparisons:

	a   b   a > b   a == b   a < b
	1   0   True    False    False
	0   0   False   True     False
	0   1   False   False    True
	0   1j  None    False    None
	
It is often necessary to compare objects in a set even though there is only
a partial order.  We often do not want exceptions when the order is not
defined, since comparisons are often imbedded in expressions but try/except
has to be statements.

On the other hand, a comparison operator with a total order is useful in
many situations even though this total order is not related to the _natural_
partial order.   For example, cmp(1, None) is well defined.  Why would
cmp(1, 1j) be an exception?   This is especially painful if all you want is
just a _unique_ order, whatever it is.

Anyone paying attention to such matters over time would discover that
allowing three valued logic would solve a supprisingly large number of
trivial but nasty problems.

However, I do not see an easy way to extract None from Python's pool of
objects denoting false.  If only it was not designed that way ...

Hopefully when IEEE floating point support becomes ubiquitous we could
redefine the comparison with NaN for this purpose.  (You might be able to
get at it now as NaN=(1e200j**2).imag, but the comparison is always False.)

Huaiyu



More information about the Python-list mailing list