summaryrefslogtreecommitdiff
path: root/tests/checkers
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 /tests/checkers
parent8f872bf49c344d1d16b3573136d53b2cbda007c6 (diff)
downloadpylint-git-a693ea7e1785def007c5a80d379cc7aaf92f38a9.tar.gz
Use ``python-typing-update`` on second half of the ``tests`` directory
Diffstat (limited to 'tests/checkers')
-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
8 files changed, 41 insertions, 34 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