Skip to content

Commit ed35507

Browse files
committed
Revert "Mark varargs as pos-only"
This reverts commit 8a4cd57.
1 parent d98e716 commit ed35507

15 files changed

+50
-56
lines changed

mypy/fastparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ def transform_args(
11011101

11021102
# *arg
11031103
if args.vararg is not None:
1104-
new_args.append(self.make_argument(args.vararg, None, ARG_STAR, no_type_check, True))
1104+
new_args.append(self.make_argument(args.vararg, None, ARG_STAR, no_type_check))
11051105
names.append(args.vararg)
11061106

11071107
# keyword-only arguments with defaults

mypy/stubgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def _get_func_args(self, o: FuncDef, ctx: FunctionContext) -> list[ArgSig]:
556556
if not isinstance(get_proper_type(annotated_type), AnyType):
557557
typename = self.print_annotation(annotated_type)
558558

559-
if actually_pos_only_args and (arg_.pos_only and kind != ARG_STAR):
559+
if actually_pos_only_args and arg_.pos_only:
560560
pos_only_marker_position += 1
561561

562562
if kind.is_named() and not any(arg.name.startswith("*") for arg in args):

test-data/unit/check-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7464,7 +7464,7 @@ class A:
74647464
class B(A):
74657465
pass
74667466

7467-
reveal_type(A.__init_subclass__) # N: Revealed type is "def (*Any, **kwargs: Any) -> Any"
7467+
reveal_type(A.__init_subclass__) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> Any"
74687468
[builtins fixtures/object_with_init_subclass.pyi]
74697469

74707470
[case testInitSubclassUnannotatedMulti]

test-data/unit/check-inference.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,7 +3847,7 @@ def Negate(count: int, /, metric: Metric[float]) -> float: ...
38473847
def Combine(count: int, m1: Metric[T], m2: Metric[T], /, *more: Metric[T]) -> T: ...
38483848

38493849
reveal_type(Negate) # N: Revealed type is "def (metric: __main__.Metric[builtins.float]) -> builtins.float"
3850-
reveal_type(Combine) # N: Revealed type is "def [T] (def () -> T`5, def () -> T`5, *def () -> T`5) -> T`5"
3850+
reveal_type(Combine) # N: Revealed type is "def [T] (def () -> T`5, def () -> T`5, *more: def () -> T`5) -> T`5"
38513851

38523852
def m1() -> float: ...
38533853
def m2() -> float: ...

test-data/unit/check-modules.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,12 +3208,12 @@ class Bar(Foo):
32083208
[out1]
32093209
tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo"
32103210
tmp/b.py:3: note: Superclass:
3211-
tmp/b.py:3: note: def frobnicate(self, x: str, *Any, **kwargs: Any) -> Any
3211+
tmp/b.py:3: note: def frobnicate(self, x: str, *args: Any, **kwargs: Any) -> Any
32123212
tmp/b.py:3: note: Subclass:
32133213
tmp/b.py:3: note: def frobnicate(self) -> None
32143214
[out2]
32153215
tmp/b.py:3: error: Signature of "frobnicate" incompatible with supertype "Foo"
32163216
tmp/b.py:3: note: Superclass:
3217-
tmp/b.py:3: note: def frobnicate(self, x: str, *Any, **kwargs: Any) -> Any
3217+
tmp/b.py:3: note: def frobnicate(self, x: str, *args: Any, **kwargs: Any) -> Any
32183218
tmp/b.py:3: note: Subclass:
3219-
tmp/b.py:3: note: def frobnicate(self, *int) -> None
3219+
tmp/b.py:3: note: def frobnicate(self, *args: int) -> None

test-data/unit/check-overloading.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ f(B(), B)
724724
f(B(), B, B)
725725
f(object()) # E: No overload variant of "f" matches argument type "object" \
726726
# N: Possible overload variants: \
727-
# N: def f(x: A, *Any) -> A \
728-
# N: def f(x: B, *Any) -> A
727+
# N: def f(x: A, *more: Any) -> A \
728+
# N: def f(x: B, *more: Any) -> A
729729
class A: pass
730730
class B: pass
731731
[builtins fixtures/list.pyi]
@@ -742,12 +742,12 @@ f(A(), B())
742742
f(A(), B(), B())
743743
f(A(), A(), B()) # E: No overload variant of "f" matches argument types "A", "A", "B" \
744744
# N: Possible overload variants: \
745-
# N: def f(x: A, *B) -> A \
746-
# N: def f(x: B, *A) -> A
745+
# N: def f(x: A, *more: B) -> A \
746+
# N: def f(x: B, *more: A) -> A
747747
f(A(), B(), A()) # E: No overload variant of "f" matches argument types "A", "B", "A" \
748748
# N: Possible overload variants: \
749-
# N: def f(x: A, *B) -> A \
750-
# N: def f(x: B, *A) -> A
749+
# N: def f(x: A, *more: B) -> A \
750+
# N: def f(x: B, *more: A) -> A
751751
class A: pass
752752
class B: pass
753753
[builtins fixtures/list.pyi]
@@ -1219,13 +1219,13 @@ def f(*x: str) -> str: pass
12191219
f(*(1,))() # E: No overload variant of "f" matches argument type "Tuple[int]" \
12201220
# N: Possible overload variants: \
12211221
# N: def f(x: int, y: str) -> int \
1222-
# N: def f(*str) -> str
1222+
# N: def f(*x: str) -> str
12231223
f(*('',))() # E: "str" not callable
12241224
f(*(1, ''))() # E: "int" not callable
12251225
f(*(1, '', 1))() # E: No overload variant of "f" matches argument type "Tuple[int, str, int]" \
12261226
# N: Possible overload variants: \
12271227
# N: def f(x: int, y: str) -> int \
1228-
# N: def f(*str) -> str
1228+
# N: def f(*x: str) -> str
12291229
[builtins fixtures/tuple.pyi]
12301230

12311231
[case testPreferExactSignatureMatchInOverload]
@@ -2543,7 +2543,7 @@ foo(*y) # E: No overload variant of "foo" matches argument type "List[str]" \
25432543
# N: Possible overload variants: \
25442544
# N: def foo(x: int) -> A \
25452545
# N: def foo(x: int, y: int) -> B \
2546-
# N: def foo(x: int, y: int, z: int, *int) -> C
2546+
# N: def foo(x: int, y: int, z: int, *args: int) -> C
25472547
[builtins fixtures/list.pyi]
25482548

25492549
[case testOverloadMultipleVarargDefinition]

test-data/unit/check-parameter-specification.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class C(Generic[P]):
414414

415415
c: C[Any]
416416
reveal_type(c) # N: Revealed type is "__main__.C[Any]"
417-
reveal_type(c.m) # N: Revealed type is "def (*Any, **kwargs: Any) -> builtins.int"
417+
reveal_type(c.m) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> builtins.int"
418418
c.m(4, 6, y='x')
419419
c = c
420420

@@ -603,18 +603,18 @@ def f5(x: X[int, int]) -> str: ... # E: Can only replace ParamSpec with a param
603603
def bar(x: int, *args: bool) -> int: ...
604604
def add(x: Callable[P, int]) -> Callable[Concatenate[str, P], bool]: ...
605605

606-
reveal_type(add(bar)) # N: Revealed type is "def (builtins.str, x: builtins.int, *builtins.bool) -> builtins.bool"
606+
reveal_type(add(bar)) # N: Revealed type is "def (builtins.str, x: builtins.int, *args: builtins.bool) -> builtins.bool"
607607

608608
def remove(x: Callable[Concatenate[int, P], int]) -> Callable[P, bool]: ...
609609

610-
reveal_type(remove(bar)) # N: Revealed type is "def (*builtins.bool) -> builtins.bool"
610+
reveal_type(remove(bar)) # N: Revealed type is "def (*args: builtins.bool) -> builtins.bool"
611611

612612
def transform(
613613
x: Callable[Concatenate[int, P], int]
614614
) -> Callable[Concatenate[str, P], bool]: ...
615615

616616
# In the PEP, "__a" appears. What is that? Autogenerated names? To what spec?
617-
reveal_type(transform(bar)) # N: Revealed type is "def (builtins.str, *builtins.bool) -> builtins.bool"
617+
reveal_type(transform(bar)) # N: Revealed type is "def (builtins.str, *args: builtins.bool) -> builtins.bool"
618618

619619
# CASE 4
620620
def expects_int_first(x: Callable[Concatenate[int, P], int]) -> None: ...
@@ -1776,9 +1776,9 @@ def bar(b: A[P]) -> A[Concatenate[int, P]]:
17761776
return b # E: Incompatible return value type (got "A[P]", expected "A[[int, **P]]") \
17771777
# N: Following member(s) of "A[P]" have conflicts: \
17781778
# N: Expected: \
1779-
# N: def foo(self, int, /, *P.args, **kwargs: P.kwargs) -> Any \
1779+
# N: def foo(self, int, /, *args: P.args, **kwargs: P.kwargs) -> Any \
17801780
# N: Got: \
1781-
# N: def foo(self, *P.args, **kwargs: P.kwargs) -> Any
1781+
# N: def foo(self, *args: P.args, **kwargs: P.kwargs) -> Any
17821782
[builtins fixtures/paramspec.pyi]
17831783

17841784
[case testParamSpecPrefixSubtypingValidNonStrict]
@@ -1818,9 +1818,9 @@ def bar(b: B[P]) -> A[Concatenate[int, P]]:
18181818
return b # E: Incompatible return value type (got "B[P]", expected "A[[int, **P]]") \
18191819
# N: Following member(s) of "B[P]" have conflicts: \
18201820
# N: Expected: \
1821-
# N: def foo(self, a: int, int, /, *P.args, **kwargs: P.kwargs) -> Any \
1821+
# N: def foo(self, a: int, int, /, *args: P.args, **kwargs: P.kwargs) -> Any \
18221822
# N: Got: \
1823-
# N: def foo(self, a: int, b: int, *P.args, **kwargs: P.kwargs) -> Any
1823+
# N: def foo(self, a: int, b: int, *args: P.args, **kwargs: P.kwargs) -> Any
18241824
[builtins fixtures/paramspec.pyi]
18251825

18261826
[case testParamSpecDecoratorOverload]

test-data/unit/check-protocols.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,15 +2287,15 @@ func2(x)
22872287
main:14: error: Argument 1 to "func1" has incompatible type "B"; expected "A"
22882288
main:14: note: Following member(s) of "B" have conflicts:
22892289
main:14: note: Expected:
2290-
main:14: note: def execute(self, statement: Any, *Any, **kwargs: Any) -> None
2290+
main:14: note: def execute(self, statement: Any, *args: Any, **kwargs: Any) -> None
22912291
main:14: note: Got:
2292-
main:14: note: def execute(self, stmt: Any, *Any, **kwargs: Any) -> None
2292+
main:14: note: def execute(self, stmt: Any, *args: Any, **kwargs: Any) -> None
22932293
main:15: error: Argument 1 to "func2" has incompatible type "B"; expected "Optional[A]"
22942294
main:15: note: Following member(s) of "B" have conflicts:
22952295
main:15: note: Expected:
2296-
main:15: note: def execute(self, statement: Any, *Any, **kwargs: Any) -> None
2296+
main:15: note: def execute(self, statement: Any, *args: Any, **kwargs: Any) -> None
22972297
main:15: note: Got:
2298-
main:15: note: def execute(self, stmt: Any, *Any, **kwargs: Any) -> None
2298+
main:15: note: def execute(self, stmt: Any, *args: Any, **kwargs: Any) -> None
22992299

23002300
[case testDontShowNotesForTupleAndIterableProtocol]
23012301
from typing import Iterable, Sequence, Protocol, NamedTuple
@@ -2375,11 +2375,11 @@ x: P = C()
23752375
main:10: error: Incompatible types in assignment (expression has type "C", variable has type "P")
23762376
main:10: note: Following member(s) of "C" have conflicts:
23772377
main:10: note: Expected:
2378-
main:10: note: def meth(self, x: int, *str) -> None
2378+
main:10: note: def meth(self, x: int, *args: str) -> None
23792379
main:10: note: Got:
23802380
main:10: note: def meth(self) -> int
23812381
main:10: note: Expected:
2382-
main:10: note: def other(self, *Any, hint: Optional[str] = ..., **kwargs: str) -> None
2382+
main:10: note: def other(self, *args: Any, hint: Optional[str] = ..., **kwargs: str) -> None
23832383
main:10: note: Got:
23842384
main:10: note: def other(self) -> int
23852385

test-data/unit/check-python311.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class C(Generic[T, *Ts]):
101101

102102
ci: C[*tuple[int, ...]]
103103
reveal_type(ci) # N: Revealed type is "__main__.C[Unpack[builtins.tuple[builtins.int, ...]]]"
104-
reveal_type(ci.meth) # N: Revealed type is "def (*builtins.int) -> builtins.int"
104+
reveal_type(ci.meth) # N: Revealed type is "def (*args: builtins.int) -> builtins.int"
105105
c3: C[str, str, str]
106106
reveal_type(c3) # N: Revealed type is "__main__.C[builtins.str, builtins.str, builtins.str]"
107107

test-data/unit/check-typevar-tuple.test

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,11 @@ def foo2(*args: Unpack[Tuple[bool, Unpack[Tuple[int, str]], bool]]) -> None:
448448

449449
# It is hard to normalize callable types in definition, because there is deep relation between `FuncDef.type`
450450
# and `FuncDef.arguments`, therefore various typeops need to be sure to normalize Callable types before using them.
451-
reveal_type(foo2) # N: Revealed type is "def (*Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])"
451+
reveal_type(foo2) # N: Revealed type is "def (*args: Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])"
452452

453453
class C:
454454
def foo2(self, *args: Unpack[Tuple[bool, Unpack[Tuple[int, str]], bool]]) -> None: ...
455-
reveal_type(C().foo2) # N: Revealed type is "def (*Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])"
455+
reveal_type(C().foo2) # N: Revealed type is "def (*args: Unpack[Tuple[builtins.bool, builtins.int, builtins.str, builtins.bool]])"
456456
[builtins fixtures/tuple.pyi]
457457

458458
[case testTypeVarTuplePep646TypeVarStarArgsVariableLengthTuple]
@@ -2015,7 +2015,7 @@ from typing_extensions import TypeVarTuple, Unpack
20152015
Ts = TypeVarTuple("Ts")
20162016
class B(Generic[Unpack[Ts]]):
20172017
def __init__(self, x: Tuple[Unpack[Ts]], *args: Unpack[Ts]) -> None: ...
2018-
reveal_type(B) # N: Revealed type is "def [Ts] (x: Tuple[Unpack[Ts`1]], *Unpack[Ts`1]) -> __main__.B[Unpack[Ts`1]]"
2018+
reveal_type(B) # N: Revealed type is "def [Ts] (x: Tuple[Unpack[Ts`1]], *args: Unpack[Ts`1]) -> __main__.B[Unpack[Ts`1]]"
20192019

20202020
T = TypeVar("T")
20212021
S = TypeVar("S")
@@ -2140,7 +2140,7 @@ get_items(b) # E: Argument 1 to "get_items" has incompatible type "Bad"; expect
21402140
match(b) # E: Argument 1 to "match" has incompatible type "Bad"; expected "PC[Unpack[Tuple[Never, ...]]]" \
21412141
# N: Following member(s) of "Bad" have conflicts: \
21422142
# N: Expected: \
2143-
# N: def meth(self, *Never) -> None \
2143+
# N: def meth(self, *args: Never) -> None \
21442144
# N: Got: \
21452145
# N: def meth(self, *, named: int) -> None
21462146
[builtins fixtures/tuple.pyi]
@@ -2178,14 +2178,14 @@ class Keywords(TypedDict):
21782178
Ints = Tuple[int, ...]
21792179

21802180
def f(*args: Unpack[Ints], other: str = "no", **kwargs: Unpack[Keywords]) -> None: ...
2181-
reveal_type(f) # N: Revealed type is "def (*builtins.int, other: builtins.str =, **kwargs: Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])"
2181+
reveal_type(f) # N: Revealed type is "def (*args: builtins.int, other: builtins.str =, **kwargs: Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])"
21822182
f(1, 2, a="a", b="b") # OK
21832183
f(1, 2, 3) # E: Missing named argument "a" for "f" \
21842184
# E: Missing named argument "b" for "f"
21852185

21862186
Ts = TypeVarTuple("Ts")
21872187
def g(*args: Unpack[Ts], other: str = "no", **kwargs: Unpack[Keywords]) -> None: ...
2188-
reveal_type(g) # N: Revealed type is "def [Ts] (*Unpack[Ts`-1], other: builtins.str =, **kwargs: Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])"
2188+
reveal_type(g) # N: Revealed type is "def [Ts] (*args: Unpack[Ts`-1], other: builtins.str =, **kwargs: Unpack[TypedDict('__main__.Keywords', {'a': builtins.str, 'b': builtins.str})])"
21892189
g(1, 2, a="a", b="b") # OK
21902190
g(1, 2, 3) # E: Missing named argument "a" for "g" \
21912191
# E: Missing named argument "b" for "g"
@@ -2194,15 +2194,15 @@ def bad(
21942194
*args: Unpack[Keywords], # E: "Keywords" cannot be unpacked (must be tuple or TypeVarTuple)
21952195
**kwargs: Unpack[Ints], # E: Unpack item in ** argument must be a TypedDict
21962196
) -> None: ...
2197-
reveal_type(bad) # N: Revealed type is "def (*Any, **kwargs: Any)"
2197+
reveal_type(bad) # N: Revealed type is "def (*args: Any, **kwargs: Any)"
21982198

21992199
def bad2(
22002200
one: int,
22012201
*args: Unpack[Keywords], # E: "Keywords" cannot be unpacked (must be tuple or TypeVarTuple)
22022202
other: str = "no",
22032203
**kwargs: Unpack[Ints], # E: Unpack item in ** argument must be a TypedDict
22042204
) -> None: ...
2205-
reveal_type(bad2) # N: Revealed type is "def (one: builtins.int, *Any, other: builtins.str =, **kwargs: Any)"
2205+
reveal_type(bad2) # N: Revealed type is "def (one: builtins.int, *args: Any, other: builtins.str =, **kwargs: Any)"
22062206
[builtins fixtures/dict.pyi]
22072207
[typing fixtures/typing-typeddict.pyi]
22082208

@@ -2429,7 +2429,7 @@ Ts = TypeVarTuple("Ts")
24292429
@cm
24302430
def test(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ...
24312431

2432-
reveal_type(test) # N: Revealed type is "def [Ts] (*Unpack[Ts`-1]) -> __main__.CM[Tuple[Unpack[Ts`-1]]]"
2432+
reveal_type(test) # N: Revealed type is "def [Ts] (*args: Unpack[Ts`-1]) -> __main__.CM[Tuple[Unpack[Ts`-1]]]"
24332433
reveal_type(test(1, 2, 3)) # N: Revealed type is "__main__.CM[Tuple[Literal[1]?, Literal[2]?, Literal[3]?]]"
24342434
[builtins fixtures/tuple.pyi]
24352435

@@ -2447,7 +2447,7 @@ Ts = TypeVarTuple("Ts")
24472447
@cm # E: Argument 1 to "cm" has incompatible type "Callable[[VarArg(Unpack[Ts])], Tuple[Unpack[Ts]]]"; expected "Callable[[VarArg(Never)], List[Never]]"
24482448
def test(*args: Unpack[Ts]) -> Tuple[Unpack[Ts]]: ...
24492449

2450-
reveal_type(test) # N: Revealed type is "def (*Never) -> __main__.CM[Never]"
2450+
reveal_type(test) # N: Revealed type is "def (*args: Never) -> __main__.CM[Never]"
24512451
[builtins fixtures/tuple.pyi]
24522452

24532453
[case testTypeVarTupleAgainstParamSpecActualPrefix]
@@ -2465,7 +2465,7 @@ Ts = TypeVarTuple("Ts")
24652465
@cm
24662466
def test(x: T, *args: Unpack[Ts]) -> Tuple[T, Unpack[Ts]]: ...
24672467

2468-
reveal_type(test) # N: Revealed type is "def [T, Ts] (builtins.list[T`2], *Unpack[Ts`-2]) -> __main__.CM[Tuple[T`2, Unpack[Ts`-2]]]"
2468+
reveal_type(test) # N: Revealed type is "def [T, Ts] (builtins.list[T`2], *args: Unpack[Ts`-2]) -> __main__.CM[Tuple[T`2, Unpack[Ts`-2]]]"
24692469
[builtins fixtures/tuple.pyi]
24702470

24712471
[case testMixingTypeVarTupleAndParamSpec]
@@ -2585,7 +2585,7 @@ class C(Generic[Unpack[Ts]]):
25852585
def foo(self, *args: Unpack[Ts]) -> None: ...
25862586

25872587
c: C[Unpack[tuple[int, ...]]]
2588-
reveal_type(c.foo) # N: Revealed type is "def (*builtins.int)"
2588+
reveal_type(c.foo) # N: Revealed type is "def (*args: builtins.int)"
25892589
[builtins fixtures/tuple.pyi]
25902590

25912591
[case testTypeVarTupleJoinInstanceTypeVar]

0 commit comments

Comments
 (0)