Skip to content

Make argument types in function type inference explicitly Optional #1392

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

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def infer_function_type_arguments(self, callee_type: CallableType,
arg_pass_nums = self.get_arg_infer_passes(
callee_type.arg_types, formal_to_actual, len(args))

pass1_args = [] # type: List[Type]
pass1_args = [] # type: List[Optional[Type]]
for i, arg in enumerate(arg_types):
if arg_pass_nums[i] > 1:
pass1_args.append(None)
Expand Down
7 changes: 5 additions & 2 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Type inference constraints."""

from typing import List, cast
from typing import List, Optional, cast

from mypy.types import (
CallableType, Type, TypeVisitor, UnboundType, AnyType, Void, NoneTyp, TypeVarType,
Expand Down Expand Up @@ -39,7 +39,7 @@ def __repr__(self) -> str:


def infer_constraints_for_callable(
callee: CallableType, arg_types: List[Type], arg_kinds: List[int],
callee: CallableType, arg_types: List[Optional[Type]], arg_kinds: List[int],
formal_to_actual: List[List[int]]) -> List[Constraint]:
"""Infer type variable constraints for a callable and actual arguments.

Expand All @@ -51,6 +51,9 @@ def infer_constraints_for_callable(

for i, actuals in enumerate(formal_to_actual):
for actual in actuals:
if arg_types[actual] is None:
continue

actual_type = get_actual_type(arg_types[actual], arg_kinds[actual],
tuple_counter)
c = infer_constraints(callee.arg_types[i], actual_type,
Expand Down
7 changes: 4 additions & 3 deletions mypy/infer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Utilities for type argument inference."""

from typing import List
from typing import List, Optional

from mypy.constraints import infer_constraints, infer_constraints_for_callable
from mypy.types import Type, CallableType
Expand All @@ -9,7 +9,7 @@


def infer_function_type_arguments(callee_type: CallableType,
arg_types: List[Type],
arg_types: List[Optional[Type]],
arg_kinds: List[int],
formal_to_actual: List[List[int]],
strict: bool = True) -> List[Type]:
Expand All @@ -21,7 +21,8 @@ def infer_function_type_arguments(callee_type: CallableType,

Arguments:
callee_type: the target generic function
arg_types: argument types at the call site
arg_types: argument types at the call site (each optional; if None,
we are not considering this argument in the current pass)
arg_kinds: nodes.ARG_* values for arg_types
formal_to_actual: mapping from formal to actual variable indices
"""
Expand Down