Is there a technic to avoid this bug

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Feb 27 20:59:07 EST 2007


hg <hg at nospam.org> writes:

> I spent a few hours find this bug:
>
> value == self.Get_Value()
> if value == WHATEVER:
>    do this
>
> instead of
> value = self.Get_Value()
> if value == WHATEVER:
>    do this
>
> Is there a way to avoid such a bug with some type of construct ?

Use pylint to check your code for common mistakes.

    <URL:http://www.logilab.org/projects/pylint>

===== bad_assign.py =====
""" Demonstrate a logical error """
value = None

value == 10
if value == 10:
    print "Yep"
else:
    print "Nope"
=====

$ python ./bad_assign.py
Nope

$ pylint ./bad_assign.py
************* Module bad_assign
C:  2: Invalid name "value" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$)
W:  4: Statement seems to have no effect

[...]

-- 
 \        "When I was crossing the border into Canada, they asked if I |
  `\     had any firearms with me. I said, 'Well, what do you need?'"  |
_o__)                                                 -- Steven Wright |
Ben Finney




More information about the Python-list mailing list