Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Support relative imports #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Keep in sync with setup.cfg which is used for source packages.

[flake8]
ignore = E302, E501
ignore = E302, E501, W504
max-line-length = 80
max-complexity = 12
select = B,C,E,F,T4,W,B9
16 changes: 2 additions & 14 deletions flake8_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
from pathlib import Path
import re
from tempfile import NamedTemporaryFile, TemporaryDirectory
import time
import traceback
from typing import (
Expand Down Expand Up @@ -163,7 +162,7 @@ class MypyChecker:

tree = attr.ib(default=None)
filename = attr.ib(default='(none)')
lines = attr.ib(default=[])
lines = attr.ib(default=[]) # type: List[str]
options = attr.ib(default=None)
visitor = attr.ib(default=attr.Factory(lambda: TypingVisitor))

Expand All @@ -180,18 +179,7 @@ def run(self) -> Iterator[_Flake8Error]:
if not self.options.mypy_config and 'MYPYPATH' not in os.environ:
os.environ['MYPYPATH'] = ':'.join(calculate_mypypath())

# Always put the file in a separate temporary directory to avoid
# unexpected clashes with other .py and .pyi files in the same original
# directory.
with TemporaryDirectory(prefix='flake8mypy_') as d:
with NamedTemporaryFile(
'w', encoding='utf8', prefix='tmpmypy_', suffix='.py', dir=d
) as f:
self.filename = f.name
for line in self.lines:
f.write(line)
f.flush()
yield from self._run()
yield from self._run()

def _run(self) -> Iterator[_Flake8Error]:
mypy_cmdline = self.build_mypy_cmdline(self.filename, self.options.mypy_config)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python-tag = py35.py36
[flake8]
# Keep in sync with .flake8. This copy here is needed for source packages
# to be able to pass tests without failing selfclean check.
ignore = E302, E501
ignore = E302, E501, W504
max-line-length = 80
max-complexity = 12
select = B,C,E,F,T4,W,B9
8 changes: 4 additions & 4 deletions tests/test_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ def test_invalid_types(self) -> None:
self.assertEqual(
errors,
self.errors(
T484(5, 0, vars=('Missing return statement',)),
T484(5, 1, vars=('Missing return statement',)),
T484(
10,
4,
5,
vars=(
'Incompatible return value type (got "int", expected "str")',
),
),
T484(
10,
11,
12,
vars=(
'Unsupported operand types for + ("int" and "str")',
),
Expand All @@ -94,7 +94,7 @@ def test_clash(self) -> None:
self.errors(
T484(
6,
4,
5,
vars=(
'Incompatible return value type '
'(got "UserDict[<nothing>, <nothing>]", '
Expand Down