[New-bugs-announce] [issue5516] equality not reflixive for subclasses of datetime.date and datetime.datetime

Jess Austin report at bugs.python.org
Thu Mar 19 01:51:26 CET 2009


New submission from Jess Austin <jess.austin at gmail.com>:

While the datetime.date and datetime.datetime classes consistently
handle mixed-type comparison, their subclasses do not:

>>> from datetime import date, datetime, time
>>> d = date.today()
>>> dt = datetime.combine(d, time())
>>> d == dt
False
>>> dt == d
False
>>> class D(date):
...     pass
... 
>>> class DT(datetime):
...     pass
... 
>>> d = D.today()
>>> dt = DT.combine(d, time())
>>> d == dt
True
>>> dt == d
False

I think this is due to the premature "optimization" of using memcmp() in
date_richcompare().

----------
components: Library (Lib)
messages: 83798
nosy: jess.austin
severity: normal
status: open
title: equality not reflixive for subclasses of datetime.date and datetime.datetime
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5516>
_______________________________________


More information about the New-bugs-announce mailing list