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

Function generate_singledispatch_callable_class_ctor

mypyc/irbuild/function.py:1095–1107  ·  view source on GitHub ↗

Create an __init__ that sets registry and dispatch_cache to empty dicts

(builder: IRBuilder)

Source from the content-addressed store, hash-verified

1093
1094
1095def generate_singledispatch_callable_class_ctor(builder: IRBuilder) -> None:
1096 """Create an __init__ that sets registry and dispatch_cache to empty dicts"""
1097 line = builder.fn_info.fitem.line
1098 class_ir = builder.fn_info.callable_class.ir
1099 with builder.enter_method(class_ir, "__init__", bool_rprimitive):
1100 empty_dict = builder.call_c(dict_new_op, [], line)
1101 builder.add(SetAttr(builder.self(), "registry", empty_dict, line))
1102 cache_dict = builder.call_c(dict_new_op, [], line)
1103 dispatch_cache_str = builder.load_str("dispatch_cache")
1104 # use the py_setattr_op instead of SetAttr so that it also gets added to our __dict__
1105 builder.primitive_op(py_setattr_op, [builder.self(), dispatch_cache_str, cache_dict], line)
1106 # the generated C code seems to expect that __init__ returns a char, so just return 1
1107 builder.add(Return(Integer(1, bool_rprimitive, line), line))
1108
1109
1110def add_register_method_to_callable_class(builder: IRBuilder, fn_info: FuncInfo) -> None:

Callers 1

gen_dispatch_func_irFunction · 0.85

Calls 9

SetAttrClass · 0.90
ReturnClass · 0.90
IntegerClass · 0.90
enter_methodMethod · 0.45
call_cMethod · 0.45
addMethod · 0.45
selfMethod · 0.45
load_strMethod · 0.45
primitive_opMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…