[IronPython] Should DBNull treat as false ?

Dino Viehland dinov at exchange.microsoft.com
Tue May 20 18:27:34 CEST 2008


I generally agree that DBNull should be false - it is logically the same as None.  We can define __nonzero__ on DBNull.Value to make this work.  I've opened bug #16695 to track the issue (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=16695) and it should be an easy fix.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Monday, May 19, 2008 9:36 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Should DBNull treat as false ?

I don't think DBNull.Value should be True, it's purpose is very
similar to None, and it should have the same truth value. Doing
otherwise complicates conditional expressions and leads to
conversations like this on the mailing list... Usually it's best to
choose the path of least surprise.

-Dan

On Thu, May 15, 2008 at 1:41 PM, Davy Mitchell <daftspaniel at gmail.com> wrote:
> Hi there,
>
> I *think* this may be related to the Closed issue
> http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=14605
>
> Dino stated at the time (with the last point being relevant here):
> "....NET conventions say that enum's should generally have a zero value
> (FxCop CA1008 :)).  Because of that we can safely define __nonzero__ on
> enums and have that return true/false based upon if the value is
> zero/non-zero.  Otherwise Python says all expressions otherwise defined
> return true,"
>
> So I think the behaviour is correct though slightly counter intuitive in the
> case of Null.
>
> Cheers,
> Davy
>
> On Thu, May 15, 2008 at 11:51 AM, Sakesun Roykiattisak
> <sakesun at boonthavorn.com> wrote:
>>
>> Some disambitguity is needed here.
>>
>> when  eval("a == True")  is False does not implied "a" is False.
>> "a" is just not equal to True.
>>
>> All .NET types actually consider "nonzero" which in turn will be treat as
>> True in conditional expression.
>>
>>
>>>>> if System.DBNull: print 'I am something'
>>
>> ...
>> I am something
>>>>>
>>
>>
>>>>> if None: print "This won't show anything"
>>
>> ...
>>>>>
>>
>> What I'm asking here is whether should DBNull.Value be considered as False
>> in conditional expression.
>>
>>
>>
>> On Thu, 15 May 2008 15:48:37 +0700, Davy Mitchell <daftspaniel at gmail.com>
>> wrote:
>>
>>> DBNull is a type. Appears all .Net types evaluate to False.
>>> e.g.
>>> from System import DBNull, Char
>>> print Char==True
>>> print DBNull==True
>>>
>>> both will print False.
>>>
>>> On Thu, May 15, 2008 at 9:09 AM, Sakesun Roykiattisak <
>>> sakesun at boonthavorn.com> wrote:
>>>
>>>>
>>>> Should DBNull treat as False ?
>>>>
>>>> Just a thought.
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at lists.ironpython.com
>>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>>>
>>>
>>>
>>>
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> --
> Davy Mitchell
> Blog - http://www.latedecember.co.uk/sites/personal/davy/
> Twitter - http://twitter.com/daftspaniel
> Skype - daftspaniel http://needgod.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list