[Python-ideas] bool(datetime.time(0, 0))

M.-A. Lemburg mal at egenix.com
Mon May 7 18:53:28 CEST 2012


Alexander Belopolsky wrote:
> On Mon, May 7, 2012 at 11:32 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Well, less occasional puzzlement is an improvement in itself.
>> Unintuitive behaviour is always a risk for software quality.
> 
> I don't find the current behavior unintuitive.  It is common to
> represent time of day as an integer (number of minutes or seconds
> since midnight) or as a float (fraction of the 24-hour day).  In these
> cases one gets bool(midnight) -> False as an artifact of the
> representation.

In Python 2.x, the slot used by bool() is called nb_nonzero, which
returns 1/0 depending on whether a value is considered zero or not.

This makes it quite natural for any special object representing a
value akin to zero in its domain to be false.

In Python 3.x, nb_nonzero was renamed to nb_bool without really
paying attention to the fact that many types implemented the original
meaning instead of a notion of boolean value, so I guess we'll just
have to live with it, unless we want to introduce yet another
subtle difference between Python 2.x and 3.x.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 07 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2012-07-02: EuroPython 2012, Florence, Italy               56 days to go
2012-04-26: Released mxODBC 3.1.2                 http://egenix.com/go28
2012-04-25: Released eGenix mx Base 3.2.4         http://egenix.com/go27

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/



More information about the Python-ideas mailing list