From 031f24b7a8257dcf62e8742f83d1bc82e496327d Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Wed, 6 Jun 2018 16:57:18 +0200 Subject: [PATCH 1/2] Fix test suites * Disable some more flake8 warnings that pop up on my machine * Newer flake8 columns seems to be indexed one off from the previous tests --- .flake8 | 2 +- flake8_mypy.py | 2 +- setup.cfg | 2 +- tests/test_mypy.py | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.flake8 b/.flake8 index 17459d3..59cb0cb 100644 --- a/.flake8 +++ b/.flake8 @@ -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 diff --git a/flake8_mypy.py b/flake8_mypy.py index 5560f2b..a24bddd 100644 --- a/flake8_mypy.py +++ b/flake8_mypy.py @@ -163,7 +163,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)) diff --git a/setup.cfg b/setup.cfg index 89353b4..da6f2fc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/test_mypy.py b/tests/test_mypy.py index 4dc3f7b..9838614 100644 --- a/tests/test_mypy.py +++ b/tests/test_mypy.py @@ -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")', ), @@ -94,7 +94,7 @@ def test_clash(self) -> None: self.errors( T484( 6, - 4, + 5, vars=( 'Incompatible return value type ' '(got "UserDict[, ]", ' From db40dbf4d36288c8dafa2b77d524891b292a33ab Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Wed, 6 Jun 2018 17:02:46 +0200 Subject: [PATCH 2/2] Do not put files in isolated temp dirs This reenables handling relative imports correctly and doesn't seem to be necessary anymore on more recent mypy versions. This will fix #6 --- flake8_mypy.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/flake8_mypy.py b/flake8_mypy.py index a24bddd..0802b53 100644 --- a/flake8_mypy.py +++ b/flake8_mypy.py @@ -7,7 +7,6 @@ import os from pathlib import Path import re -from tempfile import NamedTemporaryFile, TemporaryDirectory import time import traceback from typing import ( @@ -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)