Skip to content

Commit 2383167

Browse files
smarieSylvain MARIE
andauthored
Fixed type hint errors detected by pyright. Fixed #270 (#271)
Co-authored-by: Sylvain MARIE <[email protected]>
1 parent def94ce commit 2383167

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 3.6.12 - type hint fix
4+
5+
- Fixed type hint errors detected by `pyright`. Fixed [#270](https://github.com/smarie/python-pytest-cases/issues/270)
6+
37
### 3.6.11 - bugfix for pytest-xdist and `get_all_cases` API improvement
48

59
- `get_all_cases` can now be called without `parametrization_target` (defaulting to the caller module), and with an explicit module object. Fixed [#258](https://github.com/smarie/python-pytest-cases/issues/258). PR [#260](https://github.com/smarie/python-pytest-cases/pull/260) by [@eddiebergman](https://github.com/eddiebergman).

src/pytest_cases/fixture_parametrize_plus.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
from collections import Iterable
1818

1919
try:
20-
from typing import Union, Callable, List, Any, Sequence, Optional, Type, Tuple # noqa
20+
from typing import Union, Callable, List, Any, Sequence, Optional, Type, Tuple, TypeVar # noqa
2121
from types import ModuleType # noqa
22+
23+
T = TypeVar('T', bound=Union[Type, Callable])
2224
except ImportError:
2325
pass
2426

@@ -624,6 +626,7 @@ def parametrize(argnames=None, # type: Union[str, Tuple[str], List[str]]
624626
hook=None, # type: Callable[[Callable], Callable]
625627
debug=False, # type: bool
626628
**args):
629+
# type: (...) -> Callable[[T], T]
627630
"""
628631
Equivalent to `@pytest.mark.parametrize` but also supports
629632
@@ -733,6 +736,7 @@ def _parametrize_plus(argnames=None, # type: Union[str, Tuple[str], List[str]]
733736
hook=None, # type: Callable[[Callable], Callable]
734737
debug=False, # type: bool
735738
**args):
739+
# type: (...) -> Tuple[Callable[[T], T], bool]
736740
"""
737741
738742
:return: a tuple (decorator, needs_inject) where needs_inject is True if decorator has signature (f, host)
@@ -790,6 +794,7 @@ def _make_ids(**args):
790794
else:
791795
# wrap the decorator to check if the test function has the parameters as arguments
792796
def _apply(test_func):
797+
# type: (...) -> Callable[[T], T]
793798
if not safe_isclass(test_func):
794799
# a Function: raise a proper error message if improper use
795800
s = signature(test_func)
@@ -923,6 +928,7 @@ def _create_fixture_ref_product(fh, union_name, i, fixture_ref_positions, test_f
923928

924929
# Then create the decorator per se
925930
def parametrize_plus_decorate(test_func, fixtures_dest):
931+
# type: (...) -> Callable[[T], T]
926932
"""
927933
A decorator that wraps the test function so that instead of receiving the parameter names, it receives the
928934
new fixture. All other decorations are unchanged.

0 commit comments

Comments
 (0)