MCPcopy Create free account
hub / github.com/python/mypy / instantiate_generator_class

Function instantiate_generator_class

mypyc/irbuild/generator.py:133–158  ·  view source on GitHub ↗
(builder: IRBuilder)

Source from the content-addressed store, hash-verified

131
132
133def instantiate_generator_class(builder: IRBuilder) -> Value:
134 fitem = builder.fn_info.fitem
135 generator_reg = builder.add(Call(builder.fn_info.generator_class.ir.ctor, [], fitem.line))
136
137 if builder.fn_info.can_merge_generator_and_env_classes():
138 # Set the generator instance to the initial state (zero).
139 zero = Integer(0)
140 builder.add(SetAttr(generator_reg, NEXT_LABEL_ATTR_NAME, zero, fitem.line))
141 else:
142 # Get the current environment register. If the current function is nested, then the
143 # generator class gets instantiated from the callable class' '__call__' method, and hence
144 # we use the callable class' environment register. Otherwise, we use the original
145 # function's environment register.
146 if builder.fn_info.is_nested:
147 curr_env_reg = builder.fn_info.callable_class.curr_env_reg
148 else:
149 curr_env_reg = builder.fn_info.curr_env_reg
150
151 # Set the generator class' environment attribute to point at the environment class
152 # defined in the current scope.
153 builder.add(SetAttr(generator_reg, ENV_ATTR_NAME, curr_env_reg, fitem.line))
154
155 # Set the generator instance's environment to the initial state (zero).
156 zero = Integer(0)
157 builder.add(SetAttr(curr_env_reg, NEXT_LABEL_ATTR_NAME, zero, fitem.line))
158 return generator_reg
159
160
161def setup_generator_class(builder: IRBuilder) -> ClassIR:

Callers 1

gen_generator_funcFunction · 0.85

Calls 5

CallClass · 0.90
IntegerClass · 0.90
SetAttrClass · 0.90
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…