Skip to content

Commit 653fc9b

Browse files
authored
Update Literal imports in tests (#18640)
`Literal` was added to Python in 3.8. Replace most `typing_extensions` imports in tests.
1 parent ecc13c8 commit 653fc9b

30 files changed

+291
-347
lines changed

Diff for: mypyc/test-data/run-misc.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ for a in sorted(s):
612612
9 8 72
613613

614614
[case testDummyTypes]
615-
from typing import Tuple, List, Dict, NamedTuple
616-
from typing_extensions import Literal, TypedDict, NewType
615+
from typing import Tuple, List, Dict, Literal, NamedTuple
616+
from typing_extensions import TypedDict, NewType
617617

618618
class A:
619619
pass

Diff for: test-data/unit/check-basic.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ class B(Enum):
406406
b = 10
407407

408408
[file b.py]
409-
from typing import List, Optional, Union, Sequence, NamedTuple, Tuple, Type
410-
from typing_extensions import Literal, Final, TypedDict
409+
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type
410+
from typing_extensions import Final, TypedDict
411411
from enum import Enum
412412
import a
413413
class A: pass

Diff for: test-data/unit/check-enum.test

+17-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if int():
1818

1919
[case testEnumCreatedFromStringLiteral]
2020
from enum import Enum
21-
from typing_extensions import Literal
21+
from typing import Literal
2222

2323
x: Literal['ANT BEE CAT DOG'] = 'ANT BEE CAT DOG'
2424
Animal = Enum('Animal', x)
@@ -181,7 +181,7 @@ def infer_truth(truth: Truth) -> None:
181181
[case testEnumTruthyness]
182182
# mypy: warn-unreachable
183183
import enum
184-
from typing_extensions import Literal
184+
from typing import Literal
185185

186186
class E(enum.Enum):
187187
zero = 0
@@ -213,7 +213,7 @@ def main(zero: Literal[E.zero], one: Literal[E.one]) -> None:
213213
[case testEnumTruthynessCustomDunderBool]
214214
# mypy: warn-unreachable
215215
import enum
216-
from typing_extensions import Literal
216+
from typing import Literal
217217

218218
class E(enum.Enum):
219219
zero = 0
@@ -247,7 +247,7 @@ def main(zero: Literal[E.zero], one: Literal[E.one]) -> None:
247247
[case testEnumTruthynessStrEnum]
248248
# mypy: warn-unreachable
249249
import enum
250-
from typing_extensions import Literal
250+
from typing import Literal
251251

252252
class E(enum.StrEnum):
253253
empty = ""
@@ -726,7 +726,7 @@ reveal_type(Test.a) # N: Revealed type is "Literal[__main__.Test.a]?"
726726

727727
[case testEnumAttributeAccessMatrix]
728728
from enum import Enum, IntEnum, IntFlag, Flag, EnumMeta, auto
729-
from typing_extensions import Literal
729+
from typing import Literal
730730

731731
def is_x(val: Literal['x']) -> None: pass
732732

@@ -872,7 +872,7 @@ main:2: note: Revealed type is "Literal['foo']?"
872872

873873
[case testEnumReachabilityChecksBasic]
874874
from enum import Enum
875-
from typing_extensions import Literal
875+
from typing import Literal
876876

877877
class Foo(Enum):
878878
A = 1
@@ -924,7 +924,7 @@ reveal_type(y) # N: Revealed type is "__main__.Foo"
924924

925925
[case testEnumReachabilityChecksWithOrdering]
926926
from enum import Enum
927-
from typing_extensions import Literal
927+
from typing import Literal
928928

929929
class Foo(Enum):
930930
_order_ = "A B"
@@ -975,7 +975,8 @@ else:
975975

976976
[case testEnumReachabilityChecksIndirect]
977977
from enum import Enum
978-
from typing_extensions import Literal, Final
978+
from typing import Literal
979+
from typing_extensions import Final
979980

980981
class Foo(Enum):
981982
A = 1
@@ -1040,7 +1041,7 @@ else:
10401041

10411042
[case testEnumReachabilityNoNarrowingForUnionMessiness]
10421043
from enum import Enum
1043-
from typing_extensions import Literal
1044+
from typing import Literal
10441045

10451046
class Foo(Enum):
10461047
A = 1
@@ -1096,8 +1097,7 @@ reveal_type(x) # N: Revealed type is "Union[__main__.Foo, None]"
10961097

10971098
[case testEnumReachabilityWithMultipleEnums]
10981099
from enum import Enum
1099-
from typing import Union
1100-
from typing_extensions import Literal
1100+
from typing import Literal, Union
11011101

11021102
class Foo(Enum):
11031103
A = 1
@@ -1331,7 +1331,8 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
13311331
[case testEnumReachabilityWithChainingDirectConflict]
13321332
# flags: --warn-unreachable
13331333
from enum import Enum
1334-
from typing_extensions import Literal, Final
1334+
from typing import Literal
1335+
from typing_extensions import Final
13351336

13361337
class Foo(Enum):
13371338
A = 1
@@ -1366,7 +1367,8 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
13661367
[case testEnumReachabilityWithChainingBigDisjoints]
13671368
# flags: --warn-unreachable
13681369
from enum import Enum
1369-
from typing_extensions import Literal, Final
1370+
from typing import Literal
1371+
from typing_extensions import Final
13701372

13711373
class Foo(Enum):
13721374
A = 1
@@ -1488,8 +1490,7 @@ reveal_type(a._value_) # N: Revealed type is "Any"
14881490
# as the full type, regardless of the amount of elements
14891491
# the enum contains.
14901492
from enum import Enum
1491-
from typing import Union
1492-
from typing_extensions import Literal
1493+
from typing import Literal, Union
14931494

14941495
class Foo(Enum):
14951496
A = 1
@@ -1507,7 +1508,7 @@ def f(x: Foo):
15071508

15081509
[case testEnumTypeCompatibleWithLiteralUnion]
15091510
from enum import Enum
1510-
from typing_extensions import Literal
1511+
from typing import Literal
15111512

15121513
class E(Enum):
15131514
A = 1

Diff for: test-data/unit/check-expressions.test

+4-5
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,7 @@ main:4: error: "A" not callable
985985
-- assert_type()
986986

987987
[case testAssertType]
988-
from typing import assert_type, Any
989-
from typing_extensions import Literal
988+
from typing import assert_type, Any, Literal
990989
a: int = 1
991990
returned = assert_type(a, int)
992991
reveal_type(returned) # N: Revealed type is "builtins.int"
@@ -998,8 +997,7 @@ assert_type(42, int) # E: Expression is of type "Literal[42]", not "int"
998997
[builtins fixtures/tuple.pyi]
999998

1000999
[case testAssertTypeGeneric]
1001-
from typing import assert_type, TypeVar, Generic
1002-
from typing_extensions import Literal
1000+
from typing import assert_type, Literal, TypeVar, Generic
10031001
T = TypeVar("T")
10041002
def f(x: T) -> T: return x
10051003
assert_type(f(1), int)
@@ -2283,7 +2281,8 @@ def f(x: T) -> T:
22832281

22842282
[case testStrictEqualityWithALiteral]
22852283
# flags: --strict-equality
2286-
from typing_extensions import Literal, Final
2284+
from typing import Literal
2285+
from typing_extensions import Final
22872286

22882287
def returns_a_or_b() -> Literal['a', 'b']:
22892288
...

Diff for: test-data/unit/check-final.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,8 @@ class Child(Parent):
11871187
def __bar(self) -> None: ...
11881188

11891189
[case testFinalWithoutBool]
1190-
from typing_extensions import final, Literal
1190+
from typing import Literal
1191+
from typing_extensions import final
11911192

11921193
class A:
11931194
pass
@@ -1207,7 +1208,8 @@ reveal_type(C() and 42) # N: Revealed type is "Literal[42]?"
12071208
[builtins fixtures/bool.pyi]
12081209

12091210
[case testFinalWithoutBoolButWithLen]
1210-
from typing_extensions import final, Literal
1211+
from typing import Literal
1212+
from typing_extensions import final
12111213

12121214
# Per Python data model, __len__ is called if __bool__ does not exist.
12131215
# In a @final class, __bool__ would not exist.

Diff for: test-data/unit/check-incremental.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -5080,10 +5080,10 @@ plugins=<ROOT>/test-data/unit/plugins/config_data.py
50805080
import mod
50815081
reveal_type(mod.a)
50825082
[file mod.py]
5083-
from typing_extensions import Literal
5083+
from typing import Literal
50845084
a = 1
50855085
[file mod.py.2]
5086-
from typing_extensions import Literal
5086+
from typing import Literal
50875087
a: Literal[2] = 2
50885088
[builtins fixtures/tuple.pyi]
50895089
[out]

Diff for: test-data/unit/check-isinstance.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ if isinstance(y, B):
23782378
# flags: --warn-unreachable
23792379

23802380
from abc import abstractmethod
2381-
from typing_extensions import Literal
2381+
from typing import Literal
23822382

23832383
class A0:
23842384
def f(self) -> Literal[0]:

0 commit comments

Comments
 (0)