Skip to content

Commit

Permalink
added error code, message, in prog test
Browse files Browse the repository at this point in the history
  • Loading branch information
katconnors committed Jul 26, 2024
1 parent db9837f commit 22ca9cc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
continue

if overload_can_never_match(sig1, sig2):

self.msg.overloaded_signature_will_never_match(i + 1, i + j + 2, item2.func)
elif not is_descriptor_get:
# Note: we force mypy to check overload signatures in strict-optional mode
Expand Down
6 changes: 6 additions & 0 deletions mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ def __hash__(self) -> int:
default_enabled=False,
)

OVERLOADED_FUNCTION_MATCHING: Final[ErrorCode] = ErrorCode(
"overloaded-function-matching",
"Warn user about signature matching for overloaded functions.",
"General",
)

# Syntax errors are often blocking.
SYNTAX: Final[ErrorCode] = ErrorCode("syntax", "Report syntax errors", "General")

Expand Down
5 changes: 5 additions & 0 deletions mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,8 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
TYPE_ALIAS_WITH_AWAIT_EXPRESSION: Final = ErrorMessage(
"Await expression cannot be used within a type alias", codes.SYNTAX
)

# Overloads
OVERLOADED_FUNCTION_SIGNATURE: Final = ErrorMessage(
"Overloaded function signature {} will never be matched", codes.OVERLOADED_FUNCTION_MATCHING
)
17 changes: 17 additions & 0 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,20 @@ def f(x: str) -> TypeIs[int]: # E: Narrowed type "int" is not a subtype of inpu
pass

[builtins fixtures/tuple.pyi]


[case testOverloadedFunctionSignature]
from typing import overload, Union

@overload
def process(response1: float,response2: float) -> float:
...
@overload
def process(response1: int,response2: int) -> int: # E: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader [overloaded-function-matching]
...

def process(response1,response2)-> Union[float,int]:
return response1 + response2



0 comments on commit 22ca9cc

Please sign in to comment.