Skip to content

Commit

Permalink
fixup: pre-commit green again
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Jun 20, 2024
1 parent 2b16e7b commit e60afd5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Testing",
"Topic :: Utilities",
Expand Down
4 changes: 2 additions & 2 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def __init__(
rawentry: TracebackType,
repr_style: Literal["short", "long"] | None = None,
) -> None:
self._rawentry: "Final" = rawentry
self._repr_style: "Final" = repr_style
self._rawentry: Final = rawentry
self._repr_style: Final = repr_style

def with_repr_style(
self, repr_style: Literal["short", "long"] | None
Expand Down
10 changes: 4 additions & 6 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from .argparsing import Argument
from .argparsing import Parser
from _pytest._code.code import _TracebackStyle
from _pytest.cacheprovider import Cache
from _pytest.terminal import TerminalReporter


Expand Down Expand Up @@ -1009,6 +1010,8 @@ def __init__(
object.__setattr__(self, "plugins", plugins)
object.__setattr__(self, "dir", dir)

cache: Cache

class ArgsSource(enum.Enum):
"""Indicates the source of the test arguments.
Expand Down Expand Up @@ -1084,11 +1087,6 @@ def __init__(
self.args_source = Config.ArgsSource.ARGS
self.args: list[str] = []

if TYPE_CHECKING:
from _pytest.cacheprovider import Cache

self.cache: Optional[Cache] = None

@property
def rootpath(self) -> pathlib.Path:
"""The path to the :ref:`rootdir <rootdir>`.
Expand Down Expand Up @@ -1906,7 +1904,7 @@ def parse_warning_filter(
parts.append("")
action_, message, category_, module, lineno_ = (s.strip() for s in parts)
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:
raise UsageError(error_template.format(error=str(e))) from None
try:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def setup(self) -> None:
def runtest(self) -> None:
_check_all_skipped(self.dtest)
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
# doctest expects.
self.runner.run(self.dtest, out=failures) # type: ignore[arg-type]
Expand Down
26 changes: 14 additions & 12 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Any
from typing import Callable
from typing import cast
from typing import Dict
from typing import Final
from typing import final
from typing import Generator
Expand Down Expand Up @@ -205,7 +204,7 @@ def get_parametrized_fixture_keys(


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[
Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]
] = {}
Expand All @@ -226,8 +225,8 @@ def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]:

def fix_cache_order(
item: nodes.Item,
argkeys_cache: Dict[Scope, Dict[nodes.Item, Dict[FixtureArgKey, None]]],
items_by_argkey: Dict[Scope, Dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
argkeys_cache: dict[Scope, dict[nodes.Item, dict[FixtureArgKey, None]]],
items_by_argkey: dict[Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
) -> None:
for scope in HIGH_SCOPES:
scoped_items_by_argkey = items_by_argkey[scope]
Expand All @@ -237,20 +236,20 @@ def fix_cache_order(


def reorder_items_atscope(
items: Dict[nodes.Item, None],
argkeys_cache: Dict[Scope, Dict[nodes.Item, Dict[FixtureArgKey, None]]],
items_by_argkey: Dict[Scope, Dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
items: dict[nodes.Item, None],
argkeys_cache: dict[Scope, dict[nodes.Item, dict[FixtureArgKey, None]]],
items_by_argkey: dict[Scope, dict[FixtureArgKey, OrderedDict[nodes.Item, None]]],
scope: Scope,
) -> Dict[nodes.Item, None]:
) -> dict[nodes.Item, None]:
if scope is Scope.Function or len(items) < 3:
return items
ignore: Set[Optional[FixtureArgKey]] = set()
ignore: set[FixtureArgKey | None] = set()
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_argkeys_cache = argkeys_cache[scope]
while items_deque:
no_argkey_group: Dict[nodes.Item, None] = {}
no_argkey_group: dict[nodes.Item, None] = {}
slicing_argkey = None
while items_deque:
item = items_deque.popleft()
Expand Down Expand Up @@ -1615,7 +1614,10 @@ def _register_fixture(
name: str,
func: _FixtureFunc[object],
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,
ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
autouse: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def __init__(self) -> None:
# Node's finalizers.
list[Callable[[], object]],
# Node's exception and original traceback, if its setup raised.
tuple[OutcomeException | Exception | None] | None,
OutcomeException | Exception | None,
],
] = {}

Expand Down
6 changes: 6 additions & 0 deletions src/_pytest/stepwise.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from _pytest import nodes
from _pytest.config import Config
from _pytest.config.argparsing import Parser
Expand All @@ -8,6 +10,10 @@
import pytest


if TYPE_CHECKING:
from _pytest.cacheprovider import Cache


STEPWISE_CACHE_DIR = "cache/stepwise"


Expand Down
8 changes: 4 additions & 4 deletions src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def teardown(self) -> None:
def startTest(self, testcase: unittest.TestCase) -> None:
pass

def _addexcinfo(self, rawexcinfo: "_SysExcInfoType") -> None:
def _addexcinfo(self, rawexcinfo: _SysExcInfoType) -> None:
# Unwrap potential exception info (see twisted trial support below).
rawexcinfo = getattr(rawexcinfo, "_rawexcinfo", rawexcinfo)
try:
Expand Down Expand Up @@ -258,7 +258,7 @@ def _addexcinfo(self, rawexcinfo: "_SysExcInfoType") -> None:
self.__dict__.setdefault("_excinfo", []).append(excinfo)

def addError(
self, testcase: unittest.TestCase, rawexcinfo: "_SysExcInfoType"
self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType
) -> None:
try:
if isinstance(rawexcinfo[1], exit.Exception):
Expand All @@ -268,7 +268,7 @@ def addError(
self._addexcinfo(rawexcinfo)

def addFailure(
self, testcase: unittest.TestCase, rawexcinfo: "_SysExcInfoType"
self, testcase: unittest.TestCase, rawexcinfo: _SysExcInfoType
) -> None:
self._addexcinfo(rawexcinfo)

Expand All @@ -281,7 +281,7 @@ def addSkip(self, testcase: unittest.TestCase, reason: str) -> None:
def addExpectedFailure(
self,
testcase: unittest.TestCase,
rawexcinfo: "_SysExcInfoType",
rawexcinfo: _SysExcInfoType,
reason: str = "",
) -> None:
try:
Expand Down

0 comments on commit e60afd5

Please sign in to comment.