Skip to content
Draft
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
8 changes: 4 additions & 4 deletions mypy/checker_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mypy.errors import ErrorWatcher
from mypy.message_registry import ErrorMessage
from mypy.nodes import (
ArgKind,
ArgKinds,
Context,
Expression,
FuncItem,
Expand Down Expand Up @@ -69,7 +69,7 @@ def check_call(
self,
callee: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None = None,
callable_node: Expression | None = None,
Expand All @@ -85,7 +85,7 @@ def transform_callee_type(
callable_name: str | None,
callee: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None = None,
object_type: Type | None = None,
Expand All @@ -102,7 +102,7 @@ def check_method_call_by_name(
method: str,
base_type: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
original_type: Type | None = None,
) -> tuple[Type, Type]:
Expand Down
61 changes: 31 additions & 30 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
REVEAL_LOCALS,
REVEAL_TYPE,
ArgKind,
ArgKinds,
AssertTypeExpr,
AssignmentExpr,
AwaitExpr,
Expand Down Expand Up @@ -772,7 +773,7 @@ def check_protocol_issubclass(self, e: CallExpr) -> None:
def check_typeddict_call(
self,
callee: TypedDictType,
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None],
args: list[Expression],
context: Context,
Expand Down Expand Up @@ -1213,7 +1214,7 @@ def try_infer_partial_value_type_from_call(
def apply_function_plugin(
self,
callee: CallableType,
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_types: list[Type],
arg_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
Expand All @@ -1237,7 +1238,7 @@ def apply_function_plugin(
formal_arg_types: list[list[Type]] = [[] for _ in range(num_formals)]
formal_arg_exprs: list[list[Expression]] = [[] for _ in range(num_formals)]
formal_arg_names: list[list[str | None]] = [[] for _ in range(num_formals)]
formal_arg_kinds: list[list[ArgKind]] = [[] for _ in range(num_formals)]
formal_arg_kinds: list[ArgKinds] = [[] for _ in range(num_formals)]
for formal, actuals in enumerate(formal_to_actual):
for actual in actuals:
formal_arg_types[formal].append(arg_types[actual])
Expand Down Expand Up @@ -1287,7 +1288,7 @@ def apply_signature_hook(
self,
callee: FunctionLike,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
hook: Callable[[list[list[Expression]], CallableType], FunctionLike],
) -> FunctionLike:
Expand Down Expand Up @@ -1319,7 +1320,7 @@ def apply_function_signature_hook(
self,
callee: FunctionLike,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None,
signature_hook: Callable[[FunctionSigContext], FunctionLike],
Expand All @@ -1337,7 +1338,7 @@ def apply_method_signature_hook(
self,
callee: FunctionLike,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None,
object_type: Type,
Expand All @@ -1362,7 +1363,7 @@ def transform_callee_type(
callable_name: str | None,
callee: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None = None,
object_type: Type | None = None,
Expand Down Expand Up @@ -1529,7 +1530,7 @@ def check_call(
self,
callee: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None = None,
callable_node: Expression | None = None,
Expand Down Expand Up @@ -1651,7 +1652,7 @@ def check_callable_call(
self,
callee: CallableType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
arg_names: Sequence[str | None] | None,
callable_node: Expression | None,
Expand Down Expand Up @@ -1934,7 +1935,7 @@ def infer_arg_types_in_context(
self,
callee: CallableType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
formal_to_actual: list[list[int]],
) -> list[Type]:
"""Infer argument expression types using a callable type as context.
Expand Down Expand Up @@ -2056,7 +2057,7 @@ def infer_function_type_arguments(
self,
callee_type: CallableType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
need_refresh: bool,
Expand Down Expand Up @@ -2115,7 +2116,7 @@ def infer_function_type_arguments(
if (
callee_type.special_sig == "dict"
and len(inferred_args) == 2
and (ARG_NAMED in arg_kinds or ARG_STAR2 in arg_kinds)
and (ARG_NAMED in arg_kinds or arg_kinds.has_star2)
):
# HACK: Infer str key type for dict(...) with keyword args. The type system
# can't represent this so we special case it, as this is a pretty common
Expand Down Expand Up @@ -2195,7 +2196,7 @@ def infer_function_type_arguments_pass2(
self,
callee_type: CallableType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
old_inferred_args: Sequence[Type | None],
Expand Down Expand Up @@ -2330,7 +2331,7 @@ def check_argument_count(
self,
callee: CallableType,
actual_types: list[Type],
actual_kinds: list[ArgKind],
actual_kinds: ArgKinds,
actual_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
context: Context | None,
Expand Down Expand Up @@ -2410,7 +2411,7 @@ def check_for_extra_actual_arguments(
self,
callee: CallableType,
actual_types: list[Type],
actual_kinds: list[ArgKind],
actual_kinds: ArgKinds,
actual_names: Sequence[str | None] | None,
all_actuals: dict[int, int],
context: Context,
Expand Down Expand Up @@ -2484,7 +2485,7 @@ def missing_classvar_callable_note(
def check_argument_types(
self,
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
args: list[Expression],
callee: CallableType,
formal_to_actual: list[list[int]],
Expand Down Expand Up @@ -2671,7 +2672,7 @@ def check_overload_call(
self,
callee: Overloaded,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
callable_name: str | None,
object_type: Type | None,
Expand Down Expand Up @@ -2813,7 +2814,7 @@ def check_overload_call(
def plausible_overload_call_targets(
self,
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
overload: Overloaded,
) -> list[CallableType]:
Expand Down Expand Up @@ -2874,7 +2875,7 @@ def infer_overload_return_type(
plausible_targets: list[CallableType],
args: list[Expression],
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
callable_name: str | None,
object_type: Type | None,
Expand Down Expand Up @@ -2957,7 +2958,7 @@ def overload_erased_call_targets(
self,
plausible_targets: list[CallableType],
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
args: list[Expression],
context: Context,
Expand Down Expand Up @@ -3017,7 +3018,7 @@ def union_overload_result(
plausible_targets: list[CallableType],
args: list[Expression],
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
callable_name: str | None,
object_type: Type | None,
Expand Down Expand Up @@ -3217,7 +3218,7 @@ def combine_function_signatures(self, types: list[ProperType]) -> AnyType | Call
def erased_signature_similarity(
self,
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
args: list[Expression],
callee: CallableType,
Expand Down Expand Up @@ -3298,7 +3299,7 @@ def check_union_call(
self,
callee: UnionType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
context: Context,
) -> tuple[Type, Type]:
Expand Down Expand Up @@ -3857,7 +3858,7 @@ def check_method_call_by_name(
method: str,
base_type: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
original_type: Type | None = None,
self_type: Type | None = None,
Expand Down Expand Up @@ -3896,7 +3897,7 @@ def check_union_method_call_by_name(
method: str,
base_type: UnionType,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
original_type: Type | None = None,
) -> tuple[Type, Type]:
Expand Down Expand Up @@ -3925,7 +3926,7 @@ def check_method_call(
base_type: Type,
method_type: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
context: Context,
) -> tuple[Type, Type]:
"""Type check a call to a method with the given name and type on an object.
Expand Down Expand Up @@ -5531,7 +5532,7 @@ def infer_lambda_type_using_context(
# See https://github.com/python/mypy/issues/9927
return None, None

arg_kinds = [arg.kind for arg in e.arguments]
arg_kinds = ArgKinds(arg.kind for arg in e.arguments)

if callable_ctx.is_ellipsis_args or ctx.param_spec() is not None:
# Fill in Any arguments to match the arguments of the lambda.
Expand All @@ -5542,7 +5543,7 @@ def infer_lambda_type_using_context(
arg_names=e.arg_names.copy(),
)

if ARG_STAR in arg_kinds or ARG_STAR2 in arg_kinds:
if arg_kinds.has_any_star:
# TODO treat this case appropriately
return callable_ctx, None

Expand Down Expand Up @@ -6445,7 +6446,7 @@ def is_non_empty_tuple(t: Type) -> bool:


def is_duplicate_mapping(
mapping: list[int], actual_types: list[Type], actual_kinds: list[ArgKind]
mapping: list[int], actual_types: list[Type], actual_kinds: ArgKinds
) -> bool:
return (
len(mapping) > 1
Expand Down Expand Up @@ -6585,7 +6586,7 @@ def any_causes_overload_ambiguity(
items: list[CallableType],
return_types: list[Type],
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
) -> bool:
"""May an argument containing 'Any' cause ambiguous result type on call to overloaded function?
Expand Down
4 changes: 2 additions & 2 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ARG_STAR2,
CONTRAVARIANT,
COVARIANT,
ArgKind,
ArgKinds,
TypeInfo,
)
from mypy.type_visitor import ALL_STRATEGY, BoolTypeQuery
Expand Down Expand Up @@ -110,7 +110,7 @@ def __eq__(self, other: object) -> bool:
def infer_constraints_for_callable(
callee: CallableType,
arg_types: Sequence[Type | None],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
context: ArgumentInferContext,
Expand Down
10 changes: 6 additions & 4 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
TYPE_VAR_KIND,
TYPE_VAR_TUPLE_KIND,
ArgKind,
ArgKinds,
Argument,
AssertStmt,
AssignmentExpr,
Expand Down Expand Up @@ -1634,9 +1635,10 @@ def visit_Call(self, n: Call) -> CallExpr:
arg_types = self.translate_expr_list(
[a.value if isinstance(a, Starred) else a for a in args] + [k.value for k in keywords]
)
arg_kinds = [ARG_STAR if type(a) is Starred else ARG_POS for a in args] + [
ARG_STAR2 if arg is None else ARG_NAMED for arg in keyword_names
]
arg_kinds = ArgKinds(
[ARG_STAR if type(a) is Starred else ARG_POS for a in args]
+ [ARG_STAR2 if arg is None else ARG_NAMED for arg in keyword_names]
)
e = CallExpr(
self.visit(n.func),
arg_types,
Expand Down Expand Up @@ -1688,7 +1690,7 @@ def visit_JoinedStr(self, n: ast3.JoinedStr) -> Expression:
del strs_to_join.items[-1:]
join_method = MemberExpr(empty_string, "join")
join_method.set_line(empty_string)
result_expression = CallExpr(join_method, [strs_to_join], [ARG_POS], [None])
result_expression = CallExpr(join_method, [strs_to_join], ArgKinds([ARG_POS]), [None])
return self.set_line(result_expression, n)

# FormattedValue(expr value)
Expand Down
4 changes: 2 additions & 2 deletions mypy/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
infer_constraints,
infer_constraints_for_callable,
)
from mypy.nodes import ArgKind
from mypy.nodes import ArgKinds
from mypy.solve import solve_constraints
from mypy.types import CallableType, Instance, Type, TypeVarLikeType

Expand All @@ -33,7 +33,7 @@ class ArgumentInferContext(NamedTuple):
def infer_function_type_arguments(
callee_type: CallableType,
arg_types: Sequence[Type | None],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: Sequence[str | None] | None,
formal_to_actual: list[list[int]],
context: ArgumentInferContext,
Expand Down
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
COVARIANT,
SYMBOL_FUNCBASE_TYPES,
ArgKind,
ArgKinds,
CallExpr,
ClassDef,
Context,
Expand Down Expand Up @@ -2528,7 +2529,7 @@ def quote_type_string(type_string: str) -> str:

def format_callable_args(
arg_types: list[Type],
arg_kinds: list[ArgKind],
arg_kinds: ArgKinds,
arg_names: list[str | None],
format: Callable[[Type], str],
verbosity: int,
Expand Down
Loading
Loading