diff options
| author | robot-piglet <[email protected]> | 2025-07-27 14:17:18 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-07-27 14:28:59 +0300 |
| commit | e74d928d0f6c56f02ed72685ff569160f049174a (patch) | |
| tree | e5ee17ec64fb59e5be233dee5ec40e23d2b3a324 /contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures | |
| parent | 0c4a0ee940a18305115568ee3d2831e0fbbe04b1 (diff) | |
Intermediate changes
commit_hash:f52a543082ebbfceb217aa858510084bd9a96c06
Diffstat (limited to 'contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures')
5 files changed, 31 insertions, 20 deletions
diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture.py index 28fc00d5299..986ba2639bf 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture.py @@ -1,8 +1,11 @@ +from __future__ import annotations + from dataclasses import dataclass from operator import attrgetter -from typing import Optional +from typing import TYPE_CHECKING -import pytest +if TYPE_CHECKING: + import pytest @dataclass @@ -13,7 +16,7 @@ class LazyFixtureWrapper: def fixture_name(self) -> str: return self.name.split(".", maxsplit=1)[0] - def _get_attr(self, fixture) -> Optional[str]: + def _get_attr(self, fixture) -> str | None: splitted = self.name.split(".", maxsplit=1) if len(splitted) == 1: return fixture diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py index 3cea3a95501..4e371763f7d 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/lazy_fixture_callable.py @@ -1,17 +1,20 @@ -from inspect import isfunction -from typing import Callable, Optional, Union +from __future__ import annotations -import pytest +from inspect import isfunction +from typing import TYPE_CHECKING, Callable from .lazy_fixture import LazyFixtureWrapper +if TYPE_CHECKING: + import pytest + class LazyFixtureCallableWrapper(LazyFixtureWrapper): - _func: Optional[Callable] + _func: Callable | None args: tuple kwargs: dict - def __init__(self, callable_or_name: Union[Callable, str], *args, **kwargs): + def __init__(self, callable_or_name: Callable | str, *args, **kwargs): if callable(callable_or_name): self._func = callable_or_name self.name = ( @@ -27,10 +30,12 @@ class LazyFixtureCallableWrapper(LazyFixtureWrapper): func = self._func if func is None: func = self.load_fixture(request) - assert callable(func) + if not callable(func): + msg = "Passed fixture is not callable" + raise TypeError(msg) return func -def lfc(name: Union[Callable, str], *args, **kwargs) -> LazyFixtureCallableWrapper: +def lfc(name: Callable | str, *args, **kwargs) -> LazyFixtureCallableWrapper: """lfc is a lazy fixture callable.""" return LazyFixtureCallableWrapper(name, *args, **kwargs) diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py index d2d39ff4f80..75156ac3a63 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py @@ -13,9 +13,9 @@ def load_lazy_fixtures(value, request: pytest.FixtureRequest): if isinstance(value, LazyFixtureWrapper): return value.load_fixture(request) # we need to check exact type - if type(value) is dict: # noqa: E721 - return {load_lazy_fixtures(key, request): load_lazy_fixtures(value, request) for key, value in value.items()} + if type(value) is dict: + return {load_lazy_fixtures(key, request): load_lazy_fixtures(val, request) for key, val in value.items()} # we need to check exact type - elif type(value) in {list, tuple, set}: - return type(value)([load_lazy_fixtures(value, request) for value in value]) + if type(value) in {list, tuple, set}: + return type(value)(load_lazy_fixtures(val, request) for val in value) return value diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py index f557e4da9ca..699400c084b 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/normalizer.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import copy -from typing import Any, Dict, Iterable, Iterator, List, Tuple +from typing import Any, Iterable, Iterator import pytest @@ -7,7 +9,7 @@ from .lazy_fixture import LazyFixtureWrapper from .lazy_fixture_callable import LazyFixtureCallableWrapper -def _get_fixturenames_closure_and_arg2fixturedefs(fm, metafunc, value) -> Tuple[List[str], Dict[str, Any]]: +def _get_fixturenames_closure_and_arg2fixturedefs(fm, metafunc, value) -> tuple[list[str], dict[str, Any]]: if isinstance(value, LazyFixtureCallableWrapper): extra_fixturenames_args, arg2fixturedefs_args = _get_fixturenames_closure_and_arg2fixturedefs( fm, @@ -33,7 +35,7 @@ def _get_fixturenames_closure_and_arg2fixturedefs(fm, metafunc, value) -> Tuple[ return fixturenames_closure, arg2fixturedefs extra_fixturenames, arg2fixturedefs = [], {} # we need to check exact type - if type(value) is dict: # noqa: E721 + if type(value) is dict: value = list(value.values()) # we need to check exact type if type(value) in {list, tuple, set}: @@ -60,7 +62,7 @@ def _copy_metafunc(metafunc): return copied -def _uniq(values: "Iterable[str]") -> "Iterator[str]": +def _uniq(values: Iterable[str]) -> Iterator[str]: seen = set() for value in values: if value not in seen: diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py index f3475e199c8..0c43a845986 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py @@ -6,15 +6,16 @@ from .normalizer import normalize_metafunc_calls @pytest.hookimpl(tryfirst=True) -def pytest_fixture_setup(fixturedef, request): +def pytest_fixture_setup(fixturedef, request): # noqa: ARG001 val = getattr(request, "param", None) if val is not None: request.param = load_lazy_fixtures(val, request) -def pytest_make_parametrize_id(config, val, argname): +def pytest_make_parametrize_id(config, val, argname): # noqa: ARG001 if isinstance(val, LazyFixtureWrapper): return val.name + return None @pytest.hookimpl(hookwrapper=True) |
