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 #11617

Closed
wants to merge 4 commits into from
Closed
Changes from all 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
29 changes: 25 additions & 4 deletions mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,31 @@ def unify_generic_callable(type: CallableType, target: CallableType,
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 = {}
# `is_unsafe_overlapping_overload_signatures` calls this both ways
for i in range(len(target.arg_types)):
if target.arg_names[i]:
argument_names_map[target.arg_names[i]] = target.arg_types[i]
for i in range(len(type.arg_types)):
if type.arg_names[i]:
argument_names_map[type.arg_names[i]] = type.arg_types[i]
for i in range(len(target.arg_types)):
if target.arg_names[i]:
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)
else:
# optimization, no more positional arguments
break
if not ignore_return:
c = mypy.constraints.infer_constraints(
type.ret_type, target.ret_type, return_constraint_direction)
Expand Down