Prepare to type-check using mypy

This commit is contained in:
Takeshi KOMIYA 2016-11-07 13:15:18 +09:00
parent de3e8580c4
commit db732ac0b8
7 changed files with 21 additions and 2 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
*.swp
.dir-locals.el
.mypy_cache/
.ropeproject/
TAGS
.tags

View File

@ -1,6 +1,6 @@
PYTHON ?= python
.PHONY: all style-check clean clean-pyc clean-patchfiles clean-backupfiles \
.PHONY: all style-check type-check clean clean-pyc clean-patchfiles clean-backupfiles \
clean-generated pylint reindent test covertest build
DONT_CHECK = -i build -i dist -i sphinx/style/jquery.js \
@ -30,11 +30,14 @@ DONT_CHECK = -i build -i dist -i sphinx/style/jquery.js \
-i sphinx/search/tr.py \
-i .tox
all: clean-pyc clean-backupfiles style-check test
all: clean-pyc clean-backupfiles style-check type-check test
style-check:
@$(PYTHON) utils/check_sources.py $(DONT_CHECK) .
type-check:
mypy sphinx/
clean: clean-pyc clean-pycache clean-patchfiles clean-backupfiles clean-generated clean-testfiles clean-buildfiles
clean-pyc:

6
mypy.ini Normal file
View File

@ -0,0 +1,6 @@
[mypy]
python_version = 2.7
silent_imports = True
fast_parser = True
incremental = True
check_untyped_defs = True

View File

@ -51,6 +51,7 @@ requires = [
'alabaster>=0.7,<0.8',
'imagesize',
'requests',
'typing',
]
extras_require = {
# Environment Marker works for wheel 0.24 or later

View File

@ -16,3 +16,4 @@ imagesize
requests
html5lib
enum34
typing

View File

@ -47,6 +47,10 @@ deps=
{[testenv]deps}
[testenv:py35]
deps=
mypy-lang
typed_ast
{[testenv]deps}
commands=
{envpython} tests/run.py -m '^[tT]est' {posargs}
sphinx-build -q -W -b html -d {envtmpdir}/doctrees doc {envtmpdir}/html

View File

@ -46,6 +46,7 @@ copyright_2_re = re.compile(r'^ %s(, %s)*[,.]$' %
(name_mail_re, name_mail_re))
not_ix_re = re.compile(r'\bnot\s+\S+?\s+i[sn]\s\S+')
is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b')
noqa_re = re.compile(r'#\s+NOQA\s*$', re.I)
misspellings = ["developement", "adress", # ALLOW-MISSPELLING
"verificate", "informations"] # ALLOW-MISSPELLING
@ -81,6 +82,8 @@ def check_syntax(fn, lines):
@checker('.py')
def check_style(fn, lines):
for lno, line in enumerate(lines):
if noqa_re.search(line):
continue
if len(line.rstrip('\n')) > 95:
yield lno+1, "line too long"
if line.strip().startswith('#'):