fixup: pre-commit green again

This commit is contained in:
Ronny Pfannschmidt 2024-06-20 15:44:35 +02:00
parent 2b16e7b138
commit e60afd5af2
8 changed files with 33 additions and 26 deletions

View File

@ -31,6 +31,7 @@ classifiers = [
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing", "Topic :: Software Development :: Testing",
"Topic :: Utilities", "Topic :: Utilities",

View File

@ -200,8 +200,8 @@ class TracebackEntry:
rawentry: TracebackType, rawentry: TracebackType,
repr_style: Literal["short", "long"] | None = None, repr_style: Literal["short", "long"] | None = None,
) -> None: ) -> None:
self._rawentry: "Final" = rawentry self._rawentry: Final = rawentry
self._repr_style: "Final" = repr_style self._repr_style: Final = repr_style
def with_repr_style( def with_repr_style(
self, repr_style: Literal["short", "long"] | None self, repr_style: Literal["short", "long"] | None

View File

@ -70,6 +70,7 @@ if TYPE_CHECKING:
from .argparsing import Argument from .argparsing import Argument
from .argparsing import Parser from .argparsing import Parser
from _pytest._code.code import _TracebackStyle from _pytest._code.code import _TracebackStyle
from _pytest.cacheprovider import Cache
from _pytest.terminal import TerminalReporter from _pytest.terminal import TerminalReporter
@ -1009,6 +1010,8 @@ class Config:
object.__setattr__(self, "plugins", plugins) object.__setattr__(self, "plugins", plugins)
object.__setattr__(self, "dir", dir) object.__setattr__(self, "dir", dir)
cache: Cache
class ArgsSource(enum.Enum): class ArgsSource(enum.Enum):
"""Indicates the source of the test arguments. """Indicates the source of the test arguments.
@ -1084,11 +1087,6 @@ class Config:
self.args_source = Config.ArgsSource.ARGS self.args_source = Config.ArgsSource.ARGS
self.args: list[str] = [] self.args: list[str] = []
if TYPE_CHECKING:
from _pytest.cacheprovider import Cache
self.cache: Optional[Cache] = None
@property @property
def rootpath(self) -> pathlib.Path: def rootpath(self) -> pathlib.Path:
"""The path to the :ref:`rootdir <rootdir>`. """The path to the :ref:`rootdir <rootdir>`.
@ -1906,7 +1904,7 @@ def parse_warning_filter(
parts.append("") parts.append("")
action_, message, category_, module, lineno_ = (s.strip() for s in parts) action_, message, category_, module, lineno_ = (s.strip() for s in parts)
try: try:
action: "warnings._ActionKind" = warnings._getaction(action_) # type: ignore[attr-defined] action: warnings._ActionKind = warnings._getaction(action_) # type: ignore[attr-defined]
except warnings._OptionError as e: except warnings._OptionError as e:
raise UsageError(error_template.format(error=str(e))) from None raise UsageError(error_template.format(error=str(e))) from None
try: try:

View File

@ -294,7 +294,7 @@ class DoctestItem(Item):
def runtest(self) -> None: def runtest(self) -> None:
_check_all_skipped(self.dtest) _check_all_skipped(self.dtest)
self._disable_output_capturing_for_darwin() self._disable_output_capturing_for_darwin()
failures: list["doctest.DocTestFailure"] = [] failures: list[doctest.DocTestFailure] = []
# Type ignored because we change the type of `out` from what # Type ignored because we change the type of `out` from what
# doctest expects. # doctest expects.
self.runner.run(self.dtest, out=failures) # type: ignore[arg-type] self.runner.run(self.dtest, out=failures) # type: ignore[arg-type]

View File

@ -14,7 +14,6 @@ from typing import AbstractSet
from typing import Any from typing import Any
from typing import Callable from typing import Callable
from typing import cast from typing import cast
from typing import Dict
from typing import Final from typing import Final
from typing import final from typing import final
from typing import Generator from typing import Generator
@ -205,7 +204,7 @@ def get_parametrized_fixture_keys(
def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]: def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]:
argkeys_cache: dict[Scope, dict[nodes.Item, Dict[FixtureArgKey, None]]] = {} argkeys_cache: dict[Scope, dict[nodes.Item, dict[FixtureArgKey, None]]] = {}
items_by_argkey: dict[ items_by_argkey: dict[
Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]] Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]
] = {} ] = {}
@ -226,8 +225,8 @@ def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]:
def fix_cache_order( def fix_cache_order(
item: nodes.Item, item: nodes.Item,
argkeys_cache: Dict[Scope, Dict[nodes.Item, Dict[FixtureArgKey, None]]], argkeys_cache: dict[Scope, dict[nodes.Item, dict[FixtureArgKey, None]]],
items_by_argkey: Dict[Scope, Dict[FixtureArgKey, OrderedDict[nodes.Item, None]]], items_by_argkey: dict[Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
) -> None: ) -> None:
for scope in HIGH_SCOPES: for scope in HIGH_SCOPES:
scoped_items_by_argkey = items_by_argkey[scope] scoped_items_by_argkey = items_by_argkey[scope]
@ -237,20 +236,20 @@ def fix_cache_order(
def reorder_items_atscope( def reorder_items_atscope(
items: Dict[nodes.Item, None], items: dict[nodes.Item, None],
argkeys_cache: Dict[Scope, Dict[nodes.Item, Dict[FixtureArgKey, None]]], argkeys_cache: dict[Scope, dict[nodes.Item, dict[FixtureArgKey, None]]],
items_by_argkey: Dict[Scope, Dict[FixtureArgKey, OrderedDict[nodes.Item, None]]], items_by_argkey: dict[Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
scope: Scope, scope: Scope,
) -> Dict[nodes.Item, None]: ) -> dict[nodes.Item, None]:
if scope is Scope.Function or len(items) < 3: if scope is Scope.Function or len(items) < 3:
return items return items
ignore: Set[Optional[FixtureArgKey]] = set() ignore: set[FixtureArgKey | None] = set()
items_deque = deque(items) items_deque = deque(items)
items_done: Dict[nodes.Item, None] = {} items_done: dict[nodes.Item, None] = {}
scoped_items_by_argkey = items_by_argkey[scope] scoped_items_by_argkey = items_by_argkey[scope]
scoped_argkeys_cache = argkeys_cache[scope] scoped_argkeys_cache = argkeys_cache[scope]
while items_deque: while items_deque:
no_argkey_group: Dict[nodes.Item, None] = {} no_argkey_group: dict[nodes.Item, None] = {}
slicing_argkey = None slicing_argkey = None
while items_deque: while items_deque:
item = items_deque.popleft() item = items_deque.popleft()
@ -1615,7 +1614,10 @@ class FixtureManager:
name: str, name: str,
func: _FixtureFunc[object], func: _FixtureFunc[object],
nodeid: str | None, nodeid: str | None,
scope: Scope | _ScopeName | Callable[[str, Config], _ScopeName] | None = "function", scope: Scope
| _ScopeName
| Callable[[str, Config], _ScopeName]
| None = "function",
params: Sequence[object] | None = None, params: Sequence[object] | None = None,
ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
autouse: bool = False, autouse: bool = False,

View File

@ -486,7 +486,7 @@ class SetupState:
# Node's finalizers. # Node's finalizers.
list[Callable[[], object]], list[Callable[[], object]],
# Node's exception and original traceback, if its setup raised. # Node's exception and original traceback, if its setup raised.
tuple[OutcomeException | Exception | None] | None, OutcomeException | Exception | None,
], ],
] = {} ] = {}

View File

@ -1,5 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING
from _pytest import nodes from _pytest import nodes
from _pytest.config import Config from _pytest.config import Config
from _pytest.config.argparsing import Parser from _pytest.config.argparsing import Parser
@ -8,6 +10,10 @@ from _pytest.reports import TestReport
import pytest import pytest
if TYPE_CHECKING:
from _pytest.cacheprovider import Cache
STEPWISE_CACHE_DIR = "cache/stepwise" STEPWISE_CACHE_DIR = "cache/stepwise"

View File

@ -222,7 +222,7 @@ class TestCaseFunction(Function):
def startTest(self, testcase: unittest.TestCase) -> None: def startTest(self, testcase: unittest.TestCase) -> None:
pass pass
def _addexcinfo(self, rawexcinfo: "_SysExcInfoType") -> None: def _addexcinfo(self, rawexcinfo: _SysExcInfoType) -> None:
# Unwrap potential exception info (see twisted trial support below). # Unwrap potential exception info (see twisted trial support below).
rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo) rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo)
try: try:
@ -258,7 +258,7 @@ class TestCaseFunction(Function):
self.__dict__.setdefault("_excinfo", []).append(excinfo) self.__dict__.setdefault("_excinfo", []).append(excinfo)
def addError( def addError(
self, testcase: unittest.TestCase, rawexcinfo: "_SysExcInfoType" self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType
) -> None: ) -> None:
try: try:
if isinstance(rawexcinfo[1], exit.Exception): if isinstance(rawexcinfo[1], exit.Exception):
@ -268,7 +268,7 @@ class TestCaseFunction(Function):
self._addexcinfo(rawexcinfo) self._addexcinfo(rawexcinfo)
def addFailure( def addFailure(
self, testcase: unittest.TestCase, rawexcinfo: "_SysExcInfoType" self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType
) -> None: ) -> None:
self._addexcinfo(rawexcinfo) self._addexcinfo(rawexcinfo)
@ -281,7 +281,7 @@ class TestCaseFunction(Function):
def addExpectedFailure( def addExpectedFailure(
self, self,
testcase: unittest.TestCase, testcase: unittest.TestCase,
rawexcinfo: "_SysExcInfoType", rawexcinfo: _SysExcInfoType,
reason: str = "", reason: str = "",
) -> None: ) -> None:
try: try: