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

Method emit_undefined_attr_check

mypyc/codegen/emit.py:480–500  ·  view source on GitHub ↗
(
        self,
        rtype: RType,
        attr_expr: str,
        compare: str,
        obj: str,
        attr: str,
        cl: ClassIR,
        *,
        unlikely: bool = False,
    )

Source from the content-addressed store, hash-verified

478 self.emit_line("}")
479
480 def emit_undefined_attr_check(
481 self,
482 rtype: RType,
483 attr_expr: str,
484 compare: str,
485 obj: str,
486 attr: str,
487 cl: ClassIR,
488 *,
489 unlikely: bool = False,
490 ) -> None:
491 check = self.error_value_check(rtype, attr_expr, compare)
492 if unlikely:
493 check = f"unlikely({check})"
494 if rtype.error_overlap:
495 index = cl.bitmap_attrs.index(attr)
496 bit = 1 << (index & (BITMAP_BITS - 1))
497 attr = self.bitmap_field(index)
498 obj_expr = f"({cl.struct_name(self.names)} *){obj}"
499 check = f"{check} && !(({obj_expr})->{attr} & {bit})"
500 self.emit_line(f"if ({check}) {{")
501
502 def error_value_check(self, rtype: RType, value: str, compare: str) -> str:
503 if isinstance(rtype, RTuple):

Callers 4

generate_getterFunction · 0.80
generate_setterFunction · 0.80
visit_get_attrMethod · 0.80
visit_set_attrMethod · 0.80

Calls 5

error_value_checkMethod · 0.95
bitmap_fieldMethod · 0.95
emit_lineMethod · 0.95
indexMethod · 0.80
struct_nameMethod · 0.45

Tested by

no test coverage detected