Skip to content

Commit c7b3699

Browse files
committed
Lint
1 parent 7418ec9 commit c7b3699

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

coverage_pyver_pragma/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
import functools
3131
import re
3232
from contextlib import suppress
33+
from typing import Set
3334

3435
# 3rd party
35-
import coverage.python # type: ignore
36-
import pyparsing # type: ignore
37-
from coverage.config import DEFAULT_EXCLUDE # type: ignore
38-
from coverage.misc import join_regex # type: ignore
36+
import coverage.python # type: ignore[import]
37+
import pyparsing
38+
from coverage.config import DEFAULT_EXCLUDE # type: ignore[import]
39+
from coverage.misc import join_regex # type: ignore[import]
3940

4041
# this package
4142
from coverage_pyver_pragma.grammar import GRAMMAR
@@ -73,7 +74,7 @@ def evaluate_exclude(expression: str) -> bool:
7374

7475
class PythonParser(coverage.python.PythonParser):
7576

76-
def lines_matching(self, *regexes):
77+
def lines_matching(self, *regexes) -> Set[int]:
7778

7879
combined = join_regex([*regexes, *DEFAULT_EXCLUDE])
7980

@@ -100,5 +101,5 @@ def lines_matching(self, *regexes):
100101
return matches
101102

102103

103-
def coverage_init(*args, **kwargs):
104+
def coverage_init(*args, **kwargs) -> None:
104105
coverage.python.PythonParser.lines_matching = PythonParser.lines_matching

coverage_pyver_pragma/grammar.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
import packaging.specifiers
144144
from domdf_python_tools.doctools import prettify_docstrings
145145
from domdf_python_tools.stringlist import DelimitedList
146-
from pyparsing import ( # type: ignore
146+
from pyparsing import (
147147
CaselessKeyword,
148148
CaselessLiteral,
149149
Combine,
@@ -256,7 +256,7 @@ class PlatformTag(str):
256256

257257
__slots__ = ()
258258

259-
def __new__(cls, tokens: ParseResults): # noqa: D102
259+
def __new__(cls, tokens: ParseResults) -> "PlatformTag": # noqa: D102
260260
return super().__new__(cls, str(tokens["platform"]))
261261

262262
def __repr__(self) -> str: # pragma: no cover
@@ -293,7 +293,7 @@ class ImplementationTag(str):
293293

294294
__slots__ = ()
295295

296-
def __new__(cls, tokens: ParseResults): # noqa: D102
296+
def __new__(cls, tokens: ParseResults) -> "ImplementationTag": # noqa: D102
297297
return super().__new__(cls, str(tokens["implementation"]))
298298

299299
def __repr__(self) -> str: # pragma: no cover
@@ -314,7 +314,7 @@ class LogicalOp:
314314
def __init__(self, tokens: ParseResults):
315315
self.tokens = DelimitedList(tokens[0])
316316

317-
def __format__(self, format_spec):
317+
def __format__(self, format_spec: str) -> str:
318318
return self.tokens.__format__(format_spec)
319319

320320
def __getitem__(self, item):
@@ -335,7 +335,7 @@ class LogicalAND(LogicalOp):
335335
:param tokens:
336336
"""
337337

338-
def __bool__(self):
338+
def __bool__(self) -> bool:
339339
return bool(self[0]) and bool(self[2])
340340

341341

@@ -347,7 +347,7 @@ class LogicalOR(LogicalOp):
347347
:param tokens:
348348
"""
349349

350-
def __bool__(self):
350+
def __bool__(self) -> bool:
351351
return bool(self[0]) or bool(self[2])
352352

353353

@@ -359,7 +359,7 @@ class LogicalNOT(LogicalOp):
359359
:param tokens:
360360
"""
361361

362-
def __bool__(self):
362+
def __bool__(self) -> bool:
363363
return not bool(self[1])
364364

365365

@@ -379,10 +379,10 @@ def __bool__(self):
379379
GREATER_THAN = '>'
380380

381381
OPS = [LESS_THAN, LESS_THAN_EQUAL, GREATER_THAN, GREATER_THAN_EQUAL]
382-
COMPARATOR = Optional(oneOf(' '.join(OPS))).setResultsName("comparator")
382+
COMPARATOR = Optional(oneOf(' '.join(OPS))).setResultsName("comparator") # type: ignore[operator]
383383

384384
VERSION = Combine(CaselessLiteral("py") + Word(nums)).setResultsName("version")
385-
VERSION_TAG = Group(COMPARATOR + VERSION + Optional(PLUS)).setResultsName("version")
385+
VERSION_TAG = Group(COMPARATOR + VERSION + Optional(PLUS)).setResultsName("version") # type: ignore[operator]
386386
VERSION_TAG.setParseAction(VersionTag)
387387

388388
# Platforms (Windows, !Linux)

tests/test_grammar.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# 3rd party
77
import pytest
8-
from pyparsing import ParseBaseException # type: ignore
8+
from pyparsing import ParseBaseException
99

1010
# this package
1111
from coverage_pyver_pragma import evaluate_exclude
@@ -30,7 +30,11 @@
3030
@pytest.mark.parametrize("implementation", implementations)
3131
@pytest.mark.parametrize("plat", platforms)
3232
@pytest.mark.parametrize("version", versions_before)
33-
def test_grammar_dont_exclude(version: Tuple[int, int], implementation: str, plat: str):
33+
def test_grammar_dont_exclude(
34+
version: Tuple[int, int],
35+
implementation: str,
36+
plat: str,
37+
) -> None:
3438

3539
assert not evaluate_exclude(f"<py{version[0]}{version[1]} and {implementation} and {plat}")
3640
assert not evaluate_exclude(
@@ -51,15 +55,19 @@ def test_grammar_dont_exclude(version: Tuple[int, int], implementation: str, pla
5155
@pytest.mark.parametrize("plat", platforms)
5256
@pytest.mark.parametrize("implementation", implementations)
5357
@pytest.mark.parametrize("version", versions_after)
54-
def test_grammar_exclude(version: Tuple[int, int], implementation: str, plat: str):
58+
def test_grammar_exclude(
59+
version: Tuple[int, int],
60+
implementation: str,
61+
plat: str,
62+
) -> None:
5563

5664
assert evaluate_exclude(f"<=py{version[0]}{version[1]} and {platform.python_implementation()}")
5765
assert evaluate_exclude(f"<=py{version[0]}{version[1]} or {implementation}")
5866
assert evaluate_exclude(f"<=py{version[0]}{version[1]} or !{implementation} and not {plat}")
5967
assert evaluate_exclude(f"<=py{version[0]}{version[1]} or !{implementation} and {platform.system()}")
6068

6169

62-
def test_grammar_current_platform_etc():
70+
def test_grammar_current_platform_etc() -> None:
6371
version = sys.version_info
6472
assert evaluate_exclude(f"py{version[0]}{version[1]}")
6573
assert evaluate_exclude(f"<=py{version[0]}{version[1]}")
@@ -91,7 +99,7 @@ def test_grammar_current_platform_etc():
9199
("<py38+", SyntaxError),
92100
]
93101
)
94-
def test_bad_grammar(expression: str, exception: Type[Exception]):
102+
def test_bad_grammar(expression: str, exception: Type[Exception]) -> None:
95103
with pytest.raises(exception):
96104
evaluate_exclude(expression)
97105

tests/test_plugin.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from io import StringIO
44

55
# 3rd party
6-
import coverage # type: ignore
6+
import coverage # type: ignore[import]
77
import pytest
88
from coincidence import only_version
99
from coincidence.regressions import check_file_regression
10-
from coverage.python import PythonParser # type: ignore
10+
from coverage.python import PythonParser # type: ignore[import]
1111
from domdf_python_tools.paths import PathPlus
1212
from pytest_regressions.file_regression import FileRegressionFixture
1313

@@ -25,7 +25,11 @@
2525
pytest.param("3.10", marks=only_version("3.10", "Output differs on each version.")),
2626
]
2727
)
28-
def test_plugin(tmp_pathplus: PathPlus, file_regression: FileRegressionFixture, version):
28+
def test_plugin(
29+
tmp_pathplus: PathPlus,
30+
file_regression: FileRegressionFixture,
31+
version: str,
32+
) -> None:
2933
coverage_pyver_pragma.coverage_init()
3034

3135
assert PythonParser.lines_matching is coverage_pyver_pragma.PythonParser.lines_matching

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ basepython = python3.6
9999
ignore_errors = True
100100
changedir = {toxinidir}
101101
deps =
102-
mypy==0.931
102+
mypy==0.942
103103
-r{toxinidir}/tests/requirements.txt
104104
-r{toxinidir}/stubs.txt
105105
commands = mypy coverage_pyver_pragma tests {posargs}
@@ -122,6 +122,7 @@ rst-directives =
122122
extras-require
123123
license
124124
license-info
125+
autovariable
125126
rst-roles = choosealicense
126127
per-file-ignores =
127128
tests/*: D100 D101 D102 D103 D104 D106 D201 D204 D207 D208 D209 D210 D211 D212 D213 D214 D215 D300 D301 D400 D402 D403 D404 D415 D417 DALL000 SLOT000 SLOT001 SLOT002

0 commit comments

Comments
 (0)