diff --git a/docs/changelog.md b/docs/changelog.md index 439d93ba..74d02281 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +### 3.6.12 - type hint fix + + - Fixed type hint errors detected by `pyright`. Fixed [#270](https://github.com/smarie/python-pytest-cases/issues/270) + ### 3.6.11 - bugfix for pytest-xdist and `get_all_cases` API improvement - `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). diff --git a/src/pytest_cases/fixture_parametrize_plus.py b/src/pytest_cases/fixture_parametrize_plus.py index 800dd1e0..cd155d7b 100644 --- a/src/pytest_cases/fixture_parametrize_plus.py +++ b/src/pytest_cases/fixture_parametrize_plus.py @@ -17,8 +17,10 @@ from collections import Iterable try: - from typing import Union, Callable, List, Any, Sequence, Optional, Type, Tuple # noqa + from typing import Union, Callable, List, Any, Sequence, Optional, Type, Tuple, TypeVar # noqa from types import ModuleType # noqa + + T = TypeVar('T', bound=Union[Type, Callable]) except ImportError: pass @@ -624,6 +626,7 @@ def parametrize(argnames=None, # type: Union[str, Tuple[str], List[str]] hook=None, # type: Callable[[Callable], Callable] debug=False, # type: bool **args): + # type: (...) -> Callable[[T], T] """ Equivalent to `@pytest.mark.parametrize` but also supports @@ -733,6 +736,7 @@ def _parametrize_plus(argnames=None, # type: Union[str, Tuple[str], List[str]] hook=None, # type: Callable[[Callable], Callable] debug=False, # type: bool **args): + # type: (...) -> Tuple[Callable[[T], T], bool] """ :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): else: # wrap the decorator to check if the test function has the parameters as arguments def _apply(test_func): + # type: (...) -> Callable[[T], T] if not safe_isclass(test_func): # a Function: raise a proper error message if improper use s = signature(test_func) @@ -923,6 +928,7 @@ def _create_fixture_ref_product(fh, union_name, i, fixture_ref_positions, test_f # Then create the decorator per se def parametrize_plus_decorate(test_func, fixtures_dest): + # type: (...) -> Callable[[T], T] """ A decorator that wraps the test function so that instead of receiving the parameter names, it receives the new fixture. All other decorations are unchanged.