summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-14 19:37:49 +0200
committerGitHub <noreply@github.com>2022-04-14 19:37:49 +0200
commit8f872bf49c344d1d16b3573136d53b2cbda007c6 (patch)
treed203652d9d515b2a5d47cca6e1f7519a157d5990
parentadf660a7300148a31cdb8bc25301bfd21af0602b (diff)
downloadpylint-git-8f872bf49c344d1d16b3573136d53b2cbda007c6.tar.gz
Use ``python-typing-update`` on half of the ``tests`` directory (#6317)
-rw-r--r--tests/pyreverse/conftest.py6
-rw-r--r--tests/pyreverse/test_diadefs.py12
-rw-r--r--tests/pyreverse/test_diagrams.py5
-rw-r--r--tests/pyreverse/test_inspector.py5
-rw-r--r--tests/pyreverse/test_main.py6
-rw-r--r--tests/pyreverse/test_printer.py6
-rw-r--r--tests/pyreverse/test_writer.py5
-rw-r--r--tests/test_check_parallel.py11
-rw-r--r--tests/test_func.py15
-rw-r--r--tests/test_functional.py10
-rw-r--r--tests/test_import_graph.py6
-rw-r--r--tests/test_pylint_runners.py6
-rw-r--r--tests/test_regr.py12
-rw-r--r--tests/test_self.py27
-rw-r--r--tests/test_similar.py11
-rw-r--r--tests/testutils/test_lint_module_output_update.py15
-rw-r--r--tests/testutils/test_output_line.py6
-rw-r--r--tests/unittest_reporters_json.py6
-rw-r--r--tests/unittest_reporting.py7
-rw-r--r--tests/utils/unittest_ast_walker.py7
20 files changed, 115 insertions, 69 deletions
diff --git a/tests/pyreverse/conftest.py b/tests/pyreverse/conftest.py
index 52b919883..d8b6ea9f4 100644
--- a/tests/pyreverse/conftest.py
+++ b/tests/pyreverse/conftest.py
@@ -2,7 +2,9 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
-from typing import Callable, Optional
+from __future__ import annotations
+
+from collections.abc import Callable
import pytest
from astroid.nodes.scoped_nodes import Module
@@ -65,7 +67,7 @@ def html_config() -> PyreverseConfig:
@pytest.fixture(scope="session")
def get_project() -> Callable:
- def _get_project(module: str, name: Optional[str] = "No Name") -> Project:
+ def _get_project(module: str, name: str | None = "No Name") -> Project:
"""Return an astroid project representation."""
def _astroid_wrapper(func: Callable, modname: str) -> Module:
diff --git a/tests/pyreverse/test_diadefs.py b/tests/pyreverse/test_diadefs.py
index ecb601b0c..059f756bc 100644
--- a/tests/pyreverse/test_diadefs.py
+++ b/tests/pyreverse/test_diadefs.py
@@ -3,10 +3,14 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Unit test for the extensions.diadefslib modules."""
+
# pylint: disable=redefined-outer-name
+
+from __future__ import annotations
+
import sys
+from collections.abc import Callable
from pathlib import Path
-from typing import Callable, Dict, List, Tuple
import pytest
from astroid import nodes
@@ -22,14 +26,14 @@ from pylint.pyreverse.inspector import Linker, Project
from pylint.testutils.pyreverse import PyreverseConfig
-def _process_classes(classes: List[DiagramEntity]) -> List[Tuple[bool, str]]:
+def _process_classes(classes: list[DiagramEntity]) -> list[tuple[bool, str]]:
"""Extract class names of a list."""
return sorted((isinstance(c.node, nodes.ClassDef), c.title) for c in classes)
def _process_relations(
- relations: Dict[str, List[Relationship]]
-) -> List[Tuple[str, str, str]]:
+ relations: dict[str, list[Relationship]]
+) -> list[tuple[str, str, str]]:
"""Extract relation indices from a relation list."""
result = []
for rel_type, rels in relations.items():
diff --git a/tests/pyreverse/test_diagrams.py b/tests/pyreverse/test_diagrams.py
index f10af571d..b4a59a571 100644
--- a/tests/pyreverse/test_diagrams.py
+++ b/tests/pyreverse/test_diagrams.py
@@ -3,7 +3,10 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Unit test for the diagrams modules."""
-from typing import Callable
+
+from __future__ import annotations
+
+from collections.abc import Callable
from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler
from pylint.pyreverse.inspector import Linker
diff --git a/tests/pyreverse/test_inspector.py b/tests/pyreverse/test_inspector.py
index 8f053c148..db0f4656a 100644
--- a/tests/pyreverse/test_inspector.py
+++ b/tests/pyreverse/test_inspector.py
@@ -3,10 +3,13 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""For the visitors.diadefs module."""
+
# pylint: disable=redefined-outer-name
+from __future__ import annotations
+
import os
-from typing import Callable
+from collections.abc import Callable
import astroid
import pytest
diff --git a/tests/pyreverse/test_main.py b/tests/pyreverse/test_main.py
index 072542c3a..b5ea3fda9 100644
--- a/tests/pyreverse/test_main.py
+++ b/tests/pyreverse/test_main.py
@@ -3,9 +3,13 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Unittest for the main module."""
+
+from __future__ import annotations
+
import os
import sys
-from typing import Any, Iterator
+from collections.abc import Iterator
+from typing import Any
from unittest import mock
import pytest
diff --git a/tests/pyreverse/test_printer.py b/tests/pyreverse/test_printer.py
index 9128fc6dd..3822383db 100644
--- a/tests/pyreverse/test_printer.py
+++ b/tests/pyreverse/test_printer.py
@@ -2,7 +2,7 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
-from typing import Type
+from __future__ import annotations
import pytest
from astroid import nodes
@@ -29,7 +29,7 @@ from pylint.pyreverse.vcg_printer import VCGPrinter
],
)
def test_explicit_layout(
- layout: Layout, printer_class: Type[Printer], expected_content: str, line_index: int
+ layout: Layout, printer_class: type[Printer], expected_content: str, line_index: int
) -> None:
printer = printer_class(title="unittest", layout=layout)
assert printer.lines[line_index].strip() == expected_content
@@ -39,7 +39,7 @@ def test_explicit_layout(
"layout, printer_class",
[(Layout.BOTTOM_TO_TOP, PlantUmlPrinter), (Layout.RIGHT_TO_LEFT, PlantUmlPrinter)],
)
-def test_unsupported_layout(layout: Layout, printer_class: Type[Printer]):
+def test_unsupported_layout(layout: Layout, printer_class: type[Printer]):
with pytest.raises(ValueError):
printer_class(title="unittest", layout=layout)
diff --git a/tests/pyreverse/test_writer.py b/tests/pyreverse/test_writer.py
index d3b2d8f44..a03105092 100644
--- a/tests/pyreverse/test_writer.py
+++ b/tests/pyreverse/test_writer.py
@@ -4,11 +4,12 @@
"""Unit test for ``DiagramWriter``."""
+from __future__ import annotations
import codecs
import os
+from collections.abc import Callable, Iterator
from difflib import unified_diff
-from typing import Callable, Iterator, List
from unittest.mock import Mock
import pytest
@@ -53,7 +54,7 @@ class Config:
setattr(self, attr, value)
-def _file_lines(path: str) -> List[str]:
+def _file_lines(path: str) -> list[str]:
# we don't care about the actual encoding, but python3 forces us to pick one
with codecs.open(path, encoding="latin1") as stream:
lines = [
diff --git a/tests/test_check_parallel.py b/tests/test_check_parallel.py
index d41ed13f4..839f75c71 100644
--- a/tests/test_check_parallel.py
+++ b/tests/test_check_parallel.py
@@ -6,10 +6,11 @@
# pylint: disable=protected-access,missing-function-docstring,no-self-use
+from __future__ import annotations
+
import argparse
import multiprocessing
import os
-from typing import List
import dill
import pytest
@@ -41,7 +42,7 @@ def _gen_file_data(idx: int = 0) -> FileItem:
return file_data
-def _gen_file_datas(count: int = 1) -> List[FileItem]:
+def _gen_file_datas(count: int = 1) -> list[FileItem]:
return [_gen_file_data(idx) for idx in range(count)]
@@ -62,7 +63,7 @@ class SequentialTestChecker(BaseChecker):
def __init__(self, linter: PyLinter) -> None:
super().__init__(linter)
- self.data: List[str] = []
+ self.data: list[str] = []
self.linter = linter
def process_module(self, _node: nodes.Module) -> None:
@@ -101,7 +102,7 @@ class ParallelTestChecker(BaseChecker, MapReduceMixin):
def __init__(self, linter: PyLinter) -> None:
super().__init__(linter)
- self.data: List[str] = []
+ self.data: list[str] = []
self.linter = linter
def open(self) -> None:
@@ -116,7 +117,7 @@ class ParallelTestChecker(BaseChecker, MapReduceMixin):
def get_map_data(self):
return self.data
- def reduce_map_data(self, linter: PyLinter, data: List[List[str]]) -> None:
+ def reduce_map_data(self, linter: PyLinter, data: list[list[str]]) -> None:
recombined = type(self)(linter)
recombined.open()
aggregated = []
diff --git a/tests/test_func.py b/tests/test_func.py
index 207c9b8c9..17ff23ff5 100644
--- a/tests/test_func.py
+++ b/tests/test_func.py
@@ -4,10 +4,11 @@
"""Functional/non regression tests for pylint."""
+from __future__ import annotations
+
import re
import sys
from os.path import abspath, dirname, join
-from typing import List, Optional, Tuple
import pytest
@@ -29,13 +30,13 @@ def exception_str(self, ex) -> str: # pylint: disable=unused-argument
class LintTestUsingModule:
- INPUT_DIR: Optional[str] = None
+ INPUT_DIR: str | None = None
DEFAULT_PACKAGE = "input"
package = DEFAULT_PACKAGE
linter = linter
- module: Optional[str] = None
- depends: Optional[List[Tuple[str, str]]] = None
- output: Optional[str] = None
+ module: str | None = None
+ depends: list[tuple[str, str]] | None = None
+ output: str | None = None
def _test_functionality(self) -> None:
if self.module:
@@ -54,7 +55,7 @@ class LintTestUsingModule:
)
assert self._get_expected() == got, error_msg
- def _test(self, tocheck: List[str]) -> None:
+ def _test(self, tocheck: list[str]) -> None:
if self.module and INFO_TEST_RGX.match(self.module):
self.linter.enable("I")
else:
@@ -137,7 +138,7 @@ def test_functionality(
def __test_functionality(
- module_file: str, messages_file: str, dependencies: List[Tuple[str, str]]
+ module_file: str, messages_file: str, dependencies: list[tuple[str, str]]
) -> None:
lint_test = LintTestUpdate() if UPDATE_FILE.exists() else LintTestUsingModule()
lint_test.module = module_file.replace(".py", "")
diff --git a/tests/test_functional.py b/tests/test_functional.py
index 14d2384d9..a286e8f2a 100644
--- a/tests/test_functional.py
+++ b/tests/test_functional.py
@@ -3,9 +3,11 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Functional full-module tests for PyLint."""
+
+from __future__ import annotations
+
import sys
from pathlib import Path
-from typing import Union
import pytest
from _pytest.config import Config
@@ -46,9 +48,9 @@ def test_functional(
) -> None:
__tracebackhide__ = True # pylint: disable=unused-variable
if UPDATE_FILE.exists():
- lint_test: Union[
- LintModuleOutputUpdate, testutils.LintModuleTest
- ] = LintModuleOutputUpdate(test_file, pytestconfig)
+ lint_test: (
+ LintModuleOutputUpdate | testutils.LintModuleTest
+ ) = LintModuleOutputUpdate(test_file, pytestconfig)
else:
lint_test = testutils.LintModuleTest(test_file, pytestconfig)
lint_test.setUp()
diff --git a/tests/test_import_graph.py b/tests/test_import_graph.py
index 5efd11e85..b28285b84 100644
--- a/tests/test_import_graph.py
+++ b/tests/test_import_graph.py
@@ -4,10 +4,12 @@
# pylint: disable=redefined-outer-name
+from __future__ import annotations
+
import os
import shutil
+from collections.abc import Iterator
from os.path import exists
-from typing import Iterator, Union
import pytest
from _pytest.fixtures import SubRequest
@@ -18,7 +20,7 @@ from pylint.lint import PyLinter
@pytest.fixture
-def dest(request: SubRequest) -> Iterator[Union[Iterator, Iterator[str]]]:
+def dest(request: SubRequest) -> Iterator[Iterator | Iterator[str]]:
dest = request.param
yield dest
try:
diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py
index 303b433d3..b06046e22 100644
--- a/tests/test_pylint_runners.py
+++ b/tests/test_pylint_runners.py
@@ -1,11 +1,13 @@
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
-
# pylint: disable=missing-module-docstring, missing-function-docstring
+
+from __future__ import annotations
+
import os
import sys
-from typing import Callable
+from collections.abc import Callable
from unittest.mock import patch
import pytest
diff --git a/tests/test_regr.py b/tests/test_regr.py
index c795bf813..32f714b88 100644
--- a/tests/test_regr.py
+++ b/tests/test_regr.py
@@ -5,12 +5,16 @@
"""Non regression tests for pylint, which requires a too specific configuration
to be incorporated in the automatic functional test framework
"""
+
# pylint: disable=redefined-outer-name
+from __future__ import annotations
+
import os
import sys
+from collections.abc import Callable, Iterator
from os.path import abspath, dirname, join
-from typing import Callable, Iterator, List, cast
+from typing import cast
import astroid
import pytest
@@ -63,7 +67,7 @@ def Equals(expected):
],
)
def test_package(
- finalize_linter: PyLinter, file_names: List[str], check: Callable
+ finalize_linter: PyLinter, file_names: list[str], check: Callable
) -> None:
finalize_linter.check(file_names)
finalize_linter.reporter = cast( # Due to fixture
@@ -81,7 +85,7 @@ def test_package(
[join(REGR_DATA, "try_finally_disable_msg_crash")],
],
)
-def test_crash(finalize_linter: PyLinter, file_names: List[str]) -> None:
+def test_crash(finalize_linter: PyLinter, file_names: list[str]) -> None:
finalize_linter.check(file_names)
@@ -142,5 +146,5 @@ def test_pylint_config_attr() -> None:
@pytest.mark.timeout(30)
@pytest.mark.parametrize("file_names", ([join(REGR_DATA, "hang", "pkg4972.string")],))
-def test_hang(finalize_linter: PyLinter, file_names: List[str]) -> None:
+def test_hang(finalize_linter: PyLinter, file_names: list[str]) -> None:
finalize_linter.check(file_names)
diff --git a/tests/test_self.py b/tests/test_self.py
index 24b564ede..e2b859a21 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -4,6 +4,8 @@
# pylint: disable=too-many-public-methods
+from __future__ import annotations
+
import configparser
import contextlib
import json
@@ -14,11 +16,12 @@ import subprocess
import sys
import textwrap
import warnings
+from collections.abc import Generator, Iterator
from copy import copy
from io import BytesIO, StringIO
from os.path import abspath, dirname, join
from pathlib import Path
-from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Optional, TextIO
+from typing import TYPE_CHECKING, Any, TextIO
from unittest import mock
from unittest.mock import patch
@@ -92,7 +95,7 @@ def _test_cwd() -> Generator[None, None, None]:
class MultiReporter(BaseReporter):
- def __init__(self, reporters: List[BaseReporter]) -> None:
+ def __init__(self, reporters: list[BaseReporter]) -> None:
# pylint: disable=super-init-not-called
# We don't call it because there is an attribute "linter" that is set inside the base class
# and we have another setter here using yet undefined attribute.
@@ -108,7 +111,7 @@ class MultiReporter(BaseReporter):
for rep in self._reporters:
rep.handle_message(msg)
- def _display(self, layout: "Section") -> None:
+ def _display(self, layout: Section) -> None:
pass
@property
@@ -129,10 +132,10 @@ class MultiReporter(BaseReporter):
class TestRunTC:
def _runtest(
self,
- args: List[str],
+ args: list[str],
reporter: Any = None,
- out: Optional[StringIO] = None,
- code: Optional[int] = None,
+ out: StringIO | None = None,
+ code: int | None = None,
) -> None:
if out is None:
out = StringIO()
@@ -149,7 +152,7 @@ class TestRunTC:
assert pylint_code == code, msg
@staticmethod
- def _run_pylint(args: List[str], out: TextIO, reporter: Any = None) -> int:
+ def _run_pylint(args: list[str], out: TextIO, reporter: Any = None) -> int:
args = args + ["--persistent=no"]
with _patch_streams(out):
with pytest.raises(SystemExit) as cm:
@@ -164,7 +167,7 @@ class TestRunTC:
output = re.sub(CLEAN_PATH, "", output, flags=re.MULTILINE)
return output.replace("\\", "/")
- def _test_output(self, args: List[str], expected_output: str) -> None:
+ def _test_output(self, args: list[str], expected_output: str) -> None:
out = StringIO()
self._run_pylint(args, out=out)
actual_output = self._clean_paths(out.getvalue())
@@ -172,7 +175,7 @@ class TestRunTC:
assert expected_output.strip() in actual_output.strip()
def _test_output_file(
- self, args: List[str], filename: LocalPath, expected_output: str
+ self, args: list[str], filename: LocalPath, expected_output: str
) -> None:
"""Run Pylint with the ``output`` option set (must be included in
the ``args`` passed to this method!) and check the file content afterwards.
@@ -602,7 +605,7 @@ class TestRunTC:
assert mock_stdin.call_count == 1
def test_version(self) -> None:
- def check(lines: List[str]) -> None:
+ def check(lines: list[str]) -> None:
assert lines[0].startswith("pylint ")
assert lines[1].startswith("astroid ")
assert lines[2].startswith("Python ")
@@ -766,7 +769,7 @@ class TestRunTC:
def test_modify_sys_path() -> None:
@contextlib.contextmanager
def test_environ_pythonpath(
- new_pythonpath: Optional[str],
+ new_pythonpath: str | None,
) -> Generator[None, None, None]:
original_pythonpath = os.environ.get("PYTHONPATH")
if new_pythonpath:
@@ -1289,7 +1292,7 @@ class TestCallbackOptions:
(["--long-help"], "Environment variables:"),
],
)
- def test_output_of_callback_options(command: List[str], expected: str) -> None:
+ def test_output_of_callback_options(command: list[str], expected: str) -> None:
"""Test whether certain strings are in the output of a callback command."""
process = subprocess.run(
diff --git a/tests/test_similar.py b/tests/test_similar.py
index f595102bc..2c258a019 100644
--- a/tests/test_similar.py
+++ b/tests/test_similar.py
@@ -2,14 +2,17 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+from __future__ import annotations
+
import contextlib
import os
import re
import sys
import warnings
+from collections.abc import Iterator
from io import StringIO
from os.path import abspath, dirname, join
-from typing import Iterator, List, TextIO
+from typing import TextIO
import pytest
@@ -31,7 +34,7 @@ def _patch_streams(out: TextIO) -> Iterator:
class TestSimilarCodeChecker:
- def _runtest(self, args: List[str], code: int) -> None:
+ def _runtest(self, args: list[str], code: int) -> None:
"""Runs the tests and sees if output code is as expected."""
out = StringIO()
pylint_code = self._run_pylint(args, out=out)
@@ -42,7 +45,7 @@ class TestSimilarCodeChecker:
assert pylint_code == code, msg
@staticmethod
- def _run_pylint(args: List[str], out: TextIO) -> int:
+ def _run_pylint(args: list[str], out: TextIO) -> int:
"""Runs pylint with a patched output."""
args = args + ["--persistent=no"]
with _patch_streams(out):
@@ -58,7 +61,7 @@ class TestSimilarCodeChecker:
output = re.sub(CLEAN_PATH, "", output, flags=re.MULTILINE)
return output.replace("\\", "/")
- def _test_output(self, args: List[str], expected_output: str) -> None:
+ def _test_output(self, args: list[str], expected_output: str) -> None:
"""Tests if the output of a pylint run is as expected."""
out = StringIO()
self._run_pylint(args, out=out)
diff --git a/tests/testutils/test_lint_module_output_update.py b/tests/testutils/test_lint_module_output_update.py
index 6d46f84b4..1c9e589af 100644
--- a/tests/testutils/test_lint_module_output_update.py
+++ b/tests/testutils/test_lint_module_output_update.py
@@ -3,8 +3,11 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
# pylint: disable=redefined-outer-name
+
+from __future__ import annotations
+
+from collections.abc import Callable
from pathlib import Path
-from typing import Callable, Tuple
import pytest
@@ -16,8 +19,8 @@ from pylint.testutils.functional import LintModuleOutputUpdate
@pytest.fixture()
def lint_module_fixture(
tmp_path: Path,
-) -> Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]:
- def inner(base: str) -> Tuple[Path, Path, LintModuleOutputUpdate]:
+) -> Callable[[str], tuple[Path, Path, LintModuleOutputUpdate]]:
+ def inner(base: str) -> tuple[Path, Path, LintModuleOutputUpdate]:
filename = tmp_path / f"{base}.py"
expected_output_file = tmp_path / f"{base}.txt"
lmou = LintModuleOutputUpdate(
@@ -38,7 +41,7 @@ def test_not_py38(tmp_path: Path) -> None:
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
def test_lint_module_output_update_fail_before(
- lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
+ lint_module_fixture: Callable[[str], tuple[Path, Path, LintModuleOutputUpdate]]
) -> None:
"""There is a fail before the output need to be updated."""
filename, expected_output_file, lmou = lint_module_fixture("foo")
@@ -51,7 +54,7 @@ def test_lint_module_output_update_fail_before(
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
def test_lint_module_output_update_effective(
- lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
+ lint_module_fixture: Callable[[str], tuple[Path, Path, LintModuleOutputUpdate]]
) -> None:
"""The file is updated following a successful tests with wrong output."""
filename, expected_output_file, lmou = lint_module_fixture("foo")
@@ -66,7 +69,7 @@ def test_lint_module_output_update_effective(
@pytest.mark.skipif(not PY38_PLUS, reason="Requires python 3.8 or superior")
def test_lint_module_output_update_remove_useless_txt(
- lint_module_fixture: Callable[[str], Tuple[Path, Path, LintModuleOutputUpdate]]
+ lint_module_fixture: Callable[[str], tuple[Path, Path, LintModuleOutputUpdate]]
) -> None:
"""The file is updated following a successful tests with wrong output."""
filename, expected_output_file, lmou = lint_module_fixture("fine_name")
diff --git a/tests/testutils/test_output_line.py b/tests/testutils/test_output_line.py
index 6e6335ecc..0a194b973 100644
--- a/tests/testutils/test_output_line.py
+++ b/tests/testutils/test_output_line.py
@@ -4,7 +4,9 @@
# pylint: disable=redefined-outer-name
-from typing import Callable, Optional
+from __future__ import annotations
+
+from collections.abc import Callable
import pytest
@@ -151,7 +153,7 @@ def test_output_line_from_csv_error() -> None:
"confidence,expected_confidence", [[None, "UNDEFINED"], ["INFERENCE", "INFERENCE"]]
)
def test_output_line_from_csv_deprecated(
- confidence: Optional[str], expected_confidence: str
+ confidence: str | None, expected_confidence: str
) -> None:
"""Test that the OutputLine NamedTuple is instantiated correctly with from_csv.
Test OutputLine's of length 5 or 6.
diff --git a/tests/unittest_reporters_json.py b/tests/unittest_reporters_json.py
index 421506fe5..2a0843e7f 100644
--- a/tests/unittest_reporters_json.py
+++ b/tests/unittest_reporters_json.py
@@ -4,9 +4,11 @@
"""Test for the JSON reporter."""
+from __future__ import annotations
+
import json
from io import StringIO
-from typing import Any, Dict, List
+from typing import Any
from pylint import checkers
from pylint.lint import PyLinter
@@ -74,7 +76,7 @@ def test_simple_json_output_no_score_with_end_line() -> None:
assert json.dumps(report) == json.dumps(expected)
-def get_linter_result(score: bool, message: Dict[str, Any]) -> List[Dict[str, Any]]:
+def get_linter_result(score: bool, message: dict[str, Any]) -> list[dict[str, Any]]:
output = StringIO()
reporter = JSONReporter(output)
linter = PyLinter(reporter=reporter)
diff --git a/tests/unittest_reporting.py b/tests/unittest_reporting.py
index 511cf52ce..8fdc89775 100644
--- a/tests/unittest_reporting.py
+++ b/tests/unittest_reporting.py
@@ -3,6 +3,9 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
# pylint: disable=redefined-outer-name
+
+from __future__ import annotations
+
import sys
import warnings
from contextlib import redirect_stdout
@@ -159,7 +162,7 @@ class NopReporter(BaseReporter):
def writeln(self, string=""):
pass
- def _display(self, layout: "Section") -> None:
+ def _display(self, layout: Section) -> None:
pass
@@ -334,7 +337,7 @@ def test_multi_format_output(tmp_path):
def test_display_results_is_renamed():
class CustomReporter(TextReporter):
- def _display(self, layout: "Section") -> None:
+ def _display(self, layout: Section) -> None:
return None
reporter = CustomReporter()
diff --git a/tests/utils/unittest_ast_walker.py b/tests/utils/unittest_ast_walker.py
index ec271bee7..c0ec6b8e6 100644
--- a/tests/utils/unittest_ast_walker.py
+++ b/tests/utils/unittest_ast_walker.py
@@ -2,8 +2,9 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+from __future__ import annotations
+
import warnings
-from typing import Dict, Set
import astroid
@@ -13,7 +14,7 @@ from pylint.utils import ASTWalker
class TestASTWalker:
class MockLinter:
- def __init__(self, msgs: Dict[str, bool]) -> None:
+ def __init__(self, msgs: dict[str, bool]) -> None:
self._msgs = msgs
def is_message_enabled(self, msgid: str) -> bool:
@@ -21,7 +22,7 @@ class TestASTWalker:
class Checker:
def __init__(self) -> None:
- self.called: Set[str] = set()
+ self.called: set[str] = set()
@check_messages("first-message")
def visit_module(self, module): # pylint: disable=unused-argument