8000 Fix overloading with a typevar missing by A5rocks · Pull Request #15320 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix overloading with a typevar missing #15320

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Fix confusion about target
  • Loading branch information
A5rocks committed Jun 18, 2023
commit 173ca78bda8cd9dfe5076cda916b8b2c7f10630c
14 changes: 7 additions & 7 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,15 +1696,15 @@ def unify_generic_callable(
# check by names
argument_names_map = {}

for i in range(len(type.arg_types)):
if type.arg_names[i] and type.arg_kinds[i] != ARG_POS:
argument_names_map[type.arg_names[i]] = type.arg_types[i]

for i in range(len(target.arg_types)):
if target.arg_names[i] and target.arg_names[i] in argument_names_map:
if target.arg_names[i] and target.arg_kinds[i] != ARG_POS:
argument_names_map[target.arg_names[i]] = target.arg_types[i]

for i in range(len(type.arg_types)):
if type.arg_names[i] and type.arg_names[i] in argument_names_map:
c = mypy.constraints.infer_constraints(
argument_names_map[target.arg_names[i]],
target.arg_types[i],
argument_names_map[type.arg_names[i]],
type.arg_types[i],
mypy.constraints.SUPERTYPE_OF,
)
constraints.extend(c)
Expand Down
27 changes: 27 additions & 0 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -6563,3 +6563,30 @@ def f(a: T = ..., *, copy: bool = False) -> T:
...

reveal_type(f) # N: Revealed type is "Overload(def [T <: __main__.A] (a: T`-1) -> T`-1, def (*, copy: builtins.bool =))"

[case testOverloadingWithTypeVarWhereTargetIsPosOnly]
from typing import overload, TypeVar, Union

T1 = TypeVar("T1")
T2 = TypeVar("T2")

@overload
def f(
*,
x: T1,
) -> None:
...

@overload
def f( # type: ignore
*,
x: T2,
) -> None:
...

def f(
x: Union[T1, T2]
) -> None:
...

reveal_type(f) # N: Revealed type is "Overload(def [T1] (*, x: T1`-1), def [T2] (*, x: T2`-1))"
0