diff --git a/pyproject.toml b/pyproject.toml index 8605e5bae..634b08cbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,6 +133,7 @@ select = [ "E", # pycodestyle "F", # pyflakes "I", # isort + "PYI", # flake8-pyi "UP", # pyupgrade "RUF", # ruff "W", # pycodestyle diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index b9e095028..dce431c3d 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -598,7 +598,8 @@ if sys.version_info >= (3, 11) or TYPE_CHECKING: else: class CaptureResult( - collections.namedtuple("CaptureResult", ["out", "err"]), Generic[AnyStr] + collections.namedtuple("CaptureResult", ["out", "err"]), # noqa: PYI024 + Generic[AnyStr], ): """The result of :method:`caplog.readouterr() `.""" diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 14717e941..400b38642 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -15,11 +15,6 @@ from typing import Any from typing import Callable from typing import Final from typing import NoReturn -from typing import TypeVar - - -_T = TypeVar("_T") -_S = TypeVar("_S") # fmt: off diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 2fa6fbe37..2d92128fb 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1,10 +1,10 @@ # mypy: allow-untyped-defs -import collections import sys import textwrap from typing import Any from typing import List from typing import MutableSequence +from typing import NamedTuple from typing import Optional import attr @@ -1179,7 +1179,9 @@ class TestAssert_reprcompare_attrsclass: class TestAssert_reprcompare_namedtuple: def test_namedtuple(self) -> None: - NT = collections.namedtuple("NT", ["a", "b"]) + class NT(NamedTuple): + a: Any + b: Any left = NT(1, "b") right = NT(1, "c") @@ -1200,8 +1202,13 @@ class TestAssert_reprcompare_namedtuple: ] def test_comparing_two_different_namedtuple(self) -> None: - NT1 = collections.namedtuple("NT1", ["a", "b"]) - NT2 = collections.namedtuple("NT2", ["a", "b"]) + class NT1(NamedTuple): + a: Any + b: Any + + class NT2(NamedTuple): + a: Any + b: Any left = NT1(1, "b") right = NT2(2, "b") diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 22f041ced..bc457c398 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1,6 +1,5 @@ # mypy: allow-untyped-defs """Terminal reporting of the full testing process.""" -import collections from io import StringIO import os from pathlib import Path @@ -10,6 +9,7 @@ from types import SimpleNamespace from typing import cast from typing import Dict from typing import List +from typing import NamedTuple from typing import Tuple import pluggy @@ -34,7 +34,9 @@ from _pytest.terminal import TerminalReporter import pytest -DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"]) +class DistInfo(NamedTuple): + project_name: str + version: int TRANS_FNMATCH = str.maketrans({"[": "[[]", "]": "[]]"})