Improve docstring and type annotation

This commit is contained in:
Sadra Barikbin 2024-01-07 23:19:19 +03:30
parent ed6c38c490
commit 8361ea4c8c
1 changed files with 7 additions and 6 deletions

View File

@ -15,7 +15,6 @@ from functools import partial
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from typing import Callable from typing import Callable
from typing import cast
from typing import Dict from typing import Dict
from typing import final from typing import final
from typing import Generator from typing import Generator
@ -1190,14 +1189,16 @@ def resolve_values_indices_in_parametersets(
parametersets: Sequence[ParameterSet], parametersets: Sequence[ParameterSet],
) -> List[Tuple[int, ...]]: ) -> List[Tuple[int, ...]]:
"""Resolve indices of the values in parameter sets. The index of a value is determined by """Resolve indices of the values in parameter sets. The index of a value is determined by
where the value first appears in the existing values of the argname. For example, given where the value first appears in the existing values of the argname. In other words, given
``argnames`` and ``parametersets`` below, the result would be: a subset of the cross-product of some ordered sets, it substitues the values in the subset
members with their index in the respective sets. For example, given ``argnames`` and
``parametersets`` below, the result would be:
:: ::
argnames = ["A", "B", "C"] argnames = ["A", "B", "C"]
parametersets = [("a1", "b1", "c1"), ("a1", "b2", "c1"), ("a1", "b3", "c2")] parametersets = [("a1", "b1", "c1"), ("a1", "b2", "c1"), ("a1", "b3", "c2")]
result = [(0, 0, 0), (0, 1, 0), (0, 2, 1)] result = [(0, 0, 0), (0, 1, 0), (0, 2, 1)]
result is used in reordering tests to keep items using the same fixture close together. Result is used in reordering tests to keep items using the same fixture close together.
:param argnames: :param argnames:
Argument names passed to ``metafunc.parametrize()``. Argument names passed to ``metafunc.parametrize()``.
@ -1207,7 +1208,7 @@ def resolve_values_indices_in_parametersets(
:returns: :returns:
List of tuples of indices, each tuple for a parameter set. List of tuples of indices, each tuple for a parameter set.
""" """
indices = [] indices: List[List[int]] = []
argname_value_indices_for_hashable_ones: Dict[str, Dict[object, int]] = defaultdict( argname_value_indices_for_hashable_ones: Dict[str, Dict[object, int]] = defaultdict(
dict dict
) )
@ -1230,7 +1231,7 @@ def resolve_values_indices_in_parametersets(
argname_indices.append(argvalues_count[argname]) argname_indices.append(argvalues_count[argname])
argvalues_count[argname] += 1 argvalues_count[argname] += 1
indices.append(argname_indices) indices.append(argname_indices)
return list(cast(Iterable[Tuple[int]], zip(*indices))) return list(zip(*indices))
# Used for storing artificial fixturedefs for direct parametrization. # Used for storing artificial fixturedefs for direct parametrization.