Skip to content

Commit 2b2953a

Browse files
cdce8pAlexWaygood
andauthored
[0.980 backport] Update pos-only unit tests for Python 3.10.7 (#13660) (#13665)
Backport #13660 to fix test issues with Python 3.10.7. https://github.com/python/mypy/actions/runs/3046723692/jobs/4909887963 Co-authored-by: Alex Waygood <[email protected]>
1 parent ada0078 commit 2b2953a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

+9-5
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

+16-1
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
@@ -554,6 +567,7 @@ def foo() -> None:
554567
[builtins fixtures/dict.pyi]
555568

556569
[case testOverloadWithPositionalOnlySelf]
570+
# flags: --python-version 3.8
557571
from typing import overload, Optional
558572

559573
class Foo:
@@ -578,6 +592,7 @@ class Bar:
578592
[builtins fixtures/bool.pyi]
579593

580594
[case testUnpackWithDuplicateNamePositionalOnly]
595+
# flags: --python-version 3.8
581596
from typing_extensions import Unpack, TypedDict
582597

583598
class Person(TypedDict):

0 commit comments

Comments
 (0)