Skip to content

Commit 3ed2b2e

Browse files
committed
chore: refactor with ArgKinds
1 parent 4171da0 commit 3ed2b2e

File tree

15 files changed

+120
-95
lines changed

15 files changed

+120
-95
lines changed

mypy/checker_shared.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from mypy.errors import ErrorWatcher
1414
from mypy.message_registry import ErrorMessage
1515
from mypy.nodes import (
16-
ArgKind,
16+
ArgKinds,
1717
Context,
1818
Expression,
1919
FuncItem,
@@ -69,7 +69,7 @@ def check_call(
6969
self,
7070
callee: Type,
7171
args: list[Expression],
72-
arg_kinds: list[ArgKind],
72+
arg_kinds: ArgKinds,
7373
context: Context,
7474
arg_names: Sequence[str | None] | None = None,
7575
callable_node: Expression | None = None,
@@ -85,7 +85,7 @@ def transform_callee_type(
8585
callable_name: str | None,
8686
callee: Type,
8787
args: list[Expression],
88-
arg_kinds: list[ArgKind],
88+
arg_kinds: ArgKinds,
8989
context: Context,
9090
arg_names: Sequence[str | None] | None = None,
9191
object_type: Type | None = None,
@@ -102,7 +102,7 @@ def check_method_call_by_name(
102102
method: str,
103103
base_type: Type,
104104
args: list[Expression],
105-
arg_kinds: list[ArgKind],
105+
arg_kinds: ArgKinds,
106106
context: Context,
107107
original_type: Type | None = None,
108108
) -> tuple[Type, Type]:

mypy/checkexpr.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
REVEAL_LOCALS,
4444
REVEAL_TYPE,
4545
ArgKind,
46+
ArgKinds,
4647
AssertTypeExpr,
4748
AssignmentExpr,
4849
AwaitExpr,
@@ -772,7 +773,7 @@ def check_protocol_issubclass(self, e: CallExpr) -> None:
772773
def check_typeddict_call(
773774
self,
774775
callee: TypedDictType,
775-
arg_kinds: list[ArgKind],
776+
arg_kinds: ArgKinds,
776777
arg_names: Sequence[str | None],
777778
args: list[Expression],
778779
context: Context,
@@ -1213,7 +1214,7 @@ def try_infer_partial_value_type_from_call(
12131214
def apply_function_plugin(
12141215
self,
12151216
callee: CallableType,
1216-
arg_kinds: list[ArgKind],
1217+
arg_kinds: ArgKinds,
12171218
arg_types: list[Type],
12181219
arg_names: Sequence[str | None] | None,
12191220
formal_to_actual: list[list[int]],
@@ -1237,7 +1238,7 @@ def apply_function_plugin(
12371238
formal_arg_types: list[list[Type]] = [[] for _ in range(num_formals)]
12381239
formal_arg_exprs: list[list[Expression]] = [[] for _ in range(num_formals)]
12391240
formal_arg_names: list[list[str | None]] = [[] for _ in range(num_formals)]
1240-
formal_arg_kinds: list[list[ArgKind]] = [[] for _ in range(num_formals)]
1241+
formal_arg_kinds: list[ArgKinds] = [[] for _ in range(num_formals)]
12411242
for formal, actuals in enumerate(formal_to_actual):
12421243
for actual in actuals:
12431244
formal_arg_types[formal].append(arg_types[actual])
@@ -1287,7 +1288,7 @@ def apply_signature_hook(
12871288
self,
12881289
callee: FunctionLike,
12891290
args: list[Expression],
1290-
arg_kinds: list[ArgKind],
1291+
arg_kinds: ArgKinds,
12911292
arg_names: Sequence[str | None] | None,
12921293
hook: Callable[[list[list[Expression]], CallableType], FunctionLike],
12931294
) -> FunctionLike:
@@ -1319,7 +1320,7 @@ def apply_function_signature_hook(
13191320
self,
13201321
callee: FunctionLike,
13211322
args: list[Expression],
1322-
arg_kinds: list[ArgKind],
1323+
arg_kinds: ArgKinds,
13231324
context: Context,
13241325
arg_names: Sequence[str | None] | None,
13251326
signature_hook: Callable[[FunctionSigContext], FunctionLike],
@@ -1337,7 +1338,7 @@ def apply_method_signature_hook(
13371338
self,
13381339
callee: FunctionLike,
13391340
args: list[Expression],
1340-
arg_kinds: list[ArgKind],
1341+
arg_kinds: ArgKinds,
13411342
context: Context,
13421343
arg_names: Sequence[str | None] | None,
13431344
object_type: Type,
@@ -1362,7 +1363,7 @@ def transform_callee_type(
13621363
callable_name: str | None,
13631364
callee: Type,
13641365
args: list[Expression],
1365-
arg_kinds: list[ArgKind],
1366+
arg_kinds: ArgKinds,
13661367
context: Context,
13671368
arg_names: Sequence[str | None] | None = None,
13681369
object_type: Type | None = None,
@@ -1529,7 +1530,7 @@ def check_call(
15291530
self,
15301531
callee: Type,
15311532
args: list[Expression],
1532-
arg_kinds: list[ArgKind],
1533+
arg_kinds: ArgKinds,
15331534
context: Context,
15341535
arg_names: Sequence[str | None] | None = None,
15351536
callable_node: Expression | None = None,
@@ -1651,7 +1652,7 @@ def check_callable_call(
16511652
self,
16521653
callee: CallableType,
16531654
args: list[Expression],
1654-
arg_kinds: list[ArgKind],
1655+
arg_kinds: ArgKinds,
16551656
context: Context,
16561657
arg_names: Sequence[str | None] | None,
16571658
callable_node: Expression | None,
@@ -1934,7 +1935,7 @@ def infer_arg_types_in_context(
19341935
self,
19351936
callee: CallableType,
19361937
args: list[Expression],
1937-
arg_kinds: list[ArgKind],
1938+
arg_kinds: ArgKinds,
19381939
formal_to_actual: list[list[int]],
19391940
) -> list[Type]:
19401941
"""Infer argument expression types using a callable type as context.
@@ -2056,7 +2057,7 @@ def infer_function_type_arguments(
20562057
self,
20572058
callee_type: CallableType,
20582059
args: list[Expression],
2059-
arg_kinds: list[ArgKind],
2060+
arg_kinds: ArgKinds,
20602061
arg_names: Sequence[str | None] | None,
20612062
formal_to_actual: list[list[int]],
20622063
need_refresh: bool,
@@ -2115,7 +2116,7 @@ def infer_function_type_arguments(
21152116
if (
21162117
callee_type.special_sig == "dict"
21172118
and len(inferred_args) == 2
2118-
and (ARG_NAMED in arg_kinds or ARG_STAR2 in arg_kinds)
2119+
and (ARG_NAMED in arg_kinds or arg_kinds.has_star2)
21192120
):
21202121
# HACK: Infer str key type for dict(...) with keyword args. The type system
21212122
# can't represent this so we special case it, as this is a pretty common
@@ -2195,7 +2196,7 @@ def infer_function_type_arguments_pass2(
21952196
self,
21962197
callee_type: CallableType,
21972198
args: list[Expression],
2198-
arg_kinds: list[ArgKind],
2199+
arg_kinds: ArgKinds,
21992200
arg_names: Sequence[str | None] | None,
22002201
formal_to_actual: list[list[int]],
22012202
old_inferred_args: Sequence[Type | None],
@@ -2330,7 +2331,7 @@ def check_argument_count(
23302331
self,
23312332
callee: CallableType,
23322333
actual_types: list[Type],
2333-
actual_kinds: list[ArgKind],
2334+
actual_kinds: ArgKinds,
23342335
actual_names: Sequence[str | None] | None,
23352336
formal_to_actual: list[list[int]],
23362337
context: Context | None,
@@ -2410,7 +2411,7 @@ def check_for_extra_actual_arguments(
24102411
self,
24112412
callee: CallableType,
24122413
actual_types: list[Type],
2413-
actual_kinds: list[ArgKind],
2414+
actual_kinds: ArgKinds,
24142415
actual_names: Sequence[str | None] | None,
24152416
all_actuals: dict[int, int],
24162417
context: Context,
@@ -2484,7 +2485,7 @@ def missing_classvar_callable_note(
24842485
def check_argument_types(
24852486
self,
24862487
arg_types: list[Type],
2487-
arg_kinds: list[ArgKind],
2488+
arg_kinds: ArgKinds,
24882489
args: list[Expression],
24892490
callee: CallableType,
24902491
formal_to_actual: list[list[int]],
@@ -2671,7 +2672,7 @@ def check_overload_call(
26712672
self,
26722673
callee: Overloaded,
26732674
args: list[Expression],
2674-
arg_kinds: list[ArgKind],
2675+
arg_kinds: ArgKinds,
26752676
arg_names: Sequence[str | None] | None,
26762677
callable_name: str | None,
26772678
object_type: Type | None,
@@ -2813,7 +2814,7 @@ def check_overload_call(
28132814
def plausible_overload_call_targets(
28142815
self,
28152816
arg_types: list[Type],
2816-
arg_kinds: list[ArgKind],
2817+
arg_kinds: ArgKinds,
28172818
arg_names: Sequence[str | None] | None,
28182819
overload: Overloaded,
28192820
) -> list[CallableType]:
@@ -2874,7 +2875,7 @@ def infer_overload_return_type(
28742875
plausible_targets: list[CallableType],
28752876
args: list[Expression],
28762877
arg_types: list[Type],
2877-
arg_kinds: list[ArgKind],
2878+
arg_kinds: ArgKinds,
28782879
arg_names: Sequence[str | None] | None,
28792880
callable_name: str | None,
28802881
object_type: Type | None,
@@ -2957,7 +2958,7 @@ def overload_erased_call_targets(
29572958
self,
29582959
plausible_targets: list[CallableType],
29592960
arg_types: list[Type],
2960-
arg_kinds: list[ArgKind],
2961+
arg_kinds: ArgKinds,
29612962
arg_names: Sequence[str | None] | None,
29622963
args: list[Expression],
29632964
context: Context,
@@ -3017,7 +3018,7 @@ def union_overload_result(
30173018
plausible_targets: list[CallableType],
30183019
args: list[Expression],
30193020
arg_types: list[Type],
3020-
arg_kinds: list[ArgKind],
3021+
arg_kinds: ArgKinds,
30213022
arg_names: Sequence[str | None] | None,
30223023
callable_name: str | None,
30233024
object_type: Type | None,
@@ -3217,7 +3218,7 @@ def combine_function_signatures(self, types: list[ProperType]) -> AnyType | Call
32173218
def erased_signature_similarity(
32183219
self,
32193220
arg_types: list[Type],
3220-
arg_kinds: list[ArgKind],
3221+
arg_kinds: ArgKinds,
32213222
arg_names: Sequence[str | None] | None,
32223223
args: list[Expression],
32233224
callee: CallableType,
@@ -3298,7 +3299,7 @@ def check_union_call(
32983299
self,
32993300
callee: UnionType,
33003301
args: list[Expression],
3301-
arg_kinds: list[ArgKind],
3302+
arg_kinds: ArgKinds,
33023303
arg_names: Sequence[str | None] | None,
33033304
context: Context,
33043305
) -> tuple[Type, Type]:
@@ -3857,7 +3858,7 @@ def check_method_call_by_name(
38573858
method: str,
38583859
base_type: Type,
38593860
args: list[Expression],
3860-
arg_kinds: list[ArgKind],
3861+
arg_kinds: ArgKinds,
38613862
context: Context,
38623863
original_type: Type | None = None,
38633864
self_type: Type | None = None,
@@ -3896,7 +3897,7 @@ def check_union_method_call_by_name(
38963897
method: str,
38973898
base_type: UnionType,
38983899
args: list[Expression],
3899-
arg_kinds: list[ArgKind],
3900+
arg_kinds: ArgKinds,
39003901
context: Context,
39013902
original_type: Type | None = None,
39023903
) -> tuple[Type, Type]:
@@ -3925,7 +3926,7 @@ def check_method_call(
39253926
base_type: Type,
39263927
method_type: Type,
39273928
args: list[Expression],
3928-
arg_kinds: list[ArgKind],
3929+
arg_kinds: ArgKinds,
39293930
context: Context,
39303931
) -> tuple[Type, Type]:
39313932
"""Type check a call to a method with the given name and type on an object.
@@ -5542,7 +5543,7 @@ def infer_lambda_type_using_context(
55425543
arg_names=e.arg_names.copy(),
55435544
)
55445545

5545-
if ARG_STAR in arg_kinds or ARG_STAR2 in arg_kinds:
5546+
if arg_kinds.has_any_star:
55465547
# TODO treat this case appropriately
55475548
return callable_ctx, None
55485549

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

64466447

64476448
def is_duplicate_mapping(
6448-
mapping: list[int], actual_types: list[Type], actual_kinds: list[ArgKind]
6449+
mapping: list[int], actual_types: list[Type], actual_kinds: ArgKinds
64496450
) -> bool:
64506451
return (
64516452
len(mapping) > 1
@@ -6585,7 +6586,7 @@ def any_causes_overload_ambiguity(
65856586
items: list[CallableType],
65866587
return_types: list[Type],
65876588
arg_types: list[Type],
6588-
arg_kinds: list[ArgKind],
6589+
arg_kinds: ArgKinds,
65896590
arg_names: Sequence[str | None] | None,
65906591
) -> bool:
65916592
"""May an argument containing 'Any' cause ambiguous result type on call to overloaded function?

mypy/constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ARG_STAR2,
1919
CONTRAVARIANT,
2020
COVARIANT,
21-
ArgKind,
21+
ArgKinds,
2222
TypeInfo,
2323
)
2424
from mypy.type_visitor import ALL_STRATEGY, BoolTypeQuery
@@ -110,7 +110,7 @@ def __eq__(self, other: object) -> bool:
110110
def infer_constraints_for_callable(
111111
callee: CallableType,
112112
arg_types: Sequence[Type | None],
113-
arg_kinds: list[ArgKind],
113+
arg_kinds: ArgKinds,
114114
arg_names: Sequence[str | None] | None,
115115
formal_to_actual: list[list[int]],
116116
context: ArgumentInferContext,

mypy/infer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
infer_constraints,
1212
infer_constraints_for_callable,
1313
)
14-
from mypy.nodes import ArgKind
14+
from mypy.nodes import ArgKinds
1515
from mypy.solve import solve_constraints
1616
from mypy.types import CallableType, Instance, Type, TypeVarLikeType
1717

@@ -33,7 +33,7 @@ class ArgumentInferContext(NamedTuple):
3333
def infer_function_type_arguments(
3434
callee_type: CallableType,
3535
arg_types: Sequence[Type | None],
36-
arg_kinds: list[ArgKind],
36+
arg_kinds: ArgKinds,
3737
arg_names: Sequence[str | None] | None,
3838
formal_to_actual: list[list[int]],
3939
context: ArgumentInferContext,

mypy/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
COVARIANT,
4242
SYMBOL_FUNCBASE_TYPES,
4343
ArgKind,
44+
ArgKinds,
4445
CallExpr,
4546
ClassDef,
4647
Context,
@@ -2528,7 +2529,7 @@ def quote_type_string(type_string: str) -> str:
25282529

25292530
def format_callable_args(
25302531
arg_types: list[Type],
2531-
arg_kinds: list[ArgKind],
2532+
arg_kinds: ArgKinds,
25322533
arg_names: list[str | None],
25332534
format: Callable[[Type], str],
25342535
verbosity: int,

0 commit comments

Comments
 (0)