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

Function find_sometimes_defined_attributes

mypyc/analysis/attrdefined.py:242–261  ·  view source on GitHub ↗

Find attributes that are sometimes initialized in some basic blocks.

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

Source from the content-addressed store, hash-verified

240
241
242def find_sometimes_defined_attributes(
243 blocks: list[BasicBlock],
244 self_reg: Register,
245 maybe_defined: AnalysisResult[str],
246 dirty: AnalysisResult[None],
247) -> set[str]:
248 """Find attributes that are sometimes initialized in some basic blocks."""
249 attrs: set[str] = set()
250 for block in blocks:
251 for i, op in enumerate(block.ops):
252 # Only look at possibly defined attributes at exits.
253 if dirty.after[block, i]:
254 if not dirty.before[block, i]:
255 attrs = attrs | maybe_defined.after[block, i]
256 break
257 if isinstance(op, ControlOp):
258 for target in op.targets():
259 if not dirty.after[block, i] and dirty.before[target, 0]:
260 attrs = attrs | maybe_defined.after[target, 0]
261 return attrs
262
263
264def mark_attr_initialization_ops(

Callers 1

Calls 4

setClass · 0.85
enumerateFunction · 0.85
isinstanceFunction · 0.85
targetsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…