This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: datetime comparison with 'None' returning a TypeError
Type: behavior Stage: resolved
Components: Tests Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, pythoner
Priority: normal Keywords:

Created on 2014-10-05 08:38 by pythoner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sorting_func.py pythoner, 2014-10-05 08:38 Date Sorting
Messages (2)
msg228543 - (view) Author: Ankit Dhebar (pythoner) Date: 2014-10-05 08:38
code snippet
student_tuple = [ ('ykjsdf', 'A', 17, datetime.date(2014,10,15)), ('accjr', 'C', 11, datetime.date(2013,05,05)), ('dgekw', 'B', 5, datetime.date(1987,03,03)) ]

Output for the above code works as expected.
o/p : [('dgekw', 'B', 5, datetime.date(1987, 3, 3)), ('accjr', 'C', 11, datetime.date(2013, 5, 5)), ('ykjsdf', 'A', 17, datetime.date(2014, 10, 15))]

but when you make one of the above datetime.date as 'None' like below

student_tuple = [ ('ykjsdf', 'A', 17, datetime.date(2014,10,15)), ('accjr', 'C', 11, None), ('dgekw', 'B', 5, datetime.date(1987,03,03)) ]
 
o/p : TypeError: can't compare datetime.date to NoneType

In my opinion, the 'NoneType' should appear either in the beginning or towards the end after sorting is done.
msg228566 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2014-10-05 13:52
You've identified the main problem: would None go first or last? Modify your key function to make the decision appropriate for you, returning either a very small or very large value for None, as appropriate.

If you really want to see this behavior changed, you should have a concrete proposal and bring it up on the python-ideas mailing list.
History
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66746
2014-10-05 13:52:42eric.smithsetstatus: open -> closed

type: compile error -> behavior

nosy: + eric.smith
messages: + msg228566
resolution: not a bug
stage: resolved
2014-10-05 08:38:46pythonercreate