Called for functools.singledispatch
(ctx: FunctionContext)
| 86 | |
| 87 | |
| 88 | def 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 | |
| 115 | def singledispatch_register_callback(ctx: MethodContext) -> Type: |
nothing calls this directly
no test coverage detected
searching dependent graphs…