Skip to content

Commit

Permalink
Enable flake8-pyi plugin to automatically include *.pyi files
Browse files Browse the repository at this point in the history
This simplifies running flake8 tests and reduces the amount of F821 errors
reported (flake8-pyi enables support for forward references in *.pyi files).
The error code is left disabled until I clean up the remaining issues.
  • Loading branch information
Lukasz Langa committed Dec 21, 2016
1 parent 52d9f81 commit 8c5c788
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 55 deletions.
6 changes: 5 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

[flake8]
ignore = F401, F811, F821, E127, E128, E301, E302, E305, E501, E701, E704, E999, B303
# We are checking with Python 3 but many of the stubs are Python 2 stubs.
# A nice future improvement would be to provide separate .flake8
# configurations for Python 2 and Python 3 files.
builtins = StandardError,apply,basestring,buffer,cmp,coerce,execfile,file,intern,long,raw_input,reduce,reload,unichr,unicode,xrange

# Errors that we need to fix before enabling flake8 by default:
# 936 F821 undefined name - FIXME: re-enable and add missing imports
# 208 F821 undefined name - FIXME: re-enable and add missing imports
# 6 E999 invalid syntax - FIXME: re-enable after flake8 is running from Python 3.6
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ language: python
matrix:
include:
- python: "3.5"
env: TEST_CMD="./tests/flake8_test.py"
env: TEST_CMD="flake8"
- python: "3.5"
env: TEST_CMD="./tests/mypy_test.py"
- python: "2.7"
env: TEST_CMD="./tests/pytype_test.py --num-parallel=4"

install:
# pytype needs py-2.7, mypy needs py-3.2+. Additional logic in runtests.py
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/dropbox/typed_ast flake8-bugbear; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/dropbox/typed_ast flake8==3.2.1 flake8-bugbear flake8-pyi; fi
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -U git+git://github.com/google/pytype; fi

script:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mypy tests and flake8 tests by invoking:
```
(.venv3)$ python tests/mypy_test.py
...
(.venv3)$ python tests/flake8_test.py
(.venv3)$ flake8
...
```
To run the pytype tests, you need a separate virtual environment with
Expand Down Expand Up @@ -146,7 +146,7 @@ running mypy --python-version 3.2 --strict-optional # with 453 files
running mypy --python-version 2.7 --strict-optional # with 502 files
Running pytype tests...
Ran pytype with 244 pyis, got 0 errors.
Running flake8 on 886 .pyi files...
Running flake8...
flake8 run clean.
(.venv3)$
```
Expand Down
3 changes: 2 additions & 1 deletion requirements-tests-py3.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mypy-lang>=0.4.6
typed-ast>=0.6.1
flake8>=3.2.1
flake8==3.2.1
flake8-bugbear>=16.12.2
flake8-pyi>=16.12.0
3 changes: 2 additions & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

./tests/mypy_test.py
./tests/pytype_test.py
./tests/flake8_test.py
echo "Running flake8..."
flake8 && echo "flake8 run clean."
47 changes: 0 additions & 47 deletions tests/flake8_test.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def main():
flags.append('--strict-optional')
if (major, minor) >= (3, 6):
flags.append('--fast-parser')
##flags.append('--warn-unused-ignores') # Fast parser and regular parser disagree.
# flags.append('--warn-unused-ignores') # Fast parser and regular parser disagree.
sys.argv = ['mypy'] + flags + files
if args.verbose:
print("running", ' '.join(sys.argv))
Expand Down

0 comments on commit 8c5c788

Please sign in to comment.