Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def __hash__(self) -> int:
"General",
default_enabled=False,
)

Comment thread
randolf-scholz marked this conversation as resolved.
Outdated
USED_BEFORE_DEF: Final[ErrorCode] = ErrorCode(
"used-before-def", "Warn about variables that are used before they are defined", "General"
)
Expand All @@ -261,3 +262,10 @@ def __hash__(self) -> int:

# This is a catch-all for remaining uncategorized errors.
MISC: Final = ErrorCode("misc", "Miscellaneous other checks", "General")

UNSAFE_OVERLOAD: Final[ErrorCode] = ErrorCode(
"unsafe-overload",
"Warn if multiple @overload variants overlap in unsafe ways",
"General",
sub_code_of=MISC,
)
5 changes: 3 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,9 +1601,10 @@ def overload_inconsistently_applies_decorator(self, decorator: str, context: Con

def overloaded_signatures_overlap(self, index1: int, index2: int, context: Context) -> None:
self.fail(
"Overloaded function signatures {} and {} overlap with "
"incompatible return types".format(index1, index2),
f"Overloaded function signatures {index1} and {index2} overlap with incompatible return types",
# "See https://mypy.readthedocs.io/en/stable/more_types.html#type-checking-the-variants.",
Comment thread
randolf-scholz marked this conversation as resolved.
Outdated
context,
code=codes.UNSAFE_OVERLOAD,
)

def overloaded_signature_will_never_match(
Expand Down
2 changes: 1 addition & 1 deletion mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ def get_proper_type(typ: Type | None) -> ProperType | None:


@overload
def get_proper_types(types: list[Type] | tuple[Type, ...]) -> list[ProperType]: # type: ignore[misc]
def get_proper_types(types: list[Type] | tuple[Type, ...]) -> list[ProperType]: # type: ignore[unsafe-overload]
...


Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -1072,3 +1072,17 @@ A.f = h # type: ignore[assignment] # E: Unused "type: ignore" comment, use nar
[case testUnusedIgnoreEnableCode]
# flags: --enable-error-code=unused-ignore
x = 1 # type: ignore # E: Unused "type: ignore" comment [unused-ignore]

[case testErrorCodeUnsafeOverloadError]
from typing import overload, Union

@overload
def unsafe_func(x: int) -> int: ... # E: Overloaded function signatures 1 and 2 overlap with incompatible return types [unsafe-overload]
@overload
def unsafe_func(x: object) -> str: ...
def unsafe_func(x: object) -> Union[int, str]:
if isinstance(x, int):
return 42
else:
return "some string"
[builtins fixtures/isinstancelist.pyi]