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

Function transform_assert_stmt

mypyc/irbuild/statement.py:1195–1215  ·  view source on GitHub ↗
(builder: IRBuilder, a: AssertStmt)

Source from the content-addressed store, hash-verified

1193
1194
1195def transform_assert_stmt(builder: IRBuilder, a: AssertStmt) -> None:
1196 if builder.options.strip_asserts:
1197 return
1198 cond = builder.accept(a.expr)
1199 ok_block, error_block = BasicBlock(), BasicBlock()
1200 builder.add_bool_branch(cond, ok_block, error_block)
1201 builder.activate_block(error_block)
1202 if a.msg is None:
1203 # Special case (for simpler generated code)
1204 builder.add(RaiseStandardError(RaiseStandardError.ASSERTION_ERROR, None, a.line))
1205 elif isinstance(a.msg, StrExpr):
1206 # Another special case
1207 builder.add(RaiseStandardError(RaiseStandardError.ASSERTION_ERROR, a.msg.value, a.line))
1208 else:
1209 # The general case -- explicitly construct an exception instance
1210 message = builder.accept(a.msg)
1211 exc_type = builder.load_module_attr_by_fullname("builtins.AssertionError", a.line)
1212 exc = builder.py_call(exc_type, [message], a.line)
1213 builder.call_c(raise_exception_op, [exc], a.line)
1214 builder.add(Unreachable())
1215 builder.activate_block(ok_block)
1216
1217
1218def transform_del_stmt(builder: IRBuilder, o: DelStmt) -> None:

Callers 1

visit_assert_stmtMethod · 0.90

Calls 11

BasicBlockClass · 0.90
RaiseStandardErrorClass · 0.90
UnreachableClass · 0.90
isinstanceFunction · 0.85
acceptMethod · 0.45
add_bool_branchMethod · 0.45
activate_blockMethod · 0.45
addMethod · 0.45
py_callMethod · 0.45
call_cMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…