mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Enable flake8-pyi plugin to automatically include *.pyi files
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.
This commit is contained in:
6
.flake8
6
.flake8
@@ -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,7 +4,7 @@ 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"
|
||||
@@ -12,7 +12,7 @@ matrix:
|
||||
|
||||
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:
|
||||
|
||||
@@ -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
|
||||
@@ -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)$
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
./tests/mypy_test.py
|
||||
./tests/pytype_test.py
|
||||
./tests/flake8_test.py
|
||||
echo "Running flake8..."
|
||||
flake8 && echo "flake8 run clean."
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
PY2_ONLY_KEYWORDS = [
|
||||
'StandardError',
|
||||
'apply',
|
||||
'basestring',
|
||||
'buffer',
|
||||
'cmp',
|
||||
'coerce',
|
||||
'execfile',
|
||||
'file',
|
||||
'intern',
|
||||
'long',
|
||||
'raw_input',
|
||||
'reduce',
|
||||
'reload',
|
||||
'unichr',
|
||||
'unicode',
|
||||
'xrange',
|
||||
]
|
||||
|
||||
root = pathlib.Path(__file__).parent.parent
|
||||
paths = list(sorted(str(p) for p in root.glob('**/*.pyi')))
|
||||
window = 0
|
||||
size = 100
|
||||
returncode = 0
|
||||
|
||||
print('Running flake8 on {} .pyi files...'.format(len(paths)))
|
||||
|
||||
while True:
|
||||
chunk = paths[window:window + size]
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
proc = subprocess.run(
|
||||
['flake8', '--builtins=' + ','.join(PY2_ONLY_KEYWORDS)] + chunk,
|
||||
)
|
||||
if proc.returncode:
|
||||
print('flake8 run failed!')
|
||||
sys.exit(1)
|
||||
|
||||
window += size
|
||||
|
||||
print('flake8 run clean.')
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user