[kforge-dev] Python bug?

John Bywater john.bywater at appropriatesoftwarefoundation.org
Fri Dec 16 12:26:41 UTC 2005

Rufus Pollock wrote:

> John Bywater wrote:
>> So, I tracked down a certain problem to this wierdness:
>> An object (Register) is created. It has attributes, and methods which 
>> work fine. But it is evaluated for 'truth' in an if statement, the 
>> result is False. So code that is sensitive to whether an object has a 
>> register or not, acts as if there isn't a register, when there really 
>> is.
> Nasty bug John and one I can imagine caused quite a bit of pain :(. 
> Does that mean there is a difference for a Python class X between:
> if X != None:
>   ....
> and:
> if X:
>   ....

Yes :-) but it's wrong. None => 'False'. An instantiated object is 'True'.

But I've got an instantiated object that evaluates 'False'. Every other 
object evaluated True.

But I think rather than checking issubclass, I know that the value is 
None if it isn't a register.

So I should write "!= None" rather than the longer 
"issubclass(register.__class__, DomainObjectRegister)".


Perhaps I've disturbed the 
__builtin__.__masquerade_as_false_even_when_true__() method?

But I think I've been Pythoned again!



> Regards,
> Rufus
> _______________________________________________
> kforge-dev mailing list
> kforge-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/kforge-dev

More information about the kforge-dev mailing list