Skip to content

Commit 5264b50

Browse files
committed
Use a TypeVar in params.param
1 parent 737eb6d commit 5264b50

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

coincidence/params.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# stdlib
3434
import itertools
3535
import random
36-
from typing import Callable, Collection, Iterable, List, Optional, Sequence, Tuple, Union, cast, overload
36+
from typing import Callable, Collection, Iterable, List, Optional, Sequence, Tuple, TypeVar, Union, cast, overload
3737

3838
# 3rd party
3939
import pytest
@@ -46,6 +46,7 @@
4646

4747
__all__ = ["count", "whitespace_perms", "testing_boolean_values", "param", "parametrized_versions"]
4848

49+
_T = TypeVar("_T")
4950
MarkDecorator.__module__ = "_pytest.mark"
5051

5152

@@ -132,18 +133,18 @@ def param(
132133

133134
@overload
134135
def param(
135-
*values: object,
136+
*values: _T,
136137
marks: Union[MarkDecorator, Collection[Union[MarkDecorator, Mark]]] = (),
137-
key: Optional[Callable[[Tuple[object, ...]], str]], # noqa: A002 # pylint: disable=redefined-builtin
138+
key: Optional[Callable[[Tuple[_T, ...]], str]], # noqa: A002 # pylint: disable=redefined-builtin
138139
) -> ParameterSet: ...
139140

140141

141142
def param(
142-
*values: object,
143+
*values: _T,
143144
marks: Union[MarkDecorator, Collection[Union[MarkDecorator, Mark]]] = (),
144145
id: Optional[str] = None, # noqa: A002 # pylint: disable=redefined-builtin
145146
idx: Optional[int] = None,
146-
key: Optional[Callable[[Tuple[object, ...]], str]] = None,
147+
key: Optional[Callable[[Tuple[_T, ...]], str]] = None,
147148
) -> ParameterSet:
148149
r"""
149150
Specify a parameter in `pytest.mark.parametrize <https://docs.pytest.org/en/stable/parametrize.html>`__

tests/test_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# 3rd party
88
import pytest
99
from _pytest.mark import Mark, MarkDecorator, ParameterSet
10+
from domdf_python_tools.paths import PathPlus
1011
from domdf_python_tools.utils import strtobool
1112

1213
# this package
@@ -79,6 +80,8 @@ def test_param():
7980
with pytest.raises(ValueError, match="'id', 'idx' and 'key' are mutually exclusive."):
8081
param("sqrt(9)", 3, id="√9", idx=0, key=itemgetter(0)) # type: ignore
8182

83+
assert param(PathPlus("code.py"), key=lambda t: t[0].name).id == "code.py"
84+
8285

8386
@no_type_check
8487
def test_parametrized_versions():

0 commit comments

Comments
 (0)