Skip to content

Commit a693ea7

Browse files
committed
Use python-typing-update on second half of the tests directory
1 parent 8f872bf commit a693ea7

17 files changed

+76
-58
lines changed

tests/checkers/base/unittest_name_preset.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
"""Unittest for the NameChecker."""
66

7+
from __future__ import annotations
8+
79
import unittest
8-
from typing import Type
910

1011
from pylint.checkers import base
1112

@@ -20,18 +21,18 @@ class TestNamePresets(unittest.TestCase):
2021
)
2122

2223
def _test_name_is_correct_for_all_name_types(
23-
self, naming_style: Type[base.NamingStyle], name: str
24+
self, naming_style: type[base.NamingStyle], name: str
2425
) -> None:
2526
for name_type in base.KNOWN_NAME_TYPES_WITH_STYLE:
2627
self._test_is_correct(naming_style, name, name_type)
2728

2829
def _test_name_is_incorrect_for_all_name_types(
29-
self, naming_style: Type[base.NamingStyle], name: str
30+
self, naming_style: type[base.NamingStyle], name: str
3031
) -> None:
3132
for name_type in base.KNOWN_NAME_TYPES_WITH_STYLE:
3233
self._test_is_incorrect(naming_style, name, name_type)
3334

34-
def _test_should_always_pass(self, naming_style: Type[base.NamingStyle]) -> None:
35+
def _test_should_always_pass(self, naming_style: type[base.NamingStyle]) -> None:
3536
always_pass_data = [
3637
("__add__", "method"),
3738
("__set_name__", "method"),
@@ -43,15 +44,15 @@ def _test_should_always_pass(self, naming_style: Type[base.NamingStyle]) -> None
4344

4445
@staticmethod
4546
def _test_is_correct(
46-
naming_style: Type[base.NamingStyle], name: str, name_type: str
47+
naming_style: type[base.NamingStyle], name: str, name_type: str
4748
) -> None:
4849
rgx = naming_style.get_regex(name_type)
4950
fail = f"{name!r} does not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
5051
assert rgx.match(name), fail
5152

5253
@staticmethod
5354
def _test_is_incorrect(
54-
naming_style: Type[base.NamingStyle], name: str, name_type: str
55+
naming_style: type[base.NamingStyle], name: str, name_type: str
5556
) -> None:
5657
rgx = naming_style.get_regex(name_type)
5758
fail = f"{name!r} not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"

tests/checkers/unittest_deprecated.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5-
from typing import List, Optional, Set, Tuple, Union
5+
from __future__ import annotations
66

77
import astroid
88

@@ -15,20 +15,18 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker):
1515
__implements__ = (IAstroidChecker,)
1616
name = "deprecated"
1717

18-
def deprecated_methods(self) -> Set[str]:
18+
def deprecated_methods(self) -> set[str]:
1919
return {"deprecated_func", ".Deprecated.deprecated_method"}
2020

21-
def deprecated_modules(self) -> Set[str]:
21+
def deprecated_modules(self) -> set[str]:
2222
return {"deprecated_module"}
2323

24-
def deprecated_classes(self, module: str) -> List[str]:
24+
def deprecated_classes(self, module: str) -> list[str]:
2525
return ["DeprecatedClass"] if module == "deprecated" else []
2626

2727
def deprecated_arguments(
2828
self, method: str
29-
) -> Union[
30-
Tuple[Tuple[Optional[int], str], ...], Tuple[Tuple[int, str], Tuple[int, str]]
31-
]:
29+
) -> (tuple[tuple[int | None, str], ...] | tuple[tuple[int, str], tuple[int, str]]):
3230
if method == "myfunction1":
3331
# def myfunction1(arg1, deprecated_arg1='spam')
3432
return ((1, "deprecated_arg1"),)
@@ -52,7 +50,7 @@ def deprecated_arguments(
5250
return ((0, "deprecated_arg"),)
5351
return ()
5452

55-
def deprecated_decorators(self) -> Set[str]:
53+
def deprecated_decorators(self) -> set[str]:
5654
return {".deprecated_decorator"}
5755

5856

tests/checkers/unittest_non_ascii_name.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import sys
6-
from typing import Iterable, Optional
8+
from collections.abc import Iterable
79

810
import astroid
911
import pytest
@@ -259,7 +261,7 @@ def test_assignname(
259261
),
260262
],
261263
)
262-
def test_check_import(self, import_statement: str, wrong_name: Optional[str]):
264+
def test_check_import(self, import_statement: str, wrong_name: str | None):
263265
"""We expect that for everything that user can change there is a message."""
264266
node = astroid.extract_node(f"{import_statement} #@")
265267

tests/checkers/unittest_stdlib.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import contextlib
6-
from typing import Any, Callable, Iterator, Optional, Union
8+
from collections.abc import Callable, Iterator
9+
from typing import Any
710

811
import astroid
912
from astroid import nodes
@@ -19,7 +22,7 @@ def _add_transform(
1922
manager: AstroidManager,
2023
node: type,
2124
transform: Callable,
22-
predicate: Optional[Any] = None,
25+
predicate: Any | None = None,
2326
) -> Iterator:
2427
manager.register_transform(node, transform, predicate)
2528
try:
@@ -40,8 +43,8 @@ def test_deprecated_no_qname_on_unexpected_nodes(self) -> None:
4043
"""
4144

4245
def infer_func(
43-
node: Name, context: Optional[Any] = None # pylint: disable=unused-argument
44-
) -> Iterator[Union[Iterator, Iterator[AssignAttr]]]:
46+
node: Name, context: Any | None = None # pylint: disable=unused-argument
47+
) -> Iterator[Iterator | Iterator[AssignAttr]]:
4548
new_node = nodes.AssignAttr(attrname="alpha", parent=node)
4649
yield new_node
4750

tests/checkers/unittest_unicode/unittest_bad_chars.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

55
# pylint: disable=redefined-outer-name
6+
7+
from __future__ import annotations
8+
69
import itertools
10+
from collections.abc import Callable
711
from pathlib import Path
8-
from typing import Callable, Tuple, cast
12+
from typing import cast
913

1014
import astroid
1115
import pytest
@@ -113,7 +117,7 @@ class TestBadCharsChecker(pylint.testutils.CheckerTestCase):
113117
def test_find_bad_chars(
114118
self,
115119
bad_char_file_generator: Callable[[str, bool, str], Path],
116-
codec_and_msg: Tuple[str, Tuple[pylint.testutils.MessageTest]],
120+
codec_and_msg: tuple[str, tuple[pylint.testutils.MessageTest]],
117121
line_ending: str,
118122
add_invalid_bytes: bool,
119123
):
@@ -210,7 +214,7 @@ def test_bad_chars_that_would_currently_crash_python(
210214
self,
211215
char: str,
212216
msg_id: str,
213-
codec_and_msg: Tuple[str, Tuple[pylint.testutils.MessageTest]],
217+
codec_and_msg: tuple[str, tuple[pylint.testutils.MessageTest]],
214218
):
215219
"""Special test for a file containing chars that lead to
216220
Python or Astroid crashes (which causes Pylint to exit early)

tests/checkers/unittest_unicode/unittest_functions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import itertools
68
from pathlib import Path
7-
from typing import Dict
89

910
import pytest
1011

@@ -103,7 +104,7 @@
103104
)
104105
def test_map_positions_to_result(
105106
line: pylint.checkers.unicode._StrLike,
106-
expected: Dict[int, pylint.checkers.unicode._BadChar],
107+
expected: dict[int, pylint.checkers.unicode._BadChar],
107108
search_dict,
108109
):
109110
"""Test all possible outcomes for map position function in UTF-8 and ASCII."""

tests/checkers/unittest_unicode/unittest_invalid_encoding.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import codecs
68
import io
79
import shutil
810
from pathlib import Path
9-
from typing import Tuple, cast
11+
from typing import cast
1012

1113
import pytest
1214
from astroid import nodes
@@ -137,6 +139,6 @@ def test__determine_codec_raises_syntax_error_on_invalid_input(self):
137139
"codec, msg",
138140
(pytest.param(codec, msg, id=codec) for codec, msg in CODEC_AND_MSG),
139141
)
140-
def test___check_codec(self, codec: str, msg: Tuple[pylint.testutils.MessageTest]):
142+
def test___check_codec(self, codec: str, msg: tuple[pylint.testutils.MessageTest]):
141143
with self.assertAddsMessages(*msg):
142144
self.checker._check_codec(codec, 1)

tests/checkers/unittest_utils.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"""Tests for the pylint.checkers.utils module."""
66

7-
from typing import Dict, Union
7+
from __future__ import annotations
88

99
import astroid
1010
import pytest
@@ -32,9 +32,7 @@ def testIsBuiltin(name, expected):
3232
"fn,kw",
3333
[("foo(3)", {"keyword": "bar"}), ("foo(one=a, two=b, three=c)", {"position": 1})],
3434
)
35-
def testGetArgumentFromCallError(
36-
fn: str, kw: Union[Dict[str, int], Dict[str, str]]
37-
) -> None:
35+
def testGetArgumentFromCallError(fn: str, kw: dict[str, int] | dict[str, str]) -> None:
3836
with pytest.raises(utils.NoSuchArgumentError):
3937
node = astroid.extract_node(fn)
4038
utils.get_argument_from_call(node, **kw)
@@ -43,9 +41,7 @@ def testGetArgumentFromCallError(
4341
@pytest.mark.parametrize(
4442
"fn,kw", [("foo(bar=3)", {"keyword": "bar"}), ("foo(a, b, c)", {"position": 1})]
4543
)
46-
def testGetArgumentFromCallExists(
47-
fn: str, kw: Union[Dict[str, int], Dict[str, str]]
48-
) -> None:
44+
def testGetArgumentFromCallExists(fn: str, kw: dict[str, int] | dict[str, str]) -> None:
4945
node = astroid.extract_node(fn)
5046
assert utils.get_argument_from_call(node, **kw) is not None
5147

tests/config/test_config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import os
68
from pathlib import Path
7-
from typing import Optional, Set
89

910
from pylint.lint.run import Run
1011
from pylint.testutils.configuration_test import run_using_a_configuration_file
1112

1213

1314
def check_configuration_file_reader(
1415
runner: Run,
15-
expected_disabled: Optional[Set[str]] = None,
16+
expected_disabled: set[str] | None = None,
1617
expected_jobs: int = 10,
1718
expected_reports_truthey: bool = True,
1819
) -> None:

tests/config/test_find_default_config_files.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import contextlib
68
import importlib
79
import os
810
import shutil
911
import sys
1012
import tempfile
13+
from collections.abc import Iterator
1114
from pathlib import Path
12-
from typing import Iterator
1315

1416
import pytest
1517

tests/config/unittest_config.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
"""Unit tests for the config module."""
66

7+
from __future__ import annotations
8+
79
import re
810
import sre_constants
9-
from typing import Dict, Tuple, Type
1011

1112
import pytest
1213

@@ -66,10 +67,10 @@ class TestPyLinterOptionSetters(CheckerTestCase):
6667

6768
class Checker(BaseChecker):
6869
name = "checker"
69-
msgs: Dict[str, Tuple[str, ...]] = {}
70+
msgs: dict[str, tuple[str, ...]] = {}
7071
options = (("test-opt", {"action": "store_true", "help": "help message"}),)
7172

72-
CHECKER_CLASS: Type = Checker
73+
CHECKER_CLASS: type = Checker
7374

7475
@set_config(ignore_paths=".*/tests/.*,.*\\ignore\\.*")
7576
def test_ignore_paths_with_value(self) -> None:

tests/lint/unittest_expand_modules.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

5+
from __future__ import annotations
6+
57
import re
68
from pathlib import Path
7-
from typing import Dict, Tuple, Type
89

910
import pytest
1011

@@ -84,10 +85,10 @@ class Checker(BaseChecker):
8485
"""This dummy checker is needed to allow options to be set."""
8586

8687
name = "checker"
87-
msgs: Dict[str, Tuple[str, ...]] = {}
88+
msgs: dict[str, tuple[str, ...]] = {}
8889
options = (("test-opt", {"action": "store_true", "help": "help message"}),)
8990

90-
CHECKER_CLASS: Type = Checker
91+
CHECKER_CLASS: type = Checker
9192

9293
@pytest.mark.parametrize(
9394
"files_or_modules,expected",

tests/lint/unittest_lint.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44

55
# pylint: disable=redefined-outer-name
66

7+
from __future__ import annotations
8+
79
import argparse
810
import os
911
import re
1012
import sys
1113
import tempfile
14+
from collections.abc import Iterable, Iterator
1215
from contextlib import contextmanager
1316
from importlib import reload
1417
from io import StringIO
1518
from os import chdir, getcwd
1619
from os.path import abspath, dirname, join, sep
1720
from shutil import rmtree
18-
from typing import Iterable, Iterator, List
1921

2022
import platformdirs
2123
import pytest
@@ -106,7 +108,7 @@ def fake_path() -> Iterator[Iterable[str]]:
106108
sys.path[:] = orig
107109

108110

109-
def test_no_args(fake_path: List[int]) -> None:
111+
def test_no_args(fake_path: list[int]) -> None:
110112
with lint.fix_import_path([]):
111113
assert sys.path == fake_path
112114
assert sys.path == fake_path
@@ -115,7 +117,7 @@ def test_no_args(fake_path: List[int]) -> None:
115117
@pytest.mark.parametrize(
116118
"case", [["a/b/"], ["a/b"], ["a/b/__init__.py"], ["a/"], ["a"]]
117119
)
118-
def test_one_arg(fake_path: List[str], case: List[str]) -> None:
120+
def test_one_arg(fake_path: list[str], case: list[str]) -> None:
119121
with tempdir() as chroot:
120122
create_files(["a/b/__init__.py"])
121123
expected = [join(chroot, "a")] + fake_path

0 commit comments

Comments
 (0)