summaryrefslogtreecommitdiff
path: root/src/_pytest/runner.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-08-01 13:06:13 +0300
committerRan Benita <ran@unusedvar.com>2020-08-01 20:39:15 +0300
commitbe656dd4e4444acd9600660fc3b6bf3896067dbe (patch)
treeea7998a38648f2397a818ad8f9948d2048e3b631 /src/_pytest/runner.py
parent49827adcb9256c9c9c06a25729421dcc3c385edc (diff)
downloadpytest-be656dd4e4444acd9600660fc3b6bf3896067dbe.tar.gz
typing: set disallow_any_generics
This prevents referring to a generic type without filling in its generic type parameters. The FixtureDef typing might need some more refining in the future.
Diffstat (limited to 'src/_pytest/runner.py')
-rw-r--r--src/_pytest/runner.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py
index 289d676d6..4923406b9 100644
--- a/src/_pytest/runner.py
+++ b/src/_pytest/runner.py
@@ -213,7 +213,7 @@ def call_and_report(
return report
-def check_interactive_exception(call: "CallInfo", report: BaseReport) -> bool:
+def check_interactive_exception(call: "CallInfo[object]", report: BaseReport) -> bool:
"""Check whether the call raised an exception that should be reported as
interactive."""
if call.excinfo is None:
@@ -247,11 +247,11 @@ def call_runtest_hook(
)
-_T = TypeVar("_T")
+TResult = TypeVar("TResult", covariant=True)
@attr.s(repr=False)
-class CallInfo(Generic[_T]):
+class CallInfo(Generic[TResult]):
"""Result/Exception info a function invocation.
:param T result:
@@ -269,7 +269,7 @@ class CallInfo(Generic[_T]):
The context of invocation: "setup", "call", "teardown", ...
"""
- _result = attr.ib(type="Optional[_T]")
+ _result = attr.ib(type="Optional[TResult]")
excinfo = attr.ib(type=Optional[ExceptionInfo[BaseException]])
start = attr.ib(type=float)
stop = attr.ib(type=float)
@@ -277,26 +277,26 @@ class CallInfo(Generic[_T]):
when = attr.ib(type="Literal['collect', 'setup', 'call', 'teardown']")
@property
- def result(self) -> _T:
+ def result(self) -> TResult:
if self.excinfo is not None:
raise AttributeError("{!r} has no valid result".format(self))
# The cast is safe because an exception wasn't raised, hence
# _result has the expected function return type (which may be
# None, that's why a cast and not an assert).
- return cast(_T, self._result)
+ return cast(TResult, self._result)
@classmethod
def from_call(
cls,
- func: "Callable[[], _T]",
+ func: "Callable[[], TResult]",
when: "Literal['collect', 'setup', 'call', 'teardown']",
reraise: "Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]]" = None,
- ) -> "CallInfo[_T]":
+ ) -> "CallInfo[TResult]":
excinfo = None
start = timing.time()
precise_start = timing.perf_counter()
try:
- result = func() # type: Optional[_T]
+ result = func() # type: Optional[TResult]
except BaseException:
excinfo = ExceptionInfo.from_current()
if reraise is not None and isinstance(excinfo.value, reraise):