diff --git a/pylint_pytest/checkers/class_attr_loader.py b/pylint_pytest/checkers/class_attr_loader.py index 40d16cf..fdd8339 100644 --- a/pylint_pytest/checkers/class_attr_loader.py +++ b/pylint_pytest/checkers/class_attr_loader.py @@ -1,4 +1,4 @@ -from typing import Optional, Set +from __future__ import annotations from astroid import Assign, Attribute, ClassDef, Name @@ -10,8 +10,8 @@ class ClassAttrLoader(BasePytestChecker): msgs = {"E6400": ("", "pytest-class-attr-loader", "")} in_setup = False - request_cls: Set[str] = set() - class_node: Optional[ClassDef] = None + request_cls: set[str] = set() + class_node: ClassDef | None = None def visit_functiondef(self, node): """determine if a method is a class setup method""" diff --git a/pylint_pytest/checkers/fixture.py b/pylint_pytest/checkers/fixture.py index 86dd5bb..5b13360 100644 --- a/pylint_pytest/checkers/fixture.py +++ b/pylint_pytest/checkers/fixture.py @@ -1,8 +1,9 @@ +from __future__ import annotations + import fnmatch import io import sys from pathlib import Path -from typing import Set, Tuple import astroid import pytest @@ -19,7 +20,7 @@ from .types import FixtureDict, replacement_add_message # TODO: support pytest python_files configuration -FILE_NAME_PATTERNS: Tuple[str, ...] = ("test_*.py", "*_test.py") +FILE_NAME_PATTERNS: tuple[str, ...] = ("test_*.py", "*_test.py") ARGUMENT_ARE_KEYWORD_ONLY = ( "https://docs.pytest.org/en/stable/deprecations.html#pytest-fixture-arguments-are-keyword-only" ) @@ -28,7 +29,7 @@ class FixtureCollector: # Same as ``_pytest.fixtures.FixtureManager._arg2fixturedefs``. fixtures: FixtureDict = {} - errors: Set[pytest.CollectReport] = set() + errors: set[pytest.CollectReport] = set() def pytest_sessionfinish(self, session): # pylint: disable=protected-access @@ -76,9 +77,9 @@ class FixtureChecker(BasePytestChecker): # Store all fixtures discovered by pytest session _pytest_fixtures: FixtureDict = {} # Stores all used function arguments - _invoked_with_func_args: Set[str] = set() + _invoked_with_func_args: set[str] = set() # Stores all invoked fixtures through @pytest.mark.usefixture(...) - _invoked_with_usefixtures: Set[str] = set() + _invoked_with_usefixtures: set[str] = set() _original_add_message = replacement_add_message def open(self): diff --git a/pylint_pytest/checkers/types.py b/pylint_pytest/checkers/types.py index c4c43e8..7fd5708 100644 --- a/pylint_pytest/checkers/types.py +++ b/pylint_pytest/checkers/types.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import sys from pprint import pprint from typing import Any, Dict, List diff --git a/tests/base_tester.py b/tests/base_tester.py index c57971e..c775502 100644 --- a/tests/base_tester.py +++ b/tests/base_tester.py @@ -1,9 +1,10 @@ +from __future__ import annotations + import os import sys from abc import ABC from pathlib import Path from pprint import pprint -from typing import List, Type import astroid from pylint.checkers import BaseChecker @@ -23,9 +24,9 @@ def get_test_root_path() -> Path: class BasePytestTester(ABC): CHECKER_CLASS = BaseChecker - IMPACTED_CHECKER_CLASSES: List[Type[BaseChecker]] = [] + IMPACTED_CHECKER_CLASSES: list[BaseChecker] = [] MSG_ID: str - msgs: List[MessageTest] = [] + msgs: list[MessageTest] = [] def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) diff --git a/tests/base_tester_test.py b/tests/base_tester_test.py index b40d510..89c714c 100644 --- a/tests/base_tester_test.py +++ b/tests/base_tester_test.py @@ -25,7 +25,7 @@ class NoMsgIDSubclass(BasePytestTester): pass -@pytest.mark.parametrize("msg_id", [123, None, ""], ids=lambda x: f"msg_id={x}") +@pytest.mark.parametrize("msg_id", [123, None, ""], ids=lambda msg_id: f"{msg_id=}") def test_init_subclass_invalid_msg_id_type(msg_id): with pytest.raises(TypeError):