Skip to content

Commit bb5090c

Browse files
committed
(Manually) Update MyPy
* Ignore `IAstroidChecker` typing "error" * `CustomVariablesChecker#add_message`: x * `Confidence` type, * separate-module `NodeNG` import * `from __future__ import annotations` * Make `tests/` a module * `BasePytestTester#IMPACTED_CHECKER_CLASSES`: It's a `list[type[BaseChecker]]`, not a `list[BaseChecker]` itself * Add MOAR `tool.mypy.exclude`s (for clean interactive `mypy` execution) Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
1 parent 52c3ecc commit bb5090c

16 files changed

+48
-27
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ repos:
7474
language: pygrep
7575
types: [python]
7676
- repo: https://github.com/pre-commit/mirrors-mypy
77-
rev: v1.8.0
77+
rev: v1.10.1
7878
hooks:
7979
- id: mypy
8080
exclude: tests/input/
81+
additional_dependencies:
82+
- pylint
8183
- repo: local
8284
hooks:
8385
- id: pylint

pylint_pytest/checkers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class BasePytestChecker(BaseChecker):
99
# Since https://github.com/pylint-dev/pylint/pull/8404, pylint does not need this
1010
# __implements__ pattern. keeping it for retro compatibility with pylint==2.x
1111
# pylint: disable=import-outside-toplevel,no-name-in-module
12-
from pylint.interfaces import IAstroidChecker
12+
from pylint.interfaces import ( # type: ignore[attr-defined] # It is defined in pylint~=2
13+
IAstroidChecker,
14+
)
1315

1416
__implements__ = IAstroidChecker
1517

pylint_pytest/checkers/variables.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Any, Optional
1+
from __future__ import annotations
22

3-
from astroid import Arguments, Module
4-
from astroid.nodes.node_ng import NodeNG
3+
from typing import Any
4+
5+
from astroid import Arguments, Module, NodeNG
56
from pylint.checkers.variables import VariablesChecker
67
from pylint.interfaces import Confidence
78

@@ -19,13 +20,13 @@ class CustomVariablesChecker(VariablesChecker):
1920
def add_message(
2021
self,
2122
msgid: str,
22-
line: Optional[int] = None,
23-
node: Optional[NodeNG] = None,
23+
line: int | None = None,
24+
node: NodeNG | None = None,
2425
args: Any = None,
25-
confidence: Confidence = None,
26-
col_offset: Optional[int] = None,
27-
end_lineno: Optional[int] = None,
28-
end_col_offset: Optional[int] = None,
26+
confidence: Confidence | None = None,
27+
col_offset: int | None = None,
28+
end_lineno: int | None = None,
29+
end_col_offset: int | None = None,
2930
) -> None:
3031
"""
3132
- intercept and discard unwanted warning messages

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ exclude = [
117117
"^.venv", # Ignore installed packages
118118
"^.tox", # Ignore tox virtualenvs
119119
"^.cache", # Ignore CI-defined .cache
120-
"^tests/input/" # Ignore test inputs
120+
"^tests/input/", # Ignore test inputs
121+
"^build/", # Ignore build inputs
122+
"^dist/", # Ignore build inputs
121123
]
122124

123125
[[tool.mypy.overrides]]

tests/__init__.py

Whitespace-only changes.

tests/base_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_test_root_path() -> Path:
2424

2525
class BasePytestTester(ABC):
2626
CHECKER_CLASS = BaseChecker
27-
IMPACTED_CHECKER_CLASSES: list[BaseChecker] = []
27+
IMPACTED_CHECKER_CLASSES: list[type[BaseChecker]] = []
2828
MSG_ID: str
2929
msgs: list[MessageTest] = []
3030

tests/base_tester_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
2-
from base_tester import BasePytestTester, get_test_root_path
2+
3+
from .base_tester import BasePytestTester, get_test_root_path
34

45
# pylint: disable=unused-variable
56

tests/test_cannot_enumerate_fixtures.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import re
2+
from collections.abc import Sequence
23

34
import pytest
4-
from base_tester import BasePytestTester
55

66
from pylint_pytest.checkers.fixture import FixtureChecker
77

8+
from .base_tester import BasePytestTester
9+
810

911
class TestCannotEnumerateFixtures(BasePytestTester):
1012
CHECKER_CLASS = FixtureChecker
@@ -18,6 +20,9 @@ def test_no_such_package(self, enable_plugin):
1820
if enable_plugin:
1921
msg = self.msgs[0]
2022

23+
assert isinstance(msg.args, Sequence)
24+
assert len(msg.args) == 3
25+
2126
# Asserts/Fixes duplicate filenames in output:
2227
# https://github.com/reverbc/pylint-pytest/pull/22/files#r698204470
2328
filename_arg = msg.args[0]
@@ -28,7 +33,7 @@ def test_no_such_package(self, enable_plugin):
2833

2934
# Assert `stdout` is non-empty.
3035
assert msg.args[1]
31-
# Assert `stderr` is empty (pytest runs stably, even though fixture collection fails).
36+
# Assert `stderr` is empty (pytest runs stably, even if the fixture collection fails).
3237
assert not msg.args[2]
3338

3439
@pytest.mark.parametrize("enable_plugin", [True, False])
@@ -39,6 +44,9 @@ def test_import_corrupted_module(self, enable_plugin):
3944
if enable_plugin:
4045
msg = self.msgs[0]
4146

47+
assert isinstance(msg.args, Sequence)
48+
assert len(msg.args) == 3
49+
4250
# ... somehow, since `import_corrupted_module.py` imports `no_such_package.py`
4351
# both of their names are returned in the message.
4452
filename_arg = msg.args[0]

tests/test_no_member.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import pytest
2-
from base_tester import BasePytestTester
32
from pylint.checkers.typecheck import TypeChecker
43

54
from pylint_pytest.checkers.class_attr_loader import ClassAttrLoader
65

6+
from .base_tester import BasePytestTester
7+
78

89
class TestNoMember(BasePytestTester):
910
CHECKER_CLASS = ClassAttrLoader

tests/test_pytest_fixture_positional_arguments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from base_tester import BasePytestTester
2-
31
from pylint_pytest.checkers.fixture import FixtureChecker
42

3+
from .base_tester import BasePytestTester
4+
55

66
class TestDeprecatedPytestFixtureScopeAsPositionalParam(BasePytestTester):
77
CHECKER_CLASS = FixtureChecker

0 commit comments

Comments
 (0)