Python syntax errors: pyflakes detects only the first error of many

2.7k Views Asked by At

Let's say I have the following code:

def incr(d, a)
    r = {}
    for key, value in d.items():
        if key != a:
            value += 1
        r[key] = value
    return r
def decr(d, a)
    r = {}
    for key, value in d.items():
        if key == a:
            value -= 1
        r[key] = value
    retur r

As it may be seen, it misses : in both of the definitions and also contains retur instead of return on the last line. However, if I run it through the pyflakes (something like pyflakes test.py) it only reports the first one of all the errors:

$ pyflakes test.py
test.py:9:15: invalid syntax
def incr(d, a)
              ^

As soon as I fix the first one, it moves to the next one on the second run:

$ pyflakes test.py
test.py:18:15: invalid syntax
def decr(d, a)
              ^

So, my question would be am I missing something, or is it possible to show all the possible errors at once?

(As a matter of fact, I'm trying to make use of syntastic plugin for vim -- but because of the behaviour described above, syntastic itself displays only the first error in vim's location list...)

Thanks.

1

There are 1 best solutions below

2
On

Pyflakes is not intended to check for syntax errors. It is a tool used to check for mistakes that violate coding standards, which could go undetected because the code would still run. For example, unused imports or variables.

The syntax errors are thrown by the python interpreter, not the pyflakes library.