[Python-3000] None in Comparisons
Daniel Stutzbach
daniel.stutzbach at gmail.com
Tue Nov 11 15:22:29 CET 2008
On Tue, Nov 11, 2008 at 7:06 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> Why was the special case for None being "smaller" than all other
> objects in Python removed from Python 3.0 ? (see object.c in Py2.x)
>
It wasn't true in Python 2.5, either. Observe:
Cashew:~/pokersleuth/tracker$ python2.5
Python 2.5 (r25:51908, Feb 26 2007, 08:19:26)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> now = datetime.datetime.now()
>>> now < None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.datetime to NoneType
Right now to get the desired semantics, I implement a custom AlwaysLeast
and/or AlwaysGreatest singletons for whatever type I'm dealing with. It's a
bit of of a pain. My use cases are all along the following lines:
class TimeSpan:
def __init__(self):
self.earliest = AlwaysGreatest
self.latest = AlwaysLeast
def update(self, v):
self.earliest = min(self.earliest, v)
self.latest = max(self.latest, v)
--
Daniel Stutzbach, Ph.D.
http://www.barsoom.org/~agthorr <http://www.barsoom.org/%7Eagthorr>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20081111/44e2f29e/attachment.htm>
More information about the Python-3000
mailing list