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

Function apply_dunder_specialization

mypyc/irbuild/specialize.py:254–281  ·  view source on GitHub ↗

Invoke the DunderSpecializer callback if one has been registered. Args: builder: The IR builder base_expr: The base expression (target object) args: List of argument expressions (positional arguments to the dunder) name: The dunder method name (e.g., "__getitem__

(
    builder: IRBuilder,
    base_expr: Expression,
    args: list[Expression],
    name: str,
    ctx_expr: Expression,
)

Source from the content-addressed store, hash-verified

252
253
254def apply_dunder_specialization(
255 builder: IRBuilder,
256 base_expr: Expression,
257 args: list[Expression],
258 name: str,
259 ctx_expr: Expression,
260) -> Value | None:
261 """Invoke the DunderSpecializer callback if one has been registered.
262
263 Args:
264 builder: The IR builder
265 base_expr: The base expression (target object)
266 args: List of argument expressions (positional arguments to the dunder)
267 name: The dunder method name (e.g., "__getitem__")
268 ctx_expr: The context expression for error reporting (e.g., IndexExpr)
269
270 Returns:
271 The specialized value, or None if no specialization was found.
272 """
273 base_type = builder.node_type(base_expr)
274
275 # Check if there's a specializer for this dunder method and type
276 if (name, base_type) in dunder_specializers:
277 for specializer in dunder_specializers[name, base_type]:
278 val = specializer(builder, base_expr, args, ctx_expr)
279 if val is not None:
280 return val
281 return None
282
283
284@specialize_function("builtins.globals")

Callers 2

transform_index_exprFunction · 0.90

Calls 1

node_typeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…