|
17 | 17 | from collections import Iterable |
18 | 18 |
|
19 | 19 | 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 |
21 | 21 | from types import ModuleType # noqa |
| 22 | + |
| 23 | + T = TypeVar('T', bound=Union[Type, Callable]) |
22 | 24 | except ImportError: |
23 | 25 | pass |
24 | 26 |
|
@@ -624,6 +626,7 @@ def parametrize(argnames=None, # type: Union[str, Tuple[str], List[str]] |
624 | 626 | hook=None, # type: Callable[[Callable], Callable] |
625 | 627 | debug=False, # type: bool |
626 | 628 | **args): |
| 629 | + # type: (...) -> Callable[[T], T] |
627 | 630 | """ |
628 | 631 | Equivalent to `@pytest.mark.parametrize` but also supports |
629 | 632 |
|
@@ -733,6 +736,7 @@ def _parametrize_plus(argnames=None, # type: Union[str, Tuple[str], List[str]] |
733 | 736 | hook=None, # type: Callable[[Callable], Callable] |
734 | 737 | debug=False, # type: bool |
735 | 738 | **args): |
| 739 | + # type: (...) -> Tuple[Callable[[T], T], bool] |
736 | 740 | """ |
737 | 741 |
|
738 | 742 | :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): |
790 | 794 | else: |
791 | 795 | # wrap the decorator to check if the test function has the parameters as arguments |
792 | 796 | def _apply(test_func): |
| 797 | + # type: (...) -> Callable[[T], T] |
793 | 798 | if not safe_isclass(test_func): |
794 | 799 | # a Function: raise a proper error message if improper use |
795 | 800 | s = signature(test_func) |
@@ -923,6 +928,7 @@ def _create_fixture_ref_product(fh, union_name, i, fixture_ref_positions, test_f |
923 | 928 |
|
924 | 929 | # Then create the decorator per se |
925 | 930 | def parametrize_plus_decorate(test_func, fixtures_dest): |
| 931 | + # type: (...) -> Callable[[T], T] |
926 | 932 | """ |
927 | 933 | A decorator that wraps the test function so that instead of receiving the parameter names, it receives the |
928 | 934 | new fixture. All other decorations are unchanged. |
|
0 commit comments