[flake8-pyi] Add checks for flake8-pyi and fix existing

This commit is contained in:
Pierre Sassoulas 2024-02-02 21:36:20 +01:00
parent 4eb246d4e1
commit e193a263c7
5 changed files with 18 additions and 12 deletions

View File

@ -133,6 +133,7 @@ select = [
"E", # pycodestyle "E", # pycodestyle
"F", # pyflakes "F", # pyflakes
"I", # isort "I", # isort
"PYI", # flake8-pyi
"UP", # pyupgrade "UP", # pyupgrade
"RUF", # ruff "RUF", # ruff
"W", # pycodestyle "W", # pycodestyle

View File

@ -598,7 +598,8 @@ if sys.version_info >= (3, 11) or TYPE_CHECKING:
else: else:
class CaptureResult( class CaptureResult(
collections.namedtuple("CaptureResult", ["out", "err"]), Generic[AnyStr] collections.namedtuple("CaptureResult", ["out", "err"]), # noqa: PYI024
Generic[AnyStr],
): ):
"""The result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.""" """The result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`."""

View File

@ -15,11 +15,6 @@ from typing import Any
from typing import Callable from typing import Callable
from typing import Final from typing import Final
from typing import NoReturn from typing import NoReturn
from typing import TypeVar
_T = TypeVar("_T")
_S = TypeVar("_S")
# fmt: off # fmt: off

View File

@ -1,10 +1,10 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import collections
import sys import sys
import textwrap import textwrap
from typing import Any from typing import Any
from typing import List from typing import List
from typing import MutableSequence from typing import MutableSequence
from typing import NamedTuple
from typing import Optional from typing import Optional
import attr import attr
@ -1179,7 +1179,9 @@ class TestAssert_reprcompare_attrsclass:
class TestAssert_reprcompare_namedtuple: class TestAssert_reprcompare_namedtuple:
def test_namedtuple(self) -> None: def test_namedtuple(self) -> None:
NT = collections.namedtuple("NT", ["a", "b"]) class NT(NamedTuple):
a: Any
b: Any
left = NT(1, "b") left = NT(1, "b")
right = NT(1, "c") right = NT(1, "c")
@ -1200,8 +1202,13 @@ class TestAssert_reprcompare_namedtuple:
] ]
def test_comparing_two_different_namedtuple(self) -> None: def test_comparing_two_different_namedtuple(self) -> None:
NT1 = collections.namedtuple("NT1", ["a", "b"]) class NT1(NamedTuple):
NT2 = collections.namedtuple("NT2", ["a", "b"]) a: Any
b: Any
class NT2(NamedTuple):
a: Any
b: Any
left = NT1(1, "b") left = NT1(1, "b")
right = NT2(2, "b") right = NT2(2, "b")

View File

@ -1,6 +1,5 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
"""Terminal reporting of the full testing process.""" """Terminal reporting of the full testing process."""
import collections
from io import StringIO from io import StringIO
import os import os
from pathlib import Path from pathlib import Path
@ -10,6 +9,7 @@ from types import SimpleNamespace
from typing import cast from typing import cast
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import NamedTuple
from typing import Tuple from typing import Tuple
import pluggy import pluggy
@ -34,7 +34,9 @@ from _pytest.terminal import TerminalReporter
import pytest import pytest
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"]) class DistInfo(NamedTuple):
project_name: str
version: int
TRANS_FNMATCH = str.maketrans({"[": "[[]", "]": "[]]"}) TRANS_FNMATCH = str.maketrans({"[": "[[]", "]": "[]]"})