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

Function mark_attr_initialization_ops

mypyc/analysis/attrdefined.py:264–280  ·  view source on GitHub ↗

Tag all SetAttr ops in the basic blocks that initialize attributes. Initialization ops assume that the previous attribute value is the error value, so there's no need to decref or check for definedness.

(
    blocks: list[BasicBlock],
    self_reg: Register,
    maybe_defined: AnalysisResult[str],
    dirty: AnalysisResult[None],
)

Source from the content-addressed store, hash-verified

262
263
264def mark_attr_initialization_ops(
265 blocks: list[BasicBlock],
266 self_reg: Register,
267 maybe_defined: AnalysisResult[str],
268 dirty: AnalysisResult[None],
269) -> None:
270 """Tag all SetAttr ops in the basic blocks that initialize attributes.
271
272 Initialization ops assume that the previous attribute value is the error value,
273 so there's no need to decref or check for definedness.
274 """
275 for block in blocks:
276 for i, op in enumerate(block.ops):
277 if isinstance(op, SetAttr) and op.obj is self_reg:
278 attr = op.attr
279 if attr not in maybe_defined.before[block, i] and not dirty.after[block, i]:
280 op.mark_as_initializer()
281
282
283GenAndKill = tuple[set[str], set[str]]

Callers 1

Calls 3

enumerateFunction · 0.85
isinstanceFunction · 0.85
mark_as_initializerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…