Skip to content

Use python-typing-update on second half of the tests directory #6324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions tests/checkers/base/unittest_name_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

"""Unittest for the NameChecker."""

from __future__ import annotations

import unittest
from typing import Type

from pylint.checkers import base

Expand All @@ -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"),
Expand All @@ -43,15 +44,15 @@ def _test_should_always_pass(self, naming_style: Type[base.NamingStyle]) -> None

@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})"
assert rgx.match(name), fail

@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})"
Expand Down
14 changes: 6 additions & 8 deletions tests/checkers/unittest_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"),)
Expand All @@ -52,7 +50,7 @@ def deprecated_arguments(
return ((0, "deprecated_arg"),)
return ()

def deprecated_decorators(self) -> Set[str]:
def deprecated_decorators(self) -> set[str]:
return {".deprecated_decorator"}


Expand Down
6 changes: 4 additions & 2 deletions tests/checkers/unittest_non_ascii_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -259,7 +261,7 @@ def test_assignname(
),
],
)
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} #@")

Expand Down
11 changes: 7 additions & 4 deletions tests/checkers/unittest_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -40,8 +43,8 @@ def test_deprecated_no_qname_on_unexpected_nodes(self) -> None:
"""

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

Expand Down
10 changes: 7 additions & 3 deletions tests/checkers/unittest_unicode/unittest_bad_chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -210,7 +214,7 @@ def test_bad_chars_that_would_currently_crash_python(
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)
Expand Down
5 changes: 3 additions & 2 deletions tests/checkers/unittest_unicode/unittest_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -103,7 +104,7 @@
)
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."""
Expand Down
6 changes: 4 additions & 2 deletions tests/checkers/unittest_unicode/unittest_invalid_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +139,6 @@ def test__determine_codec_raises_syntax_error_on_invalid_input(self):
"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)
10 changes: 3 additions & 7 deletions tests/checkers/unittest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

from typing import Dict, Union
from __future__ import annotations

import astroid
import pytest
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# 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


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:
Expand Down
4 changes: 3 additions & 1 deletion tests/config/test_find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions tests/config/unittest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions tests/lint/unittest_expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -84,10 +85,10 @@ class Checker(BaseChecker):
"""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",
Expand Down
8 changes: 5 additions & 3 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading