Skip to content

Commit da42901

Browse files
committed
Solve a followup problem without a tracking issue
1 parent 993afe5 commit da42901

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

mypy/typeops.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,19 +458,17 @@ def callable_corresponding_argument(
458458
if by_name is not None and by_pos is not None:
459459
if by_name == by_pos:
460460
return by_name
461-
# If we're dealing with an optional pos-only and an optional
462-
# name-only arg, merge them. This is the case for all functions
463-
# taking both *args and **args, or a pair of functions like so:
461+
# If we're dealing with an optional pos and an optional
462+
# name arg, merge them. This is the case for all functions
463+
# taking both *args and **args, or a functions like so:
464464

465465
# def right(a: int = ...) -> None: ...
466-
# def left(__a: int = ..., *, a: int = ...) -> None: ...
466+
# def left1(__a: int = ..., *, a: int = ...) -> None: ...
467+
# def left2(x: int = ..., a: int = ...) -> None: ...
468+
467469
from mypy.meet import meet_types
468470

469-
if (
470-
not (by_name.required or by_pos.required)
471-
and by_pos.name is None
472-
and by_name.pos is None
473-
):
471+
if not (by_name.required or by_pos.required):
474472
return FormalArgument(
475473
by_name.name, by_pos.pos, meet_types(by_pos.typ, by_name.typ), False
476474
)

test-data/unit/check-overloading.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6784,3 +6784,18 @@ def set() -> None:
67846784
def set(*args: object, **kw: int) -> None:
67856785
pass
67866786
[builtins fixtures/tuple.pyi]
6787+
6788+
[case testOverloadWithTwoRelevantOptionalArgs]
6789+
from typing import overload
6790+
6791+
@overload
6792+
def set(year: int) -> None:
6793+
...
6794+
6795+
@overload
6796+
def set() -> None:
6797+
...
6798+
6799+
# no error:
6800+
def set(x: int = 42, year: int = 42) -> None:
6801+
pass

0 commit comments

Comments
 (0)