Skip to content

Commit d2886ac

Browse files
committed
ignore overload, as previously
1 parent 03b397e commit d2886ac

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mypy/plugins/functools.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AnyType,
1414
CallableType,
1515
Instance,
16+
Overloaded,
1617
Type,
1718
TypeOfAny,
1819
UnboundType,
@@ -124,6 +125,9 @@ def partial_new_callback(ctx: mypy.plugin.FunctionContext) -> Type:
124125
if len(ctx.arg_types[0]) != 1:
125126
return ctx.default_return_type
126127

128+
if isinstance(ctx.arg_types[0][0], Overloaded):
129+
# TODO: handle overloads, just fall back to whatever the non-plugin code does
130+
return ctx.default_return_type
127131
fn_type = ctx.api.extract_callable_type(ctx.arg_types[0][0], ctx=ctx.default_return_type)
128132
if fn_type is None:
129133
return ctx.default_return_type

test-data/unit/check-functools.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,23 @@ def main2(f: CallbackProto) -> None:
261261
p("a") # E: Argument 1 to "__call__" of "CallbackProto" has incompatible type "str"; expected "int"
262262
[builtins fixtures/dict.pyi]
263263

264+
[case testFunctoolsPartialOverload]
265+
from typing import overload
266+
import functools
267+
268+
@overload
269+
def foo(a: int, b: str) -> int: ...
270+
@overload
271+
def foo(a: str, b: int) -> str: ...
272+
def foo(*a, **k): ...
273+
274+
p1 = functools.partial(foo)
275+
reveal_type(p1(1, "a")) # N: Revealed type is "builtins.int"
276+
reveal_type(p1("a", 1)) # N: Revealed type is "builtins.int"
277+
p1(1, 2) # TODO: false negative
278+
p1("a", "b") # TODO: false negative
279+
[builtins fixtures/dict.pyi]
280+
264281
[case testFunctoolsPartialTypeGuard]
265282
import functools
266283
from typing_extensions import TypeGuard

0 commit comments

Comments
 (0)