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

Function generate_singledispatch_dispatch_function

mypyc/irbuild/function.py:965–997  ·  view source on GitHub ↗
(
    builder: IRBuilder, main_singledispatch_function_name: str, fitem: FuncDef
)

Source from the content-addressed store, hash-verified

963
964
965def generate_singledispatch_dispatch_function(
966 builder: IRBuilder, main_singledispatch_function_name: str, fitem: FuncDef
967) -> None:
968 line = fitem.line
969 current_func_decl = builder.mapper.func_to_decl[fitem]
970 arg_info = get_args(builder, current_func_decl.sig.args, line)
971
972 dispatch_func_obj = builder.self()
973
974 arg_type = builder.builder.get_type_of_obj(arg_info.args[0], line)
975 dispatch_cache = builder.builder.get_attr(
976 dispatch_func_obj, "dispatch_cache", dict_rprimitive, line
977 )
978 call_find_impl, use_cache, call_func = BasicBlock(), BasicBlock(), BasicBlock()
979 get_result = builder.primitive_op(dict_get_method_with_none, [dispatch_cache, arg_type], line)
980 is_not_none = builder.translate_is_op(get_result, builder.none_object(), "is not", line)
981 impl_to_use = Register(object_rprimitive)
982 builder.add_bool_branch(is_not_none, use_cache, call_find_impl)
983
984 builder.activate_block(use_cache)
985 builder.assign(impl_to_use, get_result, line)
986 builder.goto(call_func)
987
988 builder.activate_block(call_find_impl)
989 find_impl = builder.load_module_attr_by_fullname("functools._find_impl", line)
990 registry = load_singledispatch_registry(builder, dispatch_func_obj, line)
991 uncached_impl = builder.py_call(find_impl, [arg_type, registry], line)
992 builder.call_c(exact_dict_set_item_op, [dispatch_cache, arg_type, uncached_impl], line)
993 builder.assign(impl_to_use, uncached_impl, line)
994 builder.goto(call_func)
995
996 builder.activate_block(call_func)
997 gen_calls_to_correct_impl(builder, impl_to_use, arg_info, fitem, line)
998
999
1000def gen_calls_to_correct_impl(

Callers 1

gen_dispatch_func_irFunction · 0.85

Calls 15

BasicBlockClass · 0.90
RegisterClass · 0.90
get_argsFunction · 0.85
get_type_of_objMethod · 0.80
get_attrMethod · 0.80
selfMethod · 0.45
primitive_opMethod · 0.45
translate_is_opMethod · 0.45
none_objectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…