2
2
Call loop machinery
3
3
"""
4
4
from __future__ import annotations
5
+
5
6
from ._hooks import HookImpl
6
7
from ._result import _raise_wrapfail
7
8
from ._result import HookCallError
8
9
from ._result import Result
10
+
9
11
TYPE_CHECKING = False
10
12
if TYPE_CHECKING :
11
13
from typing import cast
17
19
18
20
# Need to distinguish between old- and new-style hook wrappers.
19
21
# Wrapping one a singleton tuple is the fastest type-safe way I found to do it.
20
- Teardown = Union [
22
+ Teardown = Union [
21
23
Tuple [Generator [None , Result [object ], None ]],
22
24
Generator [None , object , object ],
23
25
]
26
+ else :
27
+
28
+ def cast (t , v ):
29
+ return v
24
30
25
31
26
32
def _multicall (
@@ -57,7 +63,7 @@ def _multicall(
57
63
# If this cast is not valid, a type error is raised below,
58
64
# which is the desired response.
59
65
res = hook_impl .function (* args )
60
- wrapper_gen = cast (Generator [None , Result [object ], None ], res )
66
+ wrapper_gen = cast (" Generator[None, Result[object], None]" , res )
61
67
next (wrapper_gen ) # first yield
62
68
teardowns .append ((wrapper_gen ,))
63
69
except StopIteration :
@@ -67,7 +73,7 @@ def _multicall(
67
73
# If this cast is not valid, a type error is raised below,
68
74
# which is the desired response.
69
75
res = hook_impl .function (* args )
70
- function_gen = cast (Generator [None , object , object ], res )
76
+ function_gen = cast (" Generator[None, object, object]" , res )
71
77
next (function_gen ) # first yield
72
78
teardowns .append (function_gen )
73
79
except StopIteration :
0 commit comments