Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/plugins/singledispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def create_singledispatch_function_callback(ctx: FunctionContext) -> Type:
# singledispatch returns an instance of functools._SingleDispatchCallable according to
# typeshed
singledispatch_obj = get_proper_type(ctx.default_return_type)
assert isinstance(singledispatch_obj, Instance)
if not isinstance(singledispatch_obj, Instance):
return ctx.default_return_type
singledispatch_obj.args += (func_type,)

return ctx.default_return_type
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-singledispatch.test
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,15 @@ def default(val) -> int:
return 3

[builtins fixtures/args.pyi]

[case testDontCrashWhenSingledispatchIsShadowedByUserFunction]
# cmd: mypy -m functools
[file functools.py]
def singledispatch(func):
pass

@singledispatch
def f(fn):
pass
[out]
[builtins fixtures/args.pyi]
Loading