Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More principled approach for callable vs callable inference #15910

Merged
merged 6 commits into from
Aug 21, 2023
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
Fix partial overlap in overlapping overload checks
  • Loading branch information
ilevkivskyi committed Aug 19, 2023
commit 4fe5688a861ef854c66101b4965942791fa66c2e
6 changes: 5 additions & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,10 @@ def are_args_compatible(
allow_partial_overlap: bool,
is_compat: Callable[[Type, Type], bool],
) -> bool:
if left.required and right.required:
# If both arguments are required allow_partial_overlap has no effect.
allow_partial_overlap = False

def is_different(left_item: object | None, right_item: object | None) -> bool:
"""Checks if the left and right items are different.

Expand Down Expand Up @@ -1660,7 +1664,7 @@ def is_different(left_item: object | None, right_item: object | None) -> bool:

# If right's argument is optional, left's must also be
# (unless we're relaxing the checks to allow potential
# rather then definite compatibility).
# rather than definite compatibility).
if not allow_partial_overlap and not right.required and left.required:
return False

Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -6640,3 +6640,12 @@ def bar(x): ...

reveal_type(bar) # N: Revealed type is "Overload(def (builtins.int) -> builtins.float, def (builtins.str) -> builtins.str)"
[builtins fixtures/paramspec.pyi]

[case testOverloadOverlapWithNameOnlyArgs]
from typing import overload

@overload
def d(x: int) -> int: ...
@overload
def d(f: int, *, x: int) -> str: ...
def d(x): ...
Loading