Issue2789
Created on 2008-05-08 04:17 by shura_zam, last changed 2008-05-10 03:03 by tjreedy.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
datetimemodule.diff
|
shura_zam,
2008-05-08 04:17
|
Patch for correct from rev62827 |
|
|
| msg66402 (view) |
Author: Alexandr Zamaraev (shura_zam) |
Date: 2008-05-08 04:17 |
|
When comparing any standard objects with None returned True or False.
When comparing the object of the module datetime with None raised
exception TypeError.
Example Python session:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime as dt
>>> import decimal as dc
>>> None == 1
False
>>> None == "s"
False
>>> None == [1, 2, 3]
False
>>> None == (1, 2, 3)
False
>>> None == dc.Decimal()
False
>>> None == dt.date.today()
False
>>> None == dt.datetime.today()
False
>>> None == dt.time()
False
>>> None == dt.timedelta()
False
>>> None < 1
True
>>> None < "s"
True
>>> None < [1, 2, 3]
True
>>> None < (1, 2, 3)
True
>>> None < dc.Decimal()
True
>>> None < dt.date.today()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.date to NoneType
>>> None < dt.datetime.today()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.datetime to NoneType
>>> None < dt.time()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.time to NoneType
>>> None < dt.timedelta()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't compare datetime.timedelta to NoneType
|
| msg66508 (view) |
Author: Terry J. Reedy (tjreedy) |
Date: 2008-05-10 03:03 |
|
You actually have it backwards ;-) The arbitrary responses to
nonsensical cross-class order comparisons found in 1.x and 2.x are now
considered a design bug. They are disappearing in 3.0.
Datetime is a fairly recent module (new in 2.3) written to the new
standard. The number 1, for instance, in the same comparisons, raises
the same exceptions. And the manual specifies this. For instance, the
time class section on comparison explicitly says: "In order to stop
mixed-type comparisons from falling back to the default comparison by
object address, when a time object is compared to an object of a
different type, TypeError is raised unless the comparison is == or !=."
Closing as invalid.
As indicated in the quote, equality comparisons are different from order
comparisons. None really is not equal to anything else. This is still
true in 3.0.
|
|
| Date |
User |
Action |
Args |
| 2008-05-10 03:03:24 | tjreedy | set | status: open -> closed resolution: invalid messages:
+ msg66508 nosy:
+ tjreedy |
| 2008-05-09 09:08:12 | schmir | set | nosy:
+ schmir |
| 2008-05-08 04:17:16 | shura_zam | create | |
|