Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reduce noise on broken overloads
  • Loading branch information
ilevkivskyi committed Aug 17, 2023
commit c6560f439214f534a2a5c6a3c1a14dac1d8823d5
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
result = function_type(node, self.named_type("builtins.function"))
elif isinstance(node, OverloadedFuncDef):
if node.type is None:
if self.chk.in_checked_function():
if self.chk.in_checked_function() and node.items:
self.chk.handle_cannot_determine_type(node.name, e)
result = AnyType(TypeOfAny.from_error)
else:
Expand Down
2 changes: 1 addition & 1 deletion mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def analyze_instance_member_access(
if method.type is None:
# Overloads may be not ready if they are decorated. Handle this in same
# manner as we would handle a regular decorated function: defer if possible.
if not mx.no_deferral:
if not mx.no_deferral and method.items:
mx.not_ready_callback(method.name, mx.context)
return AnyType(TypeOfAny.special_form)
assert isinstance(method.type, Overloaded)
Expand Down
7 changes: 2 additions & 5 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ f(0)
@overload # E: Name "overload" is not defined
def g(a:int): pass
def g(a): pass # E: Name "g" already defined on line 9
g(0) # E: Cannot determine type of "g"
g(0)

@something # E: Name "something" is not defined
def r(a:int): pass
def r(a): pass # E: Name "r" already defined on line 14
r(0) # E: Cannot determine type of "r"
r(0)
[out]
main:2: error: Name "overload" is not defined
main:4: error: Name "f" already defined on line 2
main:4: error: Name "overload" is not defined
main:6: error: Name "f" already defined on line 2
main:7: error: Cannot determine type of "f"

[case testTypeCheckOverloadWithImplementation]
from typing import overload, Any
Expand Down Expand Up @@ -5227,7 +5226,6 @@ def func(x):
[out]
tmp/lib.pyi:1: error: Name "overload" is not defined
tmp/lib.pyi:4: error: Name "func" already defined on line 1
main:2: error: Cannot determine type of "func"
main:2: note: Revealed type is "Any"

-- Order of errors is different
Expand All @@ -5244,7 +5242,6 @@ def func(x: str) -> str: ...
tmp/lib.pyi:1: error: Name "overload" is not defined
tmp/lib.pyi:3: error: Name "func" already defined on line 1
tmp/lib.pyi:3: error: Name "overload" is not defined
main:3: error: Cannot determine type of "func"
main:3: note: Revealed type is "Any"

[case testLiteralSubtypeOverlap]
Expand Down