[issue20858] Enhancements/fixes to pure-python datetime module

Josh Rosenberg report at bugs.python.org
Fri Mar 7 00:26:26 CET 2014


Josh Rosenberg added the comment:

That's actually an argument to fix the C datetime implementation. Right now, you get:

    >>> from decimal import Decimal as d
    >>> from datetime import datetime
    >>> datetime(d("2000.5"), 1, 2)
    datetime.datetime(2000, 1, 2, 0, 0)

This is wildly inconsistent; if you passed 2000.0, it would raise an exception because float (even floats directly equivalent to an int value) are forbidden. But the logically equivalent Decimal type will work just fine, silently truncating. Basically any user defined type with integer coercion (but not integer equivalence) would have the same problem; str doesn't, because str is special cased (it doesn't actually have __int__), but any user-defined str-like class that defined int coercion would work as a datetime arg in a way str does not.

You've just given me an excuse to open my first bug. Thanks! :-)

----------

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


More information about the Python-bugs-list mailing list