Skip to content

Commit 02beb09

Browse files
author
David Fritzsche
committed
Run tests with mypy 0.971
1 parent 8c3f364 commit 02beb09

File tree

8 files changed

+49
-36
lines changed

8 files changed

+49
-36
lines changed

Diff for: constraints.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jinja2==3.1.2
3131
license-expression==30.0.0
3232
markupsafe==2.1.1
3333
mccabe==0.6.1
34-
mypy==0.931
34+
mypy==0.971
3535
mypy-extensions==0.4.3
3636
packaging==21.3
3737
pathspec==0.9.0
@@ -43,7 +43,7 @@ py==1.11.0
4343
pycodestyle==2.8.0
4444
pyflakes==2.4.0
4545
pyparsing==3.0.9
46-
pytest==7.0.1
46+
pytest==7.1.2
4747
pytest-cov==3.0.0
4848
pytest-html==3.1.1
4949
pytest-metadata==2.0.1

Diff for: mypy.ini

-9
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,3 @@ warn_return_any = True
4747
# Strict Optional checks.
4848
# If False, mypy treats None as compatible with every type. (default True)
4949
strict_optional = True
50-
51-
[mypy-py.*]
52-
ignore_missing_imports = True
53-
54-
[mypy-pytest]
55-
ignore_missing_imports = True
56-
57-
[mypy-_pytest.*]
58-
ignore_missing_imports = True

Diff for: requirements.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ flake8-black
88
flake8-isort
99
fsfe-reuse
1010
invoke
11-
mypy==0.931
11+
mypy==0.971
1212
pip-tools
1313
pip>=19.3
1414
pytest-cov
1515
pytest-html
16-
pytest~=7.0.1
16+
pytest~=7.1.2
1717
setuptools>=43
1818
tox-pyenv
1919
tox>=3.14.3

Diff for: requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ markupsafe==2.1.1
7272
# via jinja2
7373
mccabe==0.6.1
7474
# via flake8
75-
mypy==0.931
75+
mypy==0.971
7676
# via -r requirements.in
7777
mypy-extensions==0.4.3
7878
# via
@@ -106,7 +106,7 @@ pyflakes==2.4.0
106106
# via flake8
107107
pyparsing==3.0.9
108108
# via packaging
109-
pytest==7.0.1
109+
pytest==7.1.2
110110
# via
111111
# -r requirements.in
112112
# pytest-cov

Diff for: src/pytest_mypy_testing/message.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import dataclasses
66
import enum
77
import os
8+
import pathlib
89
import re
9-
from typing import Optional, Tuple
10+
from typing import Optional, Tuple, Union
1011

1112

1213
__all__ = [
@@ -166,7 +167,9 @@ def __str__(self) -> str:
166167
return f"{self._prefix} {self.severity.name.lower()}: {self.message}"
167168

168169
@classmethod
169-
def from_comment(cls, filename: str, lineno: int, comment: str) -> "Message":
170+
def from_comment(
171+
cls, filename: Union[pathlib.Path, str], lineno: int, comment: str
172+
) -> "Message":
170173
"""Create message object from Python *comment*.
171174
172175
>>> Message.from_comment("foo.py", 1, "R: foo")
@@ -183,7 +186,7 @@ def from_comment(cls, filename: str, lineno: int, comment: str) -> "Message":
183186
else:
184187
revealed_type = None
185188
return Message(
186-
filename,
189+
str(filename),
187190
lineno=lineno,
188191
colno=colno,
189192
severity=Severity.from_string(m.group("severity")),

Diff for: src/pytest_mypy_testing/parser.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import io
88
import itertools
99
import os
10+
import pathlib
1011
import sys
1112
import tokenize
12-
from typing import Iterable, Iterator, List, Optional, Set, Tuple
13+
from typing import Iterable, Iterator, List, Optional, Set, Tuple, Union
1314

1415
from .message import Message
1516

@@ -71,7 +72,7 @@ class MypyTestFile:
7172

7273

7374
def iter_comments(
74-
filename: str, token_lists: List[List[tokenize.TokenInfo]]
75+
filename: Union[pathlib.Path, str], token_lists: List[List[tokenize.TokenInfo]]
7576
) -> Iterator[tokenize.TokenInfo]:
7677
for toks in token_lists:
7778
for tok in toks:
@@ -80,7 +81,7 @@ def iter_comments(
8081

8182

8283
def iter_mypy_comments(
83-
filename: str, tokens: List[List[tokenize.TokenInfo]]
84+
filename: Union[pathlib.Path, str], tokens: List[List[tokenize.TokenInfo]]
8485
) -> Iterator[Message]:
8586
for tok in iter_comments(filename, tokens):
8687
try:
@@ -103,17 +104,17 @@ def generate_per_line_token_lists(source: str) -> Iterator[List[tokenize.TokenIn
103104
i += 1
104105

105106

106-
def parse_file(filename: str, config) -> MypyTestFile:
107+
def parse_file(filename: Union[os.PathLike, str, pathlib.Path], config) -> MypyTestFile:
107108
"""Parse *filename* and return information about mypy test cases."""
108-
filename = os.path.abspath(filename)
109+
filename = pathlib.Path(filename).resolve()
109110
with open(filename, "r", encoding="utf-8") as f:
110111
source_text = f.read()
111112

112113
source_lines = source_text.splitlines()
113114
token_lists = list(generate_per_line_token_lists(source_text))
114115
messages = list(iter_mypy_comments(filename, token_lists))
115116

116-
tree = ast.parse(source_text, filename=filename)
117+
tree = ast.parse(source_text, filename=str(filename))
117118
if sys.version_info < (3, 8):
118119
_add_end_lineno_if_missing(tree, len(source_lines))
119120

@@ -131,7 +132,10 @@ def parse_file(filename: str, config) -> MypyTestFile:
131132
)
132133

133134
return MypyTestFile(
134-
filename=filename, source_lines=source_lines, items=items, messages=messages
135+
filename=str(filename),
136+
source_lines=source_lines,
137+
items=items,
138+
messages=messages,
135139
)
136140

137141

Diff for: src/pytest_mypy_testing/plugin.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
import os
5+
import pathlib
56
import tempfile
6-
from typing import Iterable, Iterator, List, NamedTuple, Optional, Tuple
7+
from typing import Iterable, Iterator, List, NamedTuple, Optional, Tuple, Union
78

89
import mypy.api
910
import pytest
1011
from _pytest._code.code import ReprEntry, ReprFileLocation
1112
from _pytest.config import Config
12-
from py._path.local import LocalPath
1313

1414
from .message import Message, Severity
1515
from .output_processing import OutputMismatch, diff_message_sequences
@@ -36,6 +36,8 @@ def __init__(self, item, errors: Iterable[OutputMismatch]):
3636

3737

3838
class PytestMypyTestItem(pytest.Item):
39+
parent: "PytestMypyFile"
40+
3941
def __init__(
4042
self,
4143
name: str,
@@ -72,7 +74,7 @@ def runtest(self) -> None:
7274
if errors:
7375
raise MypyAssertionError(item=self, errors=errors)
7476

75-
def reportinfo(self) -> Tuple[str, Optional[int], str]:
77+
def reportinfo(self) -> Tuple[Union["os.PathLike[str]", str], Optional[int], str]:
7678
return self.parent.fspath, self.mypy_item.lineno, self.name
7779

7880
def repr_failure(self, excinfo, style=None):
@@ -153,7 +155,8 @@ def run_mypy(self, item: MypyTestItem) -> Tuple[int, List[Message]]:
153155
),
154156
)
155157

156-
def _run_mypy(self, filename: str) -> MypyResult:
158+
def _run_mypy(self, filename: Union[pathlib.Path, os.PathLike, str]) -> MypyResult:
159+
filename = pathlib.Path(filename)
157160
with tempfile.TemporaryDirectory(prefix="pytest-mypy-testing-") as tmp_dir_name:
158161

159162
mypy_cache_dir = os.path.join(tmp_dir_name, "mypy_cache")
@@ -213,7 +216,7 @@ def _run_mypy(self, filename: str) -> MypyResult:
213216

214217
if PYTEST_VERSION_INFO < (7,):
215218

216-
def pytest_collect_file(path: LocalPath, parent):
219+
def pytest_collect_file(path, parent):
217220
if path.ext == ".mypy-testing" or _is_pytest_test_file(path, parent):
218221
file = PytestMypyFile.from_parent(parent=parent, fspath=path)
219222
if file.mypy_file.items:
@@ -222,15 +225,15 @@ def pytest_collect_file(path: LocalPath, parent):
222225

223226
else:
224227

225-
def pytest_collect_file(file_path, path: LocalPath, parent): # type: ignore
228+
def pytest_collect_file(file_path, path, parent): # type: ignore
226229
if path.ext == ".mypy-testing" or _is_pytest_test_file(path, parent):
227230
file = PytestMypyFile.from_parent(parent=parent, path=file_path)
228231
if file.mypy_file.items:
229232
return file
230233
return None
231234

232235

233-
def _is_pytest_test_file(path: LocalPath, parent):
236+
def _is_pytest_test_file(path, parent):
234237
"""Return `True` if *path* is considered to be a pytest test file."""
235238
# Based on _pytest/python.py::pytest_collect_file
236239
fn_patterns = parent.config.getini("python_files") + ["__init__.py"]

Diff for: tox.ini

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
[tox]
44
isolated_build = True
55
envlist =
6-
{py36}-pytest{60,61,62,70}-mypy{0910,0931,0960}
7-
{py37,py38,py39}-pytest{62,70,71}-mypy{0910,0931,0960}
8-
{py310}-pytest{62,71}-mypy{0910,0931,0960}
9-
py-pytest{62,70,71}-mypy{0910,0931,0960}
6+
{py36}-pytest{60,61,62,70}-mypy{0910,0931,0971}
7+
{py37,py38,py39}-pytest{62,70,71}-mypy{0910,0931,0971}
8+
{py310}-pytest{62,71}-mypy{0910,0931,0971}
9+
py-pytest{62,70,71}-mypy{0910,0931,0971}
1010
linting
1111

1212
[testenv]
@@ -29,6 +29,8 @@ deps =
2929
mypy0942: mypy==0.942
3030
mypy0950: mypy==0.950
3131
mypy0960: mypy==0.960
32+
mypy0961: mypy==0.961
33+
mypy0971: mypy==0.971
3234
setenv =
3335
COVERAGE_FILE={toxinidir}/build/{envname}/coverage
3436
commands =
@@ -37,6 +39,16 @@ commands =
3739
--html={toxinidir}/build/{envname}/pytest-report.html \
3840
--junitxml={toxinidir}/build/{envname}/junit.xml
3941

42+
[testenv:mypy]
43+
basepython = python3.10
44+
skip_install = True
45+
deps =
46+
-cconstraints.txt
47+
mypy
48+
pytest
49+
commands =
50+
mypy src tests
51+
4052
[testenv:linting]
4153
basepython = python3.10
4254
skip_install = True

0 commit comments

Comments
 (0)