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

Method emit_error_check

mypyc/codegen/emit.py:1273–1289  ·  view source on GitHub ↗

Emit code for checking a native function return value for uncaught exception.

(self, value: str, rtype: RType, failure: str)

Source from the content-addressed store, hash-verified

1271 self.emit_line(f"{declaration}{dest} = {src};")
1272
1273 def emit_error_check(self, value: str, rtype: RType, failure: str) -> None:
1274 """Emit code for checking a native function return value for uncaught exception."""
1275 if isinstance(rtype, RTuple):
1276 if len(rtype.types) == 0:
1277 return # empty tuples can't fail.
1278 else:
1279 cond = self.tuple_undefined_check_cond(rtype, value, self.c_error_value, "==")
1280 self.emit_line(f"if ({cond}) {{")
1281 elif isinstance(rtype, RVec):
1282 self.emit_line(f"if ({value}.len < 0) {{")
1283 elif rtype.error_overlap:
1284 # The error value is also valid as a normal value, so we need to also check
1285 # for a raised exception.
1286 self.emit_line(f"if ({value} == {self.c_error_value(rtype)} && PyErr_Occurred()) {{")
1287 else:
1288 self.emit_line(f"if ({value} == {self.c_error_value(rtype)}) {{")
1289 self.emit_lines(failure, "}")
1290
1291 def emit_gc_visit(self, target: str, rtype: RType) -> None:
1292 """Emit code for GC visiting a C variable reference.

Callers 7

generate_hash_wrapperFunction · 0.80
generate_len_wrapperFunction · 0.80
generate_bool_wrapperFunction · 0.80
emit_callMethod · 0.80
generate_readonly_getterFunction · 0.80

Calls 6

emit_lineMethod · 0.95
c_error_valueMethod · 0.95
emit_linesMethod · 0.95
isinstanceFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected