mx.DateTime bug?

M.-A. Lemburg mal at egenix.com
Tue May 11 09:35:28 EDT 2004


Denis S. Otkidach wrote:
> DateTime objects always compare equal to instances of
> user-defined classes:
> 
> Python 2.3.2 (#1, Nov 27 2003, 18:07:14)
> [GCC 3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more
> information.
> 
>>>>from mx import DateTime
>>>>DateTime.__version__
> 
> '2.0.3'
> 
>>>>class c: pass
> 
> ...
> 
>>>>DateTime.now()==c()
> 
> True
> 
> Documentations states that "DateTime and DateTimeDelta instances
> can be compared and hashed, making them compatible to the
> dictionary implementation Python uses (they can be used as
> keys)", but there is at least race condition when instance of
> user defined class has the same hash value.  Moreover, making
> DateTime objects to be always equal to instances with unknown
> nature is a bad idea.

That's a bug that needs fixing. The reason is that mxDateTime
checks the nb_float slot of the object and thinks that it
gets number if the slot is non-NULL. For Python instances,
the slot is non-NULL, but whether they behave like floats
depends on the availability of the __float__ method.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 11 2004)
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
EuroPython 2004, Göteborg, Sweden                           26 days left

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::




More information about the Python-list mailing list