Skip to content

Commit e6f816a

Browse files
committed
Merge branch 'argkinds' of https://github.com/BobTheBuidler/mypy into argkinds
2 parents 667b9f5 + bf50db1 commit e6f816a

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

mypy/nodes.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import os
77
from abc import abstractmethod
88
from collections import defaultdict
9-
from collections.abc import Iterator, Sequence
9+
from collections.abc import Iterable, Iterator, Sequence
1010
from enum import Enum, unique
11-
from typing import TYPE_CHECKING, Any, Callable, Final, Iterable, Optional, TypeVar, Union, cast
11+
from typing import TYPE_CHECKING, Any, Callable, Final, Optional, TypeVar, Union, cast
1212
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard
1313

1414
from mypy_extensions import mypyc_attr, trait
@@ -2210,29 +2210,38 @@ def is_star(self) -> bool:
22102210
@mypyc_attr(native_class=False)
22112211
class ArgKinds(list[ArgKind]):
22122212
def __init__(self, values: Iterable[ArgKind] = None) -> None:
2213-
self._count_cache: dict[ArgKind, int] = {}
2214-
self._index_cache: dict[ArgKind, int] = {}
2213+
self.__count_cache: dict[ArgKind, int] = {}
2214+
self.__index_cache: dict[ArgKind, int] = {}
2215+
22152216
@property
22162217
def positional_only(self) -> bool:
22172218
return all(kind == ARG_POS for kind in self)
2219+
22182220
@property
22192221
def has_star(self) -> bool:
22202222
return ARG_STAR in self
2223+
22212224
@property
22222225
def has_star2(self) -> bool:
22232226
return ARG_STAR2 in self
2227+
22242228
@property
22252229
def has_any_star(self) -> bool:
22262230
return any(kind.is_star() for kind in self)
2231+
2232+
def copy(self) -> ArgKinds:
2233+
return ArgKinds(kind for kind in self)
2234+
22272235
def count(self, kind: ArgKind) -> int:
2228-
count = self._count_cache.get(kind)
2236+
count = self.__count_cache.get(kind)
22292237
if count is None:
2230-
count = self._count_cache[kind] = super().count(kind)
2238+
count = self.__count_cache[kind] = super().count(kind)
22312239
return count
2240+
22322241
def index(self, kind: ArgKind) -> int:
2233-
index = self._index_cache.get(kind)
2242+
index = self.__index_cache.get(kind)
22342243
if index is None:
2235-
index = self._index_cache[kind] = super().index(kind)
2244+
index = self.__index_cache[kind] = super().index(kind)
22362245
return index
22372246

22382247

@@ -4827,9 +4836,7 @@ def get_member_expr_fullname(expr: MemberExpr) -> str | None:
48274836
}
48284837

48294838

4830-
def check_arg_kinds(
4831-
arg_kinds: ArgKinds, nodes: list[T], fail: Callable[[str, T], None]
4832-
) -> None:
4839+
def check_arg_kinds(arg_kinds: ArgKinds, nodes: list[T], fail: Callable[[str, T], None]) -> None:
48334840
is_var_arg = False
48344841
is_kw_arg = False
48354842
seen_named = False

mypy/test/testinfer.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
from mypy.argmap import map_actuals_to_formals
66
from mypy.checker import DisjointDict, group_comparison_operands
77
from mypy.literals import Key
8-
from mypy.nodes import ARG_NAMED, ARG_OPT, ARG_POS, ARG_STAR, ARG_STAR2, ArgKind, ArgKinds, NameExpr
8+
from mypy.nodes import (
9+
ARG_NAMED,
10+
ARG_OPT,
11+
ARG_POS,
12+
ARG_STAR,
13+
ARG_STAR2,
14+
ArgKind,
15+
ArgKinds,
16+
NameExpr,
17+
)
918
from mypy.test.helpers import Suite, assert_equal
1019
from mypy.test.typefixture import TypeFixture
1120
from mypy.types import AnyType, TupleType, Type, TypeOfAny
@@ -118,9 +127,7 @@ def assert_vararg_map(
118127
assert_equal(result, expected)
119128

120129

121-
def expand_caller_kinds(
122-
kinds_or_names: list[ArgKind | str],
123-
) -> tuple[ArgKinds, list[str | None]]:
130+
def expand_caller_kinds(kinds_or_names: list[ArgKind | str]) -> tuple[ArgKinds, list[str | None]]:
124131
kinds = []
125132
names: list[str | None] = []
126133
for k in kinds_or_names:

mypy/types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@
3232
write_str_opt_list,
3333
write_tag,
3434
)
35-
from mypy.nodes import ARG_KINDS, ARG_POS, ARG_STAR, ARG_STAR2, INVARIANT, ArgKind, ArgKinds, SymbolNode
35+
from mypy.nodes import (
36+
ARG_KINDS,
37+
ARG_POS,
38+
ARG_STAR,
39+
ARG_STAR2,
40+
INVARIANT,
41+
ArgKind,
42+
ArgKinds,
43+
SymbolNode,
44+
)
3645
from mypy.options import Options
3746
from mypy.state import state
3847
from mypy.util import IdMapper

mypyc/irbuild/function.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,7 @@ def f(builder: IRBuilder, x: object) -> int: ...
693693

694694
# We can do a passthrough *args/**kwargs with a native call, but if the
695695
# args need to get distributed out to arguments, we just let python handle it
696-
if arg_kinds.has_any_star and any(
697-
not arg.kind.is_star() for arg in target.decl.sig.args
698-
):
696+
if arg_kinds.has_any_star and any(not arg.kind.is_star() for arg in target.decl.sig.args):
699697
do_pycall = True
700698

701699
if do_pycall:

0 commit comments

Comments
 (0)