Skip to content

Commit 303fa4f

Browse files
committed
add tests
1 parent 60d8f7c commit 303fa4f

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ reveal_type(b) # N: Revealed type is "def (*Any) -> builtins.int"
578578
[builtins fixtures/tuple.pyi]
579579

580580
[case testTypeVarTuplePep646CallableNewSyntax]
581+
# flags: --python-version 3.11
581582
from typing import Callable, Generic, Tuple
582583
from typing_extensions import ParamSpec
583584

@@ -2155,6 +2156,7 @@ def f(x: int | None):
21552156
[builtins fixtures/tuple.pyi]
21562157

21572158
[case testJoinOfVariadicTupleCallablesNoCrash]
2159+
# flags: --python-version 3.11
21582160
from typing import Callable, Tuple
21592161

21602162
f: Callable[[int, *Tuple[str, ...], int], None]
@@ -2608,6 +2610,7 @@ def test(xs: tuple[Unpack[Ts]], xsi: tuple[int, Unpack[Ts]]) -> None:
26082610
[builtins fixtures/tuple.pyi]
26092611

26102612
[case testTypeVarTupleInferAgainstAnyCallableSuffix]
2613+
# flags: --python-version 3.11
26112614
from typing import Any, Callable, TypeVar, TypeVarTuple
26122615

26132616
Ts = TypeVarTuple("Ts")
@@ -2620,6 +2623,7 @@ reveal_type(deco(untyped)) # N: Revealed type is "def (*Any) -> Any"
26202623
[builtins fixtures/tuple.pyi]
26212624

26222625
[case testNoCrashOnNonNormalUnpackInCallable]
2626+
# flags: --python-version 3.11
26232627
from typing import Callable, Unpack, TypeVar
26242628

26252629
T = TypeVar("T")

test-data/unit/check-varargs.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ class D:
11161116
[builtins fixtures/dict.pyi]
11171117

11181118
[case testUnpackInCallableType]
1119+
# flags: --python-version 3.11
11191120
from typing import Callable, TypedDict
11201121
from typing_extensions import Unpack
11211122

test-data/unit/native-parser.test

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,12 @@ try:
13001300
except* ValueError:
13011301
y
13021302
[out]
1303+
1:0: error: Exception groups: requires Python 3.11 or newer (current target: Python 3.10)
13031304
MypyFile:1(
13041305
TryStmt:1(
13051306
Block:2(
13061307
ExpressionStmt:2(
13071308
NameExpr(x)))
1308-
*
13091309
NameExpr(ValueError)
13101310
Block:4(
13111311
ExpressionStmt:4(
@@ -1317,12 +1317,12 @@ try:
13171317
except* Exception as e:
13181318
y
13191319
[out]
1320+
1:0: error: Exception groups: requires Python 3.11 or newer (current target: Python 3.10)
13201321
MypyFile:1(
13211322
TryStmt:1(
13221323
Block:2(
13231324
ExpressionStmt:2(
13241325
NameExpr(x)))
1325-
*
13261326
NameExpr(Exception)
13271327
NameExpr(e)
13281328
Block:4(
@@ -1337,12 +1337,12 @@ except* ValueError:
13371337
except* KeyError as e:
13381338
z
13391339
[out]
1340+
1:0: error: Exception groups: requires Python 3.11 or newer (current target: Python 3.10)
13401341
MypyFile:1(
13411342
TryStmt:1(
13421343
Block:2(
13431344
ExpressionStmt:2(
13441345
NameExpr(x)))
1345-
*
13461346
NameExpr(ValueError)
13471347
Block:4(
13481348
ExpressionStmt:4(
@@ -1363,12 +1363,12 @@ else:
13631363
finally:
13641364
w
13651365
[out]
1366+
1:0: error: Exception groups: requires Python 3.11 or newer (current target: Python 3.10)
13661367
MypyFile:1(
13671368
TryStmt:1(
13681369
Block:2(
13691370
ExpressionStmt:2(
13701371
NameExpr(x)))
1371-
*
13721372
NameExpr(ValueError)
13731373
Block:4(
13741374
ExpressionStmt:4(
@@ -2022,6 +2022,7 @@ MypyFile:1(
20222022
def f(*args: *Ts) -> None:
20232023
pass
20242024
[out]
2025+
1:13: error: Star unpack syntax: requires Python 3.11 or newer (current target: Python 3.10)
20252026
MypyFile:1(
20262027
FuncDef:1(
20272028
f
@@ -2034,6 +2035,7 @@ MypyFile:1(
20342035
[case testUnpackTypeInTuple]
20352036
x: tuple[int, *Ts, str]
20362037
[out]
2038+
1:14: error: Star unpack syntax: requires Python 3.11 or newer (current target: Python 3.10)
20372039
MypyFile:1(
20382040
AssignmentStmt:1(
20392041
NameExpr(x)
@@ -3190,6 +3192,7 @@ MypyFile:1(
31903192
# comment
31913193
type A[T] = C[T]
31923194
[out]
3195+
2:0: error: "type" statements: requires Python 3.12 or newer (current target: Python 3.10)
31933196
MypyFile:1(
31943197
TypeAliasStmt:2(
31953198
NameExpr(A)
@@ -3209,6 +3212,9 @@ def f[T](): pass
32093212
def g[T: str](): pass
32103213
def h[T: (int, str)](): pass
32113214
[out]
3215+
3:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
3216+
4:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
3217+
5:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
32123218
MypyFile:1(
32133219
FuncDef:3(
32143220
f
@@ -3239,6 +3245,8 @@ MypyFile:1(
32393245
def f[**P](): pass
32403246
class C[T: int, **P]: pass
32413247
[out]
3248+
3:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
3249+
4:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
32423250
MypyFile:1(
32433251
FuncDef:3(
32443252
f
@@ -3261,6 +3269,8 @@ MypyFile:1(
32613269
def f[*Ts](): pass
32623270
class C[T: int, *Ts]: pass
32633271
[out]
3272+
3:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
3273+
4:0: error: Improved type parameter syntax: requires Python 3.12 or newer (current target: Python 3.10)
32643274
MypyFile:1(
32653275
FuncDef:3(
32663276
f

test-data/unit/pythoneval.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,3 +2268,28 @@ _testNarrowingMappingAndAbstractSet.py:33: note: Revealed type is "dict[str, int
22682268
_testNarrowingMappingAndAbstractSet.py:34: note: Revealed type is "set[str]"
22692269
_testNarrowingMappingAndAbstractSet.py:38: note: Revealed type is "_collections_abc.dict_keys[str, int]"
22702270
_testNarrowingMappingAndAbstractSet.py:39: note: Revealed type is "set[str]"
2271+
2272+
[case testNativeParserTStringRequiresPython314]
2273+
# flags: --python-version=3.13 --native-parser --ignore-missing-imports
2274+
x = t"hello {1}"
2275+
[out]
2276+
_testNativeParserTStringRequiresPython314.py:2: error: T-strings: requires Python 3.14 or newer (current target: Python 3.13)
2277+
2278+
[case testNativeParserTStringRequiresPython314InStub]
2279+
# flags: --python-version=3.13 --native-parser --ignore-missing-imports
2280+
import m
2281+
[file m.pyi]
2282+
x: object
2283+
def f() -> object: ...
2284+
y = t"hello {1}"
2285+
[out]
2286+
m.pyi:3: error: T-strings: requires Python 3.14 or newer (current target: Python 3.13)
2287+
2288+
[case testNativeParserStarUnpackRequiresPython311]
2289+
# flags: --python-version=3.10 --native-parser
2290+
from typing_extensions import TypeVarTuple, Unpack
2291+
Ts = TypeVarTuple("Ts")
2292+
def f(x: tuple[Unpack[Ts]]) -> None: ...
2293+
def g(x: tuple[*Ts]) -> None: ...
2294+
[out]
2295+
_testNativeParserStarUnpackRequiresPython311.py:5: error: Star unpack syntax: requires Python 3.11 or newer (current target: Python 3.10)

0 commit comments

Comments
 (0)