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 should not be a subclass of date
Type: Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, r.david.murray, sergem, tim.peters
Priority: normal Keywords:

Created on 2016-12-05 12:52 by sergem, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg282416 - (view) Author: sergem (sergem) Date: 2016-12-05 12:52
I have Python 3.5.2.

datetime is implemented as a subclass of date
(isinstance(datetime.datetime(2015,1,1), datetime.date) == True)

I suppose that violates Liskov substitution principle:

1. datetime and date cannot be compared via "<".
2. both of these classes have "isoformat()" method. And the meaning of these methods differ.

It means one cannot pass datetime to the function that expects date.

Also one cannot say that datetime "is a" date. 

I suppose datetime must not be a subclass of date.
msg282417 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-12-05 13:00
Right or wrong, this was a concious design choice.  If you wish to argue that it should be changed, you need to address it on the python-ideas mailing list (but look for previous threads about it there and on python-dev first).
msg282419 - (view) Author: sergem (sergem) Date: 2016-12-05 13:18
Would you be so kind to point to me to the discussion/arguments for that choice? 

Also 
http://www.gossamer-threads.com/lists/python/python/1114426
msg282421 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-12-05 14:18
Hmm.  I thought there was a PEP, but maybe datetime was from before PEPs because I did find a PEP when I searched.  I don't have specific pointers to discussion, that's why I suggested you search first.  I'm pretty sure I remember a discussion of this some time in the past five years, but I have no idea which list it took place on.  If you don't find any relevant thread, start one.  I'm going to nosy Tim Peters and Andrew Belopolsky; they may be able to save you some time by speaking directly to the issue.

However, changing this is probably ruled out by backward compatibility concerns, regardless of anyone's (modern) opinion on the design.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73064
2016-12-06 03:17:42berker.peksagsetresolution: not a bug
2016-12-05 14:18:28r.david.murraysetnosy: + tim.peters, belopolsky
messages: + msg282421
2016-12-05 13:18:12sergemsetresolution: not a bug -> (no value)
messages: + msg282419
2016-12-05 13:00:48r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg282417

resolution: not a bug
stage: resolved
2016-12-05 12:52:20sergemcreate