summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-14 19:47:25 +0200
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-14 20:06:24 +0200
commita693ea7e1785def007c5a80d379cc7aaf92f38a9 (patch)
tree30c130828abae0b2bc7c1a037e45886d7bf26a99
parent8f872bf49c344d1d16b3573136d53b2cbda007c6 (diff)
downloadpylint-git-a693ea7e1785def007c5a80d379cc7aaf92f38a9.tar.gz
Use ``python-typing-update`` on second half of the ``tests`` directory
-rw-r--r--tests/checkers/base/unittest_name_preset.py13
-rw-r--r--tests/checkers/unittest_deprecated.py14
-rw-r--r--tests/checkers/unittest_non_ascii_name.py6
-rw-r--r--tests/checkers/unittest_stdlib.py11
-rw-r--r--tests/checkers/unittest_unicode/unittest_bad_chars.py10
-rw-r--r--tests/checkers/unittest_unicode/unittest_functions.py5
-rw-r--r--tests/checkers/unittest_unicode/unittest_invalid_encoding.py6
-rw-r--r--tests/checkers/unittest_utils.py10
-rw-r--r--tests/config/test_config.py5
-rw-r--r--tests/config/test_find_default_config_files.py4
-rw-r--r--tests/config/unittest_config.py7
-rw-r--r--tests/lint/unittest_expand_modules.py7
-rw-r--r--tests/lint/unittest_lint.py8
-rw-r--r--tests/message/conftest.py7
-rw-r--r--tests/message/unittest_message.py4
-rw-r--r--tests/message/unittest_message_id_store.py8
-rw-r--r--tests/primer/test_primer_external.py9
17 files changed, 76 insertions, 58 deletions
diff --git a/tests/checkers/base/unittest_name_preset.py b/tests/checkers/base/unittest_name_preset.py
index 9d4b748c6..49a81deff 100644
--- a/tests/checkers/base/unittest_name_preset.py
+++ b/tests/checkers/base/unittest_name_preset.py
@@ -4,8 +4,9 @@
"""Unittest for the NameChecker."""
+from __future__ import annotations
+
import unittest
-from typing import Type
from pylint.checkers import base
@@ -20,18 +21,18 @@ class TestNamePresets(unittest.TestCase):
)
def _test_name_is_correct_for_all_name_types(
- self, naming_style: Type[base.NamingStyle], name: str
+ self, naming_style: type[base.NamingStyle], name: str
) -> None:
for name_type in base.KNOWN_NAME_TYPES_WITH_STYLE:
self._test_is_correct(naming_style, name, name_type)
def _test_name_is_incorrect_for_all_name_types(
- self, naming_style: Type[base.NamingStyle], name: str
+ self, naming_style: type[base.NamingStyle], name: str
) -> None:
for name_type in base.KNOWN_NAME_TYPES_WITH_STYLE:
self._test_is_incorrect(naming_style, name, name_type)
- def _test_should_always_pass(self, naming_style: Type[base.NamingStyle]) -> None:
+ def _test_should_always_pass(self, naming_style: type[base.NamingStyle]) -> None:
always_pass_data = [
("__add__", "method"),
("__set_name__", "method"),
@@ -43,7 +44,7 @@ class TestNamePresets(unittest.TestCase):
@staticmethod
def _test_is_correct(
- naming_style: Type[base.NamingStyle], name: str, name_type: str
+ naming_style: type[base.NamingStyle], name: str, name_type: str
) -> None:
rgx = naming_style.get_regex(name_type)
fail = f"{name!r} does not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
@@ -51,7 +52,7 @@ class TestNamePresets(unittest.TestCase):
@staticmethod
def _test_is_incorrect(
- naming_style: Type[base.NamingStyle], name: str, name_type: str
+ naming_style: type[base.NamingStyle], name: str, name_type: str
) -> None:
rgx = naming_style.get_regex(name_type)
fail = f"{name!r} not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py
index 0b35b297a..0cd71dda9 100644
--- a/tests/checkers/unittest_deprecated.py
+++ b/tests/checkers/unittest_deprecated.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 List, Optional, Set, Tuple, Union
+from __future__ import annotations
import astroid
@@ -15,20 +15,18 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker):
__implements__ = (IAstroidChecker,)
name = "deprecated"
- def deprecated_methods(self) -> Set[str]:
+ def deprecated_methods(self) -> set[str]:
return {"deprecated_func", ".Deprecated.deprecated_method"}
- def deprecated_modules(self) -> Set[str]:
+ def deprecated_modules(self) -> set[str]:
return {"deprecated_module"}
- def deprecated_classes(self, module: str) -> List[str]:
+ def deprecated_classes(self, module: str) -> list[str]:
return ["DeprecatedClass"] if module == "deprecated" else []
def deprecated_arguments(
self, method: str
- ) -> Union[
- Tuple[Tuple[Optional[int], str], ...], Tuple[Tuple[int, str], Tuple[int, str]]
- ]:
+ ) -> (tuple[tuple[int | None, str], ...] | tuple[tuple[int, str], tuple[int, str]]):
if method == "myfunction1":
# def myfunction1(arg1, deprecated_arg1='spam')
return ((1, "deprecated_arg1"),)
@@ -52,7 +50,7 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker):
return ((0, "deprecated_arg"),)
return ()
- def deprecated_decorators(self) -> Set[str]:
+ def deprecated_decorators(self) -> set[str]:
return {".deprecated_decorator"}
diff --git a/tests/checkers/unittest_non_ascii_name.py b/tests/checkers/unittest_non_ascii_name.py
index f6c9abcdb..1830dd7ec 100644
--- a/tests/checkers/unittest_non_ascii_name.py
+++ b/tests/checkers/unittest_non_ascii_name.py
@@ -2,8 +2,10 @@
# 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 sys
-from typing import Iterable, Optional
+from collections.abc import Iterable
import astroid
import pytest
@@ -259,7 +261,7 @@ class TestNonAsciiChecker(pylint.testutils.CheckerTestCase):
),
],
)
- def test_check_import(self, import_statement: str, wrong_name: Optional[str]):
+ def test_check_import(self, import_statement: str, wrong_name: str | None):
"""We expect that for everything that user can change there is a message."""
node = astroid.extract_node(f"{import_statement} #@")
diff --git a/tests/checkers/unittest_stdlib.py b/tests/checkers/unittest_stdlib.py
index cdd61e6ba..f8de2f00d 100644
--- a/tests/checkers/unittest_stdlib.py
+++ b/tests/checkers/unittest_stdlib.py
@@ -2,8 +2,11 @@
# 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
-from typing import Any, Callable, Iterator, Optional, Union
+from collections.abc import Callable, Iterator
+from typing import Any
import astroid
from astroid import nodes
@@ -19,7 +22,7 @@ def _add_transform(
manager: AstroidManager,
node: type,
transform: Callable,
- predicate: Optional[Any] = None,
+ predicate: Any | None = None,
) -> Iterator:
manager.register_transform(node, transform, predicate)
try:
@@ -40,8 +43,8 @@ class TestStdlibChecker(CheckerTestCase):
"""
def infer_func(
- node: Name, context: Optional[Any] = None # pylint: disable=unused-argument
- ) -> Iterator[Union[Iterator, Iterator[AssignAttr]]]:
+ node: Name, context: Any | None = None # pylint: disable=unused-argument
+ ) -> Iterator[Iterator | Iterator[AssignAttr]]:
new_node = nodes.AssignAttr(attrname="alpha", parent=node)
yield new_node
diff --git a/tests/checkers/unittest_unicode/unittest_bad_chars.py b/tests/checkers/unittest_unicode/unittest_bad_chars.py
index 154faad5a..7933597f7 100644
--- a/tests/checkers/unittest_unicode/unittest_bad_chars.py
+++ b/tests/checkers/unittest_unicode/unittest_bad_chars.py
@@ -3,9 +3,13 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
# pylint: disable=redefined-outer-name
+
+from __future__ import annotations
+
import itertools
+from collections.abc import Callable
from pathlib import Path
-from typing import Callable, Tuple, cast
+from typing import cast
import astroid
import pytest
@@ -113,7 +117,7 @@ class TestBadCharsChecker(pylint.testutils.CheckerTestCase):
def test_find_bad_chars(
self,
bad_char_file_generator: Callable[[str, bool, str], Path],
- codec_and_msg: Tuple[str, Tuple[pylint.testutils.MessageTest]],
+ codec_and_msg: tuple[str, tuple[pylint.testutils.MessageTest]],
line_ending: str,
add_invalid_bytes: bool,
):
@@ -210,7 +214,7 @@ class TestBadCharsChecker(pylint.testutils.CheckerTestCase):
self,
char: str,
msg_id: str,
- codec_and_msg: Tuple[str, Tuple[pylint.testutils.MessageTest]],
+ codec_and_msg: tuple[str, tuple[pylint.testutils.MessageTest]],
):
"""Special test for a file containing chars that lead to
Python or Astroid crashes (which causes Pylint to exit early)
diff --git a/tests/checkers/unittest_unicode/unittest_functions.py b/tests/checkers/unittest_unicode/unittest_functions.py
index bf42df996..c2fef9357 100644
--- a/tests/checkers/unittest_unicode/unittest_functions.py
+++ b/tests/checkers/unittest_unicode/unittest_functions.py
@@ -2,9 +2,10 @@
# 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 itertools
from pathlib import Path
-from typing import Dict
import pytest
@@ -103,7 +104,7 @@ SEARCH_DICT_BYTE_UTF8 = {
)
def test_map_positions_to_result(
line: pylint.checkers.unicode._StrLike,
- expected: Dict[int, pylint.checkers.unicode._BadChar],
+ expected: dict[int, pylint.checkers.unicode._BadChar],
search_dict,
):
"""Test all possible outcomes for map position function in UTF-8 and ASCII."""
diff --git a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
index ff46539e4..ac12af856 100644
--- a/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
+++ b/tests/checkers/unittest_unicode/unittest_invalid_encoding.py
@@ -2,11 +2,13 @@
# 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 codecs
import io
import shutil
from pathlib import Path
-from typing import Tuple, cast
+from typing import cast
import pytest
from astroid import nodes
@@ -137,6 +139,6 @@ class TestInvalidEncoding(pylint.testutils.CheckerTestCase):
"codec, msg",
(pytest.param(codec, msg, id=codec) for codec, msg in CODEC_AND_MSG),
)
- def test___check_codec(self, codec: str, msg: Tuple[pylint.testutils.MessageTest]):
+ def test___check_codec(self, codec: str, msg: tuple[pylint.testutils.MessageTest]):
with self.assertAddsMessages(*msg):
self.checker._check_codec(codec, 1)
diff --git a/tests/checkers/unittest_utils.py b/tests/checkers/unittest_utils.py
index 121bcef2e..1ac461141 100644
--- a/tests/checkers/unittest_utils.py
+++ b/tests/checkers/unittest_utils.py
@@ -4,7 +4,7 @@
"""Tests for the pylint.checkers.utils module."""
-from typing import Dict, Union
+from __future__ import annotations
import astroid
import pytest
@@ -32,9 +32,7 @@ def testIsBuiltin(name, expected):
"fn,kw",
[("foo(3)", {"keyword": "bar"}), ("foo(one=a, two=b, three=c)", {"position": 1})],
)
-def testGetArgumentFromCallError(
- fn: str, kw: Union[Dict[str, int], Dict[str, str]]
-) -> None:
+def testGetArgumentFromCallError(fn: str, kw: dict[str, int] | dict[str, str]) -> None:
with pytest.raises(utils.NoSuchArgumentError):
node = astroid.extract_node(fn)
utils.get_argument_from_call(node, **kw)
@@ -43,9 +41,7 @@ def testGetArgumentFromCallError(
@pytest.mark.parametrize(
"fn,kw", [("foo(bar=3)", {"keyword": "bar"}), ("foo(a, b, c)", {"position": 1})]
)
-def testGetArgumentFromCallExists(
- fn: str, kw: Union[Dict[str, int], Dict[str, str]]
-) -> None:
+def testGetArgumentFromCallExists(fn: str, kw: dict[str, int] | dict[str, str]) -> None:
node = astroid.extract_node(fn)
assert utils.get_argument_from_call(node, **kw) is not None
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index 701d24a82..d8b619115 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -2,9 +2,10 @@
# 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 os
from pathlib import Path
-from typing import Optional, Set
from pylint.lint.run import Run
from pylint.testutils.configuration_test import run_using_a_configuration_file
@@ -12,7 +13,7 @@ from pylint.testutils.configuration_test import run_using_a_configuration_file
def check_configuration_file_reader(
runner: Run,
- expected_disabled: Optional[Set[str]] = None,
+ expected_disabled: set[str] | None = None,
expected_jobs: int = 10,
expected_reports_truthey: bool = True,
) -> None:
diff --git a/tests/config/test_find_default_config_files.py b/tests/config/test_find_default_config_files.py
index ca1461bad..c1d99e532 100644
--- a/tests/config/test_find_default_config_files.py
+++ b/tests/config/test_find_default_config_files.py
@@ -2,14 +2,16 @@
# 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 importlib
import os
import shutil
import sys
import tempfile
+from collections.abc import Iterator
from pathlib import Path
-from typing import Iterator
import pytest
diff --git a/tests/config/unittest_config.py b/tests/config/unittest_config.py
index 9b6ff70d9..c282ebe38 100644
--- a/tests/config/unittest_config.py
+++ b/tests/config/unittest_config.py
@@ -4,9 +4,10 @@
"""Unit tests for the config module."""
+from __future__ import annotations
+
import re
import sre_constants
-from typing import Dict, Tuple, Type
import pytest
@@ -66,10 +67,10 @@ class TestPyLinterOptionSetters(CheckerTestCase):
class Checker(BaseChecker):
name = "checker"
- msgs: Dict[str, Tuple[str, ...]] = {}
+ msgs: dict[str, tuple[str, ...]] = {}
options = (("test-opt", {"action": "store_true", "help": "help message"}),)
- CHECKER_CLASS: Type = Checker
+ CHECKER_CLASS: type = Checker
@set_config(ignore_paths=".*/tests/.*,.*\\ignore\\.*")
def test_ignore_paths_with_value(self) -> None:
diff --git a/tests/lint/unittest_expand_modules.py b/tests/lint/unittest_expand_modules.py
index b231c9ace..ac9852938 100644
--- a/tests/lint/unittest_expand_modules.py
+++ b/tests/lint/unittest_expand_modules.py
@@ -2,9 +2,10 @@
# 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 re
from pathlib import Path
-from typing import Dict, Tuple, Type
import pytest
@@ -84,10 +85,10 @@ class TestExpandModules(CheckerTestCase):
"""This dummy checker is needed to allow options to be set."""
name = "checker"
- msgs: Dict[str, Tuple[str, ...]] = {}
+ msgs: dict[str, tuple[str, ...]] = {}
options = (("test-opt", {"action": "store_true", "help": "help message"}),)
- CHECKER_CLASS: Type = Checker
+ CHECKER_CLASS: type = Checker
@pytest.mark.parametrize(
"files_or_modules,expected",
diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py
index b39b30b38..82ed9d3d5 100644
--- a/tests/lint/unittest_lint.py
+++ b/tests/lint/unittest_lint.py
@@ -4,18 +4,20 @@
# pylint: disable=redefined-outer-name
+from __future__ import annotations
+
import argparse
import os
import re
import sys
import tempfile
+from collections.abc import Iterable, Iterator
from contextlib import contextmanager
from importlib import reload
from io import StringIO
from os import chdir, getcwd
from os.path import abspath, dirname, join, sep
from shutil import rmtree
-from typing import Iterable, Iterator, List
import platformdirs
import pytest
@@ -106,7 +108,7 @@ def fake_path() -> Iterator[Iterable[str]]:
sys.path[:] = orig
-def test_no_args(fake_path: List[int]) -> None:
+def test_no_args(fake_path: list[int]) -> None:
with lint.fix_import_path([]):
assert sys.path == fake_path
assert sys.path == fake_path
@@ -115,7 +117,7 @@ def test_no_args(fake_path: List[int]) -> None:
@pytest.mark.parametrize(
"case", [["a/b/"], ["a/b"], ["a/b/__init__.py"], ["a/"], ["a"]]
)
-def test_one_arg(fake_path: List[str], case: List[str]) -> None:
+def test_one_arg(fake_path: list[str], case: list[str]) -> None:
with tempdir() as chroot:
create_files(["a/b/__init__.py"])
expected = [join(chroot, "a")] + fake_path
diff --git a/tests/message/conftest.py b/tests/message/conftest.py
index 76a18c037..e41057835 100644
--- a/tests/message/conftest.py
+++ b/tests/message/conftest.py
@@ -4,8 +4,9 @@
# pylint: disable=redefined-outer-name
+from __future__ import annotations
-from typing import Dict, ValuesView
+from collections.abc import ValuesView
import pytest
@@ -63,7 +64,7 @@ def message_definitions(store: MessageDefinitionStore) -> ValuesView[MessageDefi
@pytest.fixture
-def msgids() -> Dict[str, str]:
+def msgids() -> dict[str, str]:
return {
"W1234": "warning-symbol",
"W1235": "warning-symbol-two",
@@ -78,7 +79,7 @@ def empty_msgid_store() -> MessageIdStore:
@pytest.fixture
-def msgid_store(msgids: Dict[str, str]) -> MessageIdStore:
+def msgid_store(msgids: dict[str, str]) -> MessageIdStore:
msgid_store = MessageIdStore()
for msgid, symbol in msgids.items():
msgid_store.add_msgid_and_symbol(msgid, symbol)
diff --git a/tests/message/unittest_message.py b/tests/message/unittest_message.py
index ef560a649..d0805e337 100644
--- a/tests/message/unittest_message.py
+++ b/tests/message/unittest_message.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 ValuesView
+from __future__ import annotations
+
+from collections.abc import ValuesView
from pylint.interfaces import HIGH
from pylint.message import Message
diff --git a/tests/message/unittest_message_id_store.py b/tests/message/unittest_message_id_store.py
index 150ec8d69..69ff5f50b 100644
--- a/tests/message/unittest_message_id_store.py
+++ b/tests/message/unittest_message_id_store.py
@@ -2,8 +2,10 @@
# 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
+
+from collections.abc import ValuesView
from pathlib import Path
-from typing import Dict, ValuesView
import pytest
@@ -15,7 +17,7 @@ from pylint.message.message_id_store import MessageIdStore
EMPTY_FILE = str(Path(__file__).parent.parent.resolve() / "regrtest_data" / "empty.py")
-def test_len_str(msgid_store: MessageIdStore, msgids: Dict[str, str]) -> None:
+def test_len_str(msgid_store: MessageIdStore, msgids: dict[str, str]) -> None:
assert len(msgid_store) == len(msgids)
str_result = str(msgid_store)
assert "MessageIdStore: [" in str_result
@@ -26,7 +28,7 @@ def test_len_str(msgid_store: MessageIdStore, msgids: Dict[str, str]) -> None:
assert "]" in str_result
-def test_get_message_ids(msgid_store: MessageIdStore, msgids: Dict[str, str]) -> None:
+def test_get_message_ids(msgid_store: MessageIdStore, msgids: dict[str, str]) -> None:
"""We can get message id even with capitalization problem."""
msgid = list(msgids.keys())[0]
msgids_result = msgid_store.get_active_msgids(msgid.lower())
diff --git a/tests/primer/test_primer_external.py b/tests/primer/test_primer_external.py
index 4a4325962..aedc55c8b 100644
--- a/tests/primer/test_primer_external.py
+++ b/tests/primer/test_primer_external.py
@@ -2,11 +2,12 @@
# 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 json
import logging
import subprocess
from pathlib import Path
-from typing import Dict, Union
import pytest
from pytest import LogCaptureFixture
@@ -16,10 +17,8 @@ from pylint.testutils.primer import PackageToLint
PRIMER_DIRECTORY = Path(".pylint_primer_tests/").resolve()
-def get_packages_to_lint_from_json(
- json_path: Union[Path, str]
-) -> Dict[str, PackageToLint]:
- result: Dict[str, PackageToLint] = {}
+def get_packages_to_lint_from_json(json_path: Path | str) -> dict[str, PackageToLint]:
+ result: dict[str, PackageToLint] = {}
with open(json_path, encoding="utf8") as f:
for name, package_data in json.load(f).items():
result[name] = PackageToLint(**package_data)