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

Function partial_new_callback

mypy/plugins/functools.py:137–149  ·  view source on GitHub ↗

Infer a more precise return type for functools.partial

(ctx: mypy.plugin.FunctionContext)

Source from the content-addressed store, hash-verified

135
136
137def 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
152def handle_partial_with_callee(ctx: mypy.plugin.FunctionContext, callee: Type) -> Type:

Callers

nothing calls this directly

Calls 4

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…