Skip to content

Commit 1df4ac2

Browse files
authored
Update pos-only unit tests for Python 3.10.7 (#13660)
The CI has started to sporadically fail depending on whether 3.10.6 is picked up by GitHub Actions (okay) or 3.10.7 (not okay). For example: - https://github.com/python/mypy/actions/runs/3046671132/jobs/4909772702 - https://github.com/python/mypy/actions/runs/3046723692/jobs/4909887963 On Python 3.10.7 (but not on Python 3.10.6), mypy correctly rejects using PEP 570 syntax unless `--python-version` is set to 3.8 or higher (this is due to python/cpython#95935). However, this makes several unit tests fail. This PR updates those unit tests so that the CI passes on both 3.10.6 and 3.10.7
1 parent a784b48 commit 1df4ac2

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ reveal_type(f(n)) # N: Revealed type is "def (builtins.int, builtins.bytes) ->
573573
[builtins fixtures/paramspec.pyi]
574574

575575
[case testParamSpecConcatenateNamedArgs]
576-
# flags: --strict-concatenate
576+
# flags: --python-version 3.8 --strict-concatenate
577577
# this is one noticeable deviation from PEP but I believe it is for the better
578578
from typing_extensions import ParamSpec, Concatenate
579579
from typing import Callable, TypeVar
@@ -595,12 +595,14 @@ def f2(c: Callable[P, R]) -> Callable[Concatenate[int, P], R]:
595595
f2(lambda x: 42)(42, x=42)
596596
[builtins fixtures/paramspec.pyi]
597597
[out]
598-
main:10: error: invalid syntax
598+
main:10: error: invalid syntax; you likely need to run mypy using Python 3.8 or newer
599599
[out version>=3.8]
600600
main:17: error: Incompatible return value type (got "Callable[[Arg(int, 'x'), **P], R]", expected "Callable[[int, **P], R]")
601601
main:17: note: This may be because "result" has arguments named: "x"
602602

603603
[case testNonStrictParamSpecConcatenateNamedArgs]
604+
# flags: --python-version 3.8
605+
604606
# this is one noticeable deviation from PEP but I believe it is for the better
605607
from typing_extensions import ParamSpec, Concatenate
606608
from typing import Callable, TypeVar
@@ -622,7 +624,7 @@ def f2(c: Callable[P, R]) -> Callable[Concatenate[int, P], R]:
622624
f2(lambda x: 42)(42, x=42)
623625
[builtins fixtures/paramspec.pyi]
624626
[out]
625-
main:9: error: invalid syntax
627+
main:11: error: invalid syntax; you likely need to run mypy using Python 3.8 or newer
626628
[out version>=3.8]
627629

628630
[case testParamSpecConcatenateWithTypeVar]
@@ -644,6 +646,8 @@ reveal_type(n(42)) # N: Revealed type is "None"
644646
[builtins fixtures/paramspec.pyi]
645647

646648
[case testCallablesAsParameters]
649+
# flags: --python-version 3.8
650+
647651
# credits to https://github.com/microsoft/pyright/issues/2705
648652
from typing_extensions import ParamSpec, Concatenate
649653
from typing import Generic, Callable, Any
@@ -661,9 +665,9 @@ reveal_type(abc)
661665
bar(abc)
662666
[builtins fixtures/paramspec.pyi]
663667
[out]
664-
main:11: error: invalid syntax
668+
main:13: error: invalid syntax; you likely need to run mypy using Python 3.8 or newer
665669
[out version>=3.8]
666-
main:14: note: Revealed type is "__main__.Foo[[builtins.int, b: builtins.str]]"
670+
main:16: note: Revealed type is "__main__.Foo[[builtins.int, b: builtins.str]]"
667671

668672
[case testSolveParamSpecWithSelfType]
669673
from typing_extensions import ParamSpec, Concatenate

test-data/unit/check-python38.test

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,33 @@ def g(x: int): ...
115115
) # type: ignore # E: Unused "type: ignore" comment
116116

117117
[case testPEP570ArgTypesMissing]
118-
# flags: --disallow-untyped-defs
118+
# flags: --python-version 3.8 --disallow-untyped-defs
119119
def f(arg, /) -> None: ... # E: Function is missing a type annotation for one or more arguments
120120

121121
[case testPEP570ArgTypesBadDefault]
122+
# flags: --python-version 3.8
122123
def f(arg: int = "ERROR", /) -> None: ... # E: Incompatible default for argument "arg" (default has type "str", argument has type "int")
123124

124125
[case testPEP570ArgTypesDefault]
126+
# flags: --python-version 3.8
125127
def f(arg: int = 0, /) -> None:
126128
reveal_type(arg) # N: Revealed type is "builtins.int"
127129

128130
[case testPEP570ArgTypesRequired]
131+
# flags: --python-version 3.8
129132
def f(arg: int, /) -> None:
130133
reveal_type(arg) # N: Revealed type is "builtins.int"
131134

132135
[case testPEP570Required]
136+
# flags: --python-version 3.8
133137
def f(arg: int, /) -> None: ... # N: "f" defined here
134138
f(1)
135139
f("ERROR") # E: Argument 1 to "f" has incompatible type "str"; expected "int"
136140
f(arg=1) # E: Unexpected keyword argument "arg" for "f"
137141
f(arg="ERROR") # E: Unexpected keyword argument "arg" for "f"
138142

139143
[case testPEP570Default]
144+
# flags: --python-version 3.8
140145
def f(arg: int = 0, /) -> None: ... # N: "f" defined here
141146
f()
142147
f(1)
@@ -145,6 +150,7 @@ f(arg=1) # E: Unexpected keyword argument "arg" for "f"
145150
f(arg="ERROR") # E: Unexpected keyword argument "arg" for "f"
146151

147152
[case testPEP570Calls]
153+
# flags: --python-version 3.8 --no-strict-optional
148154
from typing import Any, Dict
149155
def f(p, /, p_or_kw, *, kw) -> None: ... # N: "f" defined here
150156
d = None # type: Dict[Any, Any]
@@ -157,42 +163,49 @@ f(**d) # E: Missing positional argument "p_or_kw" in call to "f"
157163
[builtins fixtures/dict.pyi]
158164

159165
[case testPEP570Signatures1]
166+
# flags: --python-version 3.8
160167
def f(p1: bytes, p2: float, /, p_or_kw: int, *, kw: str) -> None:
161168
reveal_type(p1) # N: Revealed type is "builtins.bytes"
162169
reveal_type(p2) # N: Revealed type is "builtins.float"
163170
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"
164171
reveal_type(kw) # N: Revealed type is "builtins.str"
165172

166173
[case testPEP570Signatures2]
174+
# flags: --python-version 3.8
167175
def f(p1: bytes, p2: float = 0.0, /, p_or_kw: int = 0, *, kw: str) -> None:
168176
reveal_type(p1) # N: Revealed type is "builtins.bytes"
169177
reveal_type(p2) # N: Revealed type is "builtins.float"
170178
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"
171179
reveal_type(kw) # N: Revealed type is "builtins.str"
172180

173181
[case testPEP570Signatures3]
182+
# flags: --python-version 3.8
174183
def f(p1: bytes, p2: float = 0.0, /, *, kw: int) -> None:
175184
reveal_type(p1) # N: Revealed type is "builtins.bytes"
176185
reveal_type(p2) # N: Revealed type is "builtins.float"
177186
reveal_type(kw) # N: Revealed type is "builtins.int"
178187

179188
[case testPEP570Signatures4]
189+
# flags: --python-version 3.8
180190
def f(p1: bytes, p2: int = 0, /) -> None:
181191
reveal_type(p1) # N: Revealed type is "builtins.bytes"
182192
reveal_type(p2) # N: Revealed type is "builtins.int"
183193

184194
[case testPEP570Signatures5]
195+
# flags: --python-version 3.8
185196
def f(p1: bytes, p2: float, /, p_or_kw: int) -> None:
186197
reveal_type(p1) # N: Revealed type is "builtins.bytes"
187198
reveal_type(p2) # N: Revealed type is "builtins.float"
188199
reveal_type(p_or_kw) # N: Revealed type is "builtins.int"
189200

190201
[case testPEP570Signatures6]
202+
# flags: --python-version 3.8
191203
def f(p1: bytes, p2: float, /) -> None:
192204
reveal_type(p1) # N: Revealed type is "builtins.bytes"
193205
reveal_type(p2) # N: Revealed type is "builtins.float"
194206

195207
[case testPEP570Unannotated]
208+
# flags: --python-version 3.8
196209
def f(arg, /): ... # N: "f" defined here
197210
g = lambda arg, /: arg
198211
def h(arg=0, /): ... # N: "h" defined here
@@ -561,6 +574,7 @@ def foo() -> None:
561574
[builtins fixtures/dict.pyi]
562575

563576
[case testOverloadWithPositionalOnlySelf]
577+
# flags: --python-version 3.8
564578
from typing import overload, Optional
565579

566580
class Foo:
@@ -585,6 +599,7 @@ class Bar:
585599
[builtins fixtures/bool.pyi]
586600

587601
[case testOverloadPositionalOnlyErrorMessage]
602+
# flags: --python-version 3.8
588603
from typing import overload
589604

590605
@overload
@@ -595,12 +610,13 @@ def foo(a): ...
595610

596611
foo(a=1)
597612
[out]
598-
main:9: error: No overload variant of "foo" matches argument type "int"
599-
main:9: note: Possible overload variants:
600-
main:9: note: def foo(int, /) -> Any
601-
main:9: note: def foo(a: str) -> Any
613+
main:10: error: No overload variant of "foo" matches argument type "int"
614+
main:10: note: Possible overload variants:
615+
main:10: note: def foo(int, /) -> Any
616+
main:10: note: def foo(a: str) -> Any
602617

603618
[case testOverloadPositionalOnlyErrorMessageAllTypes]
619+
# flags: --python-version 3.8
604620
from typing import overload
605621

606622
@overload
@@ -611,12 +627,13 @@ def foo(a, b, *, c): ...
611627

612628
foo(a=1)
613629
[out]
614-
main:9: error: No overload variant of "foo" matches argument type "int"
615-
main:9: note: Possible overload variants:
616-
main:9: note: def foo(int, /, b: int, *, c: int) -> Any
617-
main:9: note: def foo(a: str, b: int, *, c: int) -> Any
630+
main:10: error: No overload variant of "foo" matches argument type "int"
631+
main:10: note: Possible overload variants:
632+
main:10: note: def foo(int, /, b: int, *, c: int) -> Any
633+
main:10: note: def foo(a: str, b: int, *, c: int) -> Any
618634

619635
[case testOverloadPositionalOnlyErrorMessageMultiplePosArgs]
636+
# flags: --python-version 3.8
620637
from typing import overload
621638

622639
@overload
@@ -627,12 +644,13 @@ def foo(a, b, c, d): ...
627644

628645
foo(a=1)
629646
[out]
630-
main:9: error: No overload variant of "foo" matches argument type "int"
631-
main:9: note: Possible overload variants:
632-
main:9: note: def foo(int, int, int, /, d: str) -> Any
633-
main:9: note: def foo(a: str, b: int, c: int, d: str) -> Any
647+
main:10: error: No overload variant of "foo" matches argument type "int"
648+
main:10: note: Possible overload variants:
649+
main:10: note: def foo(int, int, int, /, d: str) -> Any
650+
main:10: note: def foo(a: str, b: int, c: int, d: str) -> Any
634651

635652
[case testOverloadPositionalOnlyErrorMessageMethod]
653+
# flags: --python-version 3.8
636654
from typing import overload
637655

638656
class Some:
@@ -646,13 +664,14 @@ class Some:
646664

647665
Some().foo(a=1)
648666
[out]
649-
main:12: error: No overload variant of "foo" of "Some" matches argument type "int"
650-
main:12: note: Possible overload variants:
651-
main:12: note: def foo(self, int, /) -> Any
652-
main:12: note: def foo(self, float, /) -> Any
653-
main:12: note: def foo(self, a: str) -> Any
667+
main:13: error: No overload variant of "foo" of "Some" matches argument type "int"
668+
main:13: note: Possible overload variants:
669+
main:13: note: def foo(self, int, /) -> Any
670+
main:13: note: def foo(self, float, /) -> Any
671+
main:13: note: def foo(self, a: str) -> Any
654672

655673
[case testOverloadPositionalOnlyErrorMessageClassMethod]
674+
# flags: --python-version 3.8
656675
from typing import overload
657676

658677
class Some:
@@ -671,13 +690,14 @@ class Some:
671690
Some.foo(a=1)
672691
[builtins fixtures/classmethod.pyi]
673692
[out]
674-
main:16: error: No overload variant of "foo" of "Some" matches argument type "int"
675-
main:16: note: Possible overload variants:
676-
main:16: note: def foo(cls, int, /) -> Any
677-
main:16: note: def foo(cls, float, /) -> Any
678-
main:16: note: def foo(cls, a: str) -> Any
693+
main:17: error: No overload variant of "foo" of "Some" matches argument type "int"
694+
main:17: note: Possible overload variants:
695+
main:17: note: def foo(cls, int, /) -> Any
696+
main:17: note: def foo(cls, float, /) -> Any
697+
main:17: note: def foo(cls, a: str) -> Any
679698

680699
[case testUnpackWithDuplicateNamePositionalOnly]
700+
# flags: --python-version 3.8
681701
from typing_extensions import Unpack, TypedDict
682702

683703
class Person(TypedDict):

0 commit comments

Comments
 (0)