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

Function add_throw_to_generator_class

mypyc/irbuild/generator.py:302–331  ·  view source on GitHub ↗

Generates the 'throw' method for a generator class.

(builder: IRBuilder, fn_info: FuncInfo, fn_decl: FuncDecl)

Source from the content-addressed store, hash-verified

300
301
302def add_throw_to_generator_class(builder: IRBuilder, fn_info: FuncInfo, fn_decl: FuncDecl) -> None:
303 """Generates the 'throw' method for a generator class."""
304 with builder.enter_method(fn_info.generator_class.ir, "throw", object_rprimitive, fn_info):
305 typ = builder.add_argument("type", object_rprimitive)
306 val = builder.add_argument("value", object_rprimitive, ARG_OPT)
307 tb = builder.add_argument("traceback", object_rprimitive, ARG_OPT)
308
309 # Because the value and traceback arguments are optional and hence
310 # can be NULL if not passed in, we have to assign them Py_None if
311 # they are not passed in.
312 none_reg = builder.none_object()
313 builder.assign_if_null(val, lambda: none_reg, fn_info.fitem.line)
314 builder.assign_if_null(tb, lambda: none_reg, fn_info.fitem.line)
315
316 # Call the helper function using the arguments passed in, and return that result.
317 result = builder.add(
318 Call(
319 fn_decl,
320 [
321 builder.self(),
322 builder.read(typ),
323 builder.read(val),
324 builder.read(tb),
325 none_reg,
326 Integer(0, object_pointer_rprimitive),
327 ],
328 fn_info.fitem.line,
329 )
330 )
331 builder.add(Return(result))
332
333
334def add_close_to_generator_class(builder: IRBuilder, fn_info: FuncInfo) -> None:

Callers 1

Calls 10

CallClass · 0.90
IntegerClass · 0.90
ReturnClass · 0.90
add_argumentMethod · 0.80
assign_if_nullMethod · 0.80
enter_methodMethod · 0.45
none_objectMethod · 0.45
addMethod · 0.45
selfMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…