MCPcopy Index your code
hub / github.com/python/mypy / run_generator

Function run_generator

mypyc/test-data/fixtures/testutil.py:64–85  ·  view source on GitHub ↗
(gen: Generator[T, V, U],
                  inputs: Optional[List[V]] = None,
                  p: bool = False)

Source from the content-addressed store, hash-verified

62V = TypeVar('V')
63
64def run_generator(gen: Generator[T, V, U],
65 inputs: Optional[List[V]] = None,
66 p: bool = False) -> Tuple[Sequence[T], Union[U, str]]:
67 res: List[T] = []
68 i = -1
69 while True:
70 try:
71 if i >= 0 and inputs:
72 # ... fixtures don't have send
73 val = gen.send(inputs[i]) # type: ignore
74 elif not hasattr(gen, '__next__'): # type: ignore
75 val = gen.send(None) # type: ignore
76 else:
77 val = next(gen)
78 except StopIteration as e:
79 return (tuple(res), e.value)
80 except Exception as e:
81 return (tuple(res), str(e))
82 if p:
83 print(val)
84 res.append(val)
85 i += 1
86
87F = TypeVar('F', bound=Callable)
88

Callers

nothing calls this directly

Calls 6

hasattrFunction · 0.85
nextFunction · 0.85
tupleClass · 0.85
strClass · 0.85
printFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…