Skip to content

Commit

Permalink
Roll back from __future__ import annotations for Python 3.6
Browse files Browse the repository at this point in the history
... and `f{msg_id=}`

Signed-off-by: Stavros Ntentos <[email protected]>
  • Loading branch information
stdedos committed Oct 17, 2023
1 parent b65e979 commit b8ce4ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions pylint_pytest/checkers/class_attr_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations
from typing import Optional, Set

from astroid import Assign, Attribute, ClassDef, Name
from pylint.interfaces import IAstroidChecker
Expand All @@ -12,8 +12,8 @@ class ClassAttrLoader(BasePytestChecker):
msgs = {"E6400": ("", "pytest-class-attr-loader", "")}

in_setup = False
request_cls: set[str] = set()
class_node: ClassDef | None = None
request_cls: Set[str] = set()
class_node: Optional[ClassDef] = None

def visit_functiondef(self, node):
"""determine if a method is a class setup method"""
Expand Down
11 changes: 5 additions & 6 deletions pylint_pytest/checkers/fixture.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

import fnmatch
import os
import sys
from pathlib import Path
from typing import Set, Tuple

import astroid
import pylint
Expand All @@ -22,7 +21,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"
)
Expand All @@ -31,7 +30,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
Expand Down Expand Up @@ -80,9 +79,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):
Expand Down
2 changes: 0 additions & 2 deletions pylint_pytest/checkers/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import sys
from pprint import pprint
from typing import Any, Dict, List
Expand Down
10 changes: 4 additions & 6 deletions tests/base_tester.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

import os
import sys
from abc import ABC
from pprint import pprint
from typing import Any
from typing import Any, Dict, List

import astroid
from pylint.testutils import MessageTest, UnittestLinter
Expand All @@ -25,10 +23,10 @@

class BasePytestTester(ABC):
CHECKER_CLASS = BaseChecker
IMPACTED_CHECKER_CLASSES: list[BaseChecker] = []
IMPACTED_CHECKER_CLASSES: List[BaseChecker] = []
MSG_ID: str
msgs: list[MessageTest] = []
CONFIG: dict[str, Any] = {}
msgs: List[MessageTest] = []
CONFIG: Dict[str, Any] = {}

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/base_tester_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NoMsgIDSubclass(BasePytestTester):
pass


@pytest.mark.parametrize("msg_id", [123, None, ""], ids=lambda msg_id: f"{msg_id=}")
@pytest.mark.parametrize("msg_id", [123, None, ""], ids=lambda x: f"msg_id={x}")
def test_init_subclass_invalid_msg_id_type(msg_id):
with pytest.raises(TypeError):

Expand Down

0 comments on commit b8ce4ad

Please sign in to comment.