Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use flake8 for Python 3 ?

In this code snippet,

def add(x:int, y:int) -> int:     return x + y 

there are function annotations that are only supported after python 3.0

When I execute flake8 for this python code:

$ flake8 7.3.py -vv checking 7.3.py def add(x: int, y: int) -> int: return x + y 7.3.py:1:11: E901 SyntaxError: invalid syntax 

I got the invalid syntax error, but it should be valid syntax. How can I use flake8 to check the syntax that is only supported in Python 3.x?

like image 685
Cody Avatar asked May 12 '14 03:05

Cody


1 Answers

See: https://bugs.launchpad.net/pyflakes/+bug/989203

NB: Whilst this bug report indicates some level of resolution, testing the latest version of pyflakes 0.8.1 this lack of Python 3 Annotations still exists.

I guess you'd have to file a separate new feature request to pyflakes.

pyflakes Bugs

$ cat - > foo.py def add(x:int, y:int) -> int:     return x + y ^D $ pyflakes --version 0.8.1  $ pyflakes foo.py foo.py:1:10: invalid syntax def add(x:int, y:int) -> int:          ^ 

UPDATE (20140514):

As it turns out the actual answer to this problem is to run pyflakes or flake8 under Python 3.x instead of Python 2.x. It makes sense :)

So do something like this:

/usr/bin/python3 -m pyflakes foo.py 

See: http://codepad.org/9BKxSZaD

like image 134
James Mills Avatar answered Sep 19 '22 13:09

James Mills