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

Fix overloading with a typevar missing #15320

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
30 changes: 25 additions & 5 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Circular import; done in the function instead.
# import mypy.solve
from mypy.nodes import (
ARG_POS,
ARG_STAR,
ARG_STAR2,
CONTRAVARIANT,
Expand Down Expand Up @@ -1692,11 +1693,30 @@ def unify_generic_callable(
return_constraint_direction = mypy.constraints.SUBTYPE_OF

constraints: list[mypy.constraints.Constraint] = []
for arg_type, target_arg_type in zip(type.arg_types, target.arg_types):
c = mypy.constraints.infer_constraints(
arg_type, target_arg_type, mypy.constraints.SUPERTYPE_OF
)
constraints.extend(c)
# 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:
c = mypy.constraints.infer_constraints(
argument_names_map[target.arg_names[i]],
target.arg_types[i],
mypy.constraints.SUPERTYPE_OF,
)
constraints.extend(c)

# check pos-only arguments
for arg, target_arg in zip(type.formal_arguments(), target.formal_arguments()):
if arg.pos is not None and target_arg.pos is not None:
c = mypy.constraints.infer_constraints(
arg.typ, target_arg.typ, mypy.constraints.SUPERTYPE_OF
)
constraints.extend(c)

if not ignore_return:
c = mypy.constraints.infer_constraints(
type.ret_type, target.ret_type, return_constraint_direction
Expand Down