Pychecker

Matt Good matt.good at gmail.com
Fri Jun 9 20:46:59 CEST 2006


Anthony Greene wrote:
> Howdy, I had the impression that pychecker caught and reported such
> dynamic syntactical errors.
>
> #!/usr/bin/env python
>
>
> def add(i):
>     i += 10
>
> status = 3
>
> if 1 == 1:
>     statuss = 15
>
> add(status)
>
> =======================
>
> exalted sysfault$ pychecker foo.py
> Processing foo...
>
> Warnings...
>
> None
>
> =======================
>
> Hence the mispelling of status (statuss), which was done purposely to test
> if pychecker will acknowledge and report the error. Do i need to enable
> some type of pychecker option in order for it to pick up the error? I know
> that it is syntactically correct in python, however it's likely that
> 'status' is meant. Am i wishing that pychecker will replace a statically
> typed language mechanism?

That's a functional error, not a syntactical one.  Analyzing the
spelling of variables for similarity would lead to a lot of incorrect
warnings since pychecker has no way to tell this apart from intentional
similar spellings such as:

values = [1, 2, 3]
value = values[0]

However, when the misspelling is made inside a local scope, rather than
at the module level a warning is reported "test.py:8: Local variable
(statuss) not used":

def add(i):
    i += 10

def test():
    status = 3
    if 1 == 1:
        statuss = 15
    add(status)


This is why tools like pychecker (or pyflakes, pylint, or even a static
code compiler) aren't a substitute for unit tests.  They can definitely
help catch common mistakes, but they can't ensure your code does what
you intended.

--
Matt Good




More information about the Python-list mailing list