datetime as subclass of date

Ben Finney ben+python at benfinney.id.au
Fri Jan 24 01:54:26 EST 2014


Roy Smith <roy at panix.com> writes:

> Ben Finney <ben+python at benfinney.id.au> wrote:
>
> > Makes sense, since ‘datetime’ can do everything ‘date’ can do, and
> > is conceptually a subset of the same concept.
>
> That's reasonable, but given that, it's weird that date(2014, 1, 23) == 
> datetime(2014, 1, 23) is False.  You would think it should be True, in 
> the same way that 1 + 0j == 1 is True.

Hmm. It does make sense to me that ‘datetime.date(2014, 1, 23) ==
datetime.datetime(2014, 1, 23)’.

I can come up with rationalisations for why it isn't, but they're not
satisfactory. I also don't consider it a bug, though. I'm conflicted :-)

-- 
 \          “Those who write software only for pay should go hurt some |
  `\                 other field.” —Erik Naggum, in _gnu.misc.discuss_ |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list