[Python-ideas] Please reconsider the Boolean evaluation of midnight

M.-A. Lemburg mal at egenix.com
Thu Mar 6 12:04:56 CET 2014


On 06.03.2014 11:46, Antoine Pitrou wrote:
> Le 06/03/2014 11:33, M.-A. Lemburg a écrit :
>>
>> I find it strange that the only argument against having time(0,0,0)
>> evaluate to False in a boolean context is a wrongly used
>> None test.
> 
> It's only "wrongly used" because of that particular wart.
> In other words, the "wrongly used" None test *exposes* the wart, it is not its *cause*.

Wait. Let's be clear on this:

Writing

    if x: print ('x is None')

or

    if x == None: print ('x is None')

is wrong code.

None is a singleton, so you have to use the "is" operator, i.e.

    if x is None: print ('x is None')

is the only correct way of testing for None.

Adding a test to pylint for this would probably be more helpful
and address the real problem in a more productive way, than the
current discussion to making the above problematic code work in
the single use case of x being a datetime.time object.

> There are other contexts with implicit boolean conversion, such as any() and all().

If you expect those to work correctly for None testing, then
you're writing wrong code as well.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 06 2014)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2014-04-09: PyCon 2014, Montreal, Canada ...               34 days to go

::::: Try our 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