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

Function load_outer_env

mypyc/irbuild/env_class.py:143–168  ·  view source on GitHub ↗

Load the environment class for a given base into a register. Additionally, iterates through all of the SymbolNode and AssignmentTarget instances of the environment at the given index's symtable, and adds those instances to the environment of the current environment. This is done so

(
    builder: IRBuilder, base: Value, outer_env: dict[SymbolNode, SymbolTarget]
)

Source from the content-addressed store, hash-verified

141
142
143def load_outer_env(
144 builder: IRBuilder, base: Value, outer_env: dict[SymbolNode, SymbolTarget]
145) -> Value:
146 """Load the environment class for a given base into a register.
147
148 Additionally, iterates through all of the SymbolNode and
149 AssignmentTarget instances of the environment at the given index's
150 symtable, and adds those instances to the environment of the
151 current environment. This is done so that the current environment
152 can access outer environment variables without having to reload
153 all of the environment registers.
154
155 Returns the register where the environment class was loaded.
156 """
157 env = builder.add(GetAttr(base, ENV_ATTR_NAME, builder.fn_info.fitem.line))
158 assert isinstance(env.type, RInstance), f"{env} must be of type RInstance"
159
160 for symbol, target in outer_env.items():
161 attr_name = symbol.name
162 if isinstance(target, AssignmentTargetAttr):
163 attr_name = target.attr
164 env.type.class_ir.attributes[attr_name] = target.type
165 symbol_target = AssignmentTargetAttr(env, attr_name)
166 builder.add_target(symbol, symbol_target)
167
168 return env
169
170
171def load_outer_envs(builder: IRBuilder, base: ImplicitClass) -> None:

Callers 2

load_outer_envsFunction · 0.85

Calls 6

GetAttrClass · 0.90
isinstanceFunction · 0.85
add_targetMethod · 0.80
addMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…