[ python-Bugs-1028306 ] date-datetime comparison
SourceForge.net
noreply at sourceforge.net
Thu Sep 16 01:57:40 CEST 2004
Bugs item #1028306, was opened at 2004-09-14 21:00
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1028306&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Donnal Walter (donnal)
>Assigned to: Tim Peters (tim_one)
Summary: date-datetime comparison
Initial Comment:
> I was surprised to discover that
>
> >>> import datetime
> >>> x = datetime.date(2004, 9, 14)
> >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15)
> >>> print x == y
> True
>
> How can these two objects be considered equal?
They should not be. Please open a bug report. The
problem is due to that datetime.datetime is a subclass
of datetime.date:
>>> isinstance(y, datetime.date) True
>>>
and date's comparison implementation believes that
instances of date subclasses can be compared as if
they *were* dates. Indeed, since a datetime.datetime
is-a datetime.date, it's a bit hard to see why that
shouldn't be allowed, and offhand I don't know of a
principled way to fix this without breaking existing code
that compares instances of user-defined subclasses of
datetime.date to instances of datetime.date.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1028306&group_id=5470
More information about the Python-bugs-list
mailing list