Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17160 > unrolled thread

Re: boolean from a function

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-12-13 09:42 -0800
Last post2011-12-13 09:42 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: boolean from a function Ethan Furman <ethan@stoneleaf.us> - 2011-12-13 09:42 -0800

#17160 — Re: boolean from a function

FromEthan Furman <ethan@stoneleaf.us>
Date2011-12-13 09:42 -0800
SubjectRe: boolean from a function
Message-ID<mailman.3611.1323801308.27778.python-list@python.org>
Andrea Crotti wrote:
> I'm not sure for how long I had this bug, and I could not understand the 
> problem.
> 
> I had a function which would return a boolean
> 
> def func_bool():
>     if x:
>         return True
>     else: return False
> 
> Now somewhere else I had
> 
> if func_bool:
>     # do something
> 
> I could not quite understand why it was always true, until I finally 
> noticed that the () were missing.
> Is there some tool to avoid these stupid mistakes? (pylint doesn't warn 
> me on that)
> I don't think I will ever (or almost) have to use a function as a 
> boolean, instead of its return value...

Heh, I do believe I've been bitten by that a couple times.

The only defense I'm aware of is good unit tests.

~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web