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

M.-A. Lemburg mal at egenix.com
Tue May 8 13:36:52 CEST 2012


Antoine Pitrou wrote:
> On Tue, 08 May 2012 12:34:32 +0200
> "M.-A. Lemburg" <mal at egenix.com> wrote:
>>
>> Fully agreed.
>>
>> The above code is just plain wrong and often causes problems
>> in larger applications - besides, it's also slower in most
>> cases, esp. if determining the length of an object or
>> converting it to a numeric value is slow.
>>
>> If you want to test for None return values, you need to use
>> "if is None" or "if is not None".
> 
> So who writes the PEP to deprecate __bool__ methods wholesale?

I think I lost you there. What does the above have to do with
__bool__ methods ?

Whether or not a type implements the notion of a boolean value
is really up to the specific implementation and not a question
that can be answered in general.

It's perfectly fine for time value to mimic a boolean value
by following the same paradigm as a float "seconds since midnight"
value.

As such, reusing the __nonzero__ or __len__ slots for boolean
values is fine as well. It may not always make sense in every
conceivable way, but as long as there is a valid explanation
that can be documented, I don't see that as problem.

If you're purist, you'd probably disallow __bool__ methods
on non-boolean types, but this is Python, so we pass on
control to object and type implementers.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 08 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               55 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