Infer a more precise return type for functools.partial
(ctx: mypy.plugin.FunctionContext)
| 135 | |
| 136 | |
| 137 | def partial_new_callback(ctx: mypy.plugin.FunctionContext) -> Type: |
| 138 | """Infer a more precise return type for functools.partial""" |
| 139 | if not isinstance(ctx.api, mypy.checker.TypeChecker): # use internals |
| 140 | return ctx.default_return_type |
| 141 | if len(ctx.arg_types) != 3: # fn, *args, **kwargs |
| 142 | return ctx.default_return_type |
| 143 | if len(ctx.arg_types[0]) != 1: |
| 144 | return ctx.default_return_type |
| 145 | |
| 146 | if isinstance(get_proper_type(ctx.arg_types[0][0]), Overloaded): |
| 147 | # TODO: handle overloads, just fall back to whatever the non-plugin code does |
| 148 | return ctx.default_return_type |
| 149 | return handle_partial_with_callee(ctx, callee=ctx.arg_types[0][0]) |
| 150 | |
| 151 | |
| 152 | def handle_partial_with_callee(ctx: mypy.plugin.FunctionContext, callee: Type) -> Type: |
nothing calls this directly
no test coverage detected
searching dependent graphs…