Skip to content
Merged
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
4 changes: 3 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
elif isinstance(node, FuncDef):
# Reference to a global function.
result = function_type(node, self.named_type('builtins.function'))
elif isinstance(node, OverloadedFuncDef):
elif isinstance(node, OverloadedFuncDef) and node.type is not None:
# node.type is None when there are multiple definitions of a function
# and it's decorated by somthing that is not typing.overload
result = node.type
elif isinstance(node, TypeInfo):
# Reference to a type object.
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
-- Test cases for function overloading
[case testOverloadNotImportedNoCrash]
@overload
def f(a): pass
@overload
def f(a): pass
def f(a): pass
f(0)

@overload # E: Name 'overload' is not defined
def g(a:int): pass
def g(a): pass # E: Name 'g' already defined
g(0)

@something # E: Name 'something' is not defined
def r(a:int): pass
def r(a): pass # E: Name 'r' already defined
r(0)
[out]
main:1: error: Name 'overload' is not defined
main:3: error: Name 'f' already defined
main:3: error: Name 'overload' is not defined
main:5: error: Name 'f' already defined

[case testTypeCheckOverloadWithImplementation]
from typing import overload, Any
Expand Down