This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/mypy-lint (pull request #56)
Add mypy linter
- Loading branch information
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ docs/_build/ | |
|
||
# Vagrant | ||
.vagrant/ | ||
|
||
.mypy_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
|
||
from badwolf.utils import run_command | ||
from badwolf.lint import Problem | ||
from badwolf.lint.linters import PythonLinter | ||
from badwolf.lint.utils import in_path | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MypyLinter(PythonLinter): | ||
name = 'mypy' | ||
default_pattern = '*.py *.pyi' | ||
|
||
def is_usable(self): | ||
if not in_path('mypy'): | ||
return False | ||
|
||
# mypy only avaiable in Python 3 | ||
python_version = self.python_name[6:] | ||
major, *_ = python_version.split('.', 1) | ||
if int(major) < 3: | ||
return False | ||
return True | ||
|
||
def lint_files(self, files): | ||
command = [ | ||
self.python_name, | ||
'-m', | ||
'mypy', | ||
] | ||
command += files | ||
_, output = run_command(command, split=True, include_errors=True, cwd=self.working_dir) | ||
if not output: | ||
raise StopIteration() | ||
|
||
for line in output: | ||
filename, line, level, message = self._parse_line(line) | ||
is_error = level == 'error' | ||
yield Problem(filename, line, message, self.name, is_error=is_error) | ||
|
||
def _parse_line(self, line): | ||
"""mypy only generates results as stdout. | ||
Parse the output for real data.""" | ||
parts = line.split(':', 3) | ||
return parts[0], int(parts[1]), parts[2].strip(), parts[3].strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ marshmallow-oneofschema | |
twine | ||
flake8-bugbear | ||
is-minified-js | ||
mypy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def p() -> None: | ||
print('hello') | ||
|
||
|
||
a = p() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters