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

Function create_singledispatch_function_callback

mypy/plugins/singledispatch.py:88–112  ·  view source on GitHub ↗

Called for functools.singledispatch

(ctx: FunctionContext)

Source from the content-addressed store, hash-verified

86
87
88def create_singledispatch_function_callback(ctx: FunctionContext) -> Type:
89 """Called for functools.singledispatch"""
90 func_type = get_proper_type(get_first_arg(ctx.arg_types))
91 if isinstance(func_type, CallableType):
92 if len(func_type.arg_kinds) < 1:
93 fail(
94 ctx, "Singledispatch function requires at least one argument", func_type.definition
95 )
96 return ctx.default_return_type
97
98 elif not func_type.arg_kinds[0].is_positional(star=True):
99 fail(
100 ctx,
101 "First argument to singledispatch function must be a positional argument",
102 func_type.definition,
103 )
104 return ctx.default_return_type
105
106 # singledispatch returns an instance of functools._SingleDispatchCallable according to
107 # typeshed
108 singledispatch_obj = get_proper_type(ctx.default_return_type)
109 assert isinstance(singledispatch_obj, Instance)
110 singledispatch_obj.args += (func_type,)
111
112 return ctx.default_return_type
113
114
115def singledispatch_register_callback(ctx: MethodContext) -> Type:

Callers

nothing calls this directly

Calls 6

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
is_positionalMethod · 0.80
get_first_argFunction · 0.70
failFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…