Skip to content

Commit 7548cd1

Browse files
authored
Update Final imports in tests (#18654)
Replace most `typing_extensions.Final` and `typing_extensions.final` imports in tests with `typing.Final` and `typing.final`.
1 parent 24ecb27 commit 7548cd1

31 files changed

+97
-153
lines changed

mypyc/test-data/alwaysdefined.test

+2-3
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ IfConditionalAndNonConditional1: [x]
166166
IfConditionalAndNonConditional2: []
167167

168168
[case testAlwaysDefinedExpressions]
169-
from typing import Dict, List, Set, Optional, cast
170-
from typing_extensions import Final
169+
from typing import Dict, Final, List, Set, Optional, cast
171170

172171
import other
173172

@@ -307,7 +306,7 @@ def f() -> int:
307306

308307
[file other.py]
309308
# Not compiled
310-
from typing_extensions import Final
309+
from typing import Final
311310

312311
Y: Final = 3
313312

mypyc/test-data/commandline.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def f(x: int) -> int:
105105
# cmd: test.py
106106

107107
[file test.py]
108-
from typing import List, Any, AsyncIterable
109-
from typing_extensions import Final
108+
from typing import Final, List, Any, AsyncIterable
110109
from mypy_extensions import trait, mypyc_attr
111110
from functools import singledispatch
112111

mypyc/test-data/exceptions-freq.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ L2:
9797
hot blocks: [0, 1]
9898

9999
[case testRareBranch_freq]
100-
from typing_extensions import Final
100+
from typing import Final
101101

102102
x: Final = str()
103103

mypyc/test-data/irbuild-constant-fold.test

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ L0:
187187
return 1
188188

189189
[case testIntConstantFoldingFinal]
190-
from typing_extensions import Final
190+
from typing import Final
191191
X: Final = 5
192192
Y: Final = 2 + 4
193193

@@ -203,7 +203,7 @@ L0:
203203
return 1
204204

205205
[case testIntConstantFoldingClassFinal]
206-
from typing_extensions import Final
206+
from typing import Final
207207
class C:
208208
X: Final = 5
209209

@@ -222,7 +222,7 @@ L0:
222222
return 1
223223

224224
[case testFloatConstantFolding]
225-
from typing_extensions import Final
225+
from typing import Final
226226

227227
N: Final = 1.5
228228
N2: Final = 1.5 * 2
@@ -391,7 +391,7 @@ L2:
391391
return 1
392392

393393
[case testStrConstantFolding]
394-
from typing_extensions import Final
394+
from typing import Final
395395

396396
S: Final = 'z'
397397
N: Final = 2
@@ -416,7 +416,7 @@ L0:
416416
return 1
417417

418418
[case testBytesConstantFolding]
419-
from typing_extensions import Final
419+
from typing import Final
420420

421421
N: Final = 2
422422

@@ -438,7 +438,7 @@ L0:
438438
return 1
439439

440440
[case testComplexConstantFolding]
441-
from typing_extensions import Final
441+
from typing import Final
442442

443443
N: Final = 1
444444
FLOAT_N: Final = 1.5

mypyc/test-data/irbuild-float.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ L0:
219219
return r0
220220

221221
[case testFloatFinalConstant]
222-
from typing_extensions import Final
222+
from typing import Final
223223

224224
X: Final = 123.0
225225
Y: Final = -1.0

mypyc/test-data/irbuild-i64.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ L2:
16771677
return 1
16781678

16791679
[case testI64FinalConstants]
1680-
from typing_extensions import Final
1680+
from typing import Final
16811681
from mypy_extensions import i64
16821682

16831683
A: Final = -1

mypyc/test-data/irbuild-int.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ L0:
116116
return r0
117117

118118
[case testFinalConstantFolding]
119-
from typing_extensions import Final
119+
from typing import Final
120120

121121
X: Final = -1
122122
Y: Final = -(1 + 3*2)

mypyc/test-data/irbuild-set.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ L0:
628628
return r0
629629

630630
[case testOperatorInSetLiteral]
631-
from typing_extensions import Final
631+
from typing import Final
632632

633633
CONST: Final = "daylily"
634634
non_const = 10
@@ -716,7 +716,7 @@ L0:
716716
return r14
717717

718718
[case testForSetLiteral]
719-
from typing_extensions import Final
719+
from typing import Final
720720

721721
CONST: Final = 10
722722
non_const = 20

mypyc/test-data/refcount.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ L0:
13391339
return r2
13401340

13411341
[case testBorrowIntCompareFinal]
1342-
from typing_extensions import Final
1342+
from typing import Final
13431343

13441344
X: Final = 10
13451345

mypyc/test-data/run-classes.test

+2-3
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ Traceback (most recent call last):
711711
AttributeError: attribute 'x' of 'X' undefined
712712

713713
[case testClassMethods]
714-
from typing import ClassVar, Any
715-
from typing_extensions import final
714+
from typing import ClassVar, Any, final
716715
from mypy_extensions import mypyc_attr
717716

718717
from interp import make_interpreted_subclass
@@ -2543,7 +2542,7 @@ class Derived(Base):
25432542
assert Derived()() == 1
25442543

25452544
[case testClassWithFinalAttribute]
2546-
from typing_extensions import Final
2545+
from typing import Final
25472546

25482547
class C:
25492548
A: Final = -1

mypyc/test-data/run-floats.test

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
[case testFloatOps]
44
from __future__ import annotations
5-
from typing import Any, cast
6-
from typing_extensions import Final
5+
from typing import Final, Any, cast
76
from testutil import assertRaises, float_vals, FLOAT_MAGIC
87
import math
98

@@ -348,8 +347,7 @@ def test_tuples() -> None:
348347
assert t2 == tuple([5.0, 1.5, -7.0, -113.0])
349348

350349
[case testFloatGlueMethodsAndInheritance]
351-
from typing import Any
352-
from typing_extensions import Final
350+
from typing import Final, Any
353351

354352
from mypy_extensions import trait
355353

mypyc/test-data/run-i64.test

+4-7
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,10 @@ def test_isinstance() -> None:
517517
assert narrow2("foobar") == 6
518518

519519
[case testI64ErrorValuesAndUndefined]
520-
from typing import Any, Tuple
520+
from typing import Any, Final, Tuple
521521
import sys
522522

523523
from mypy_extensions import mypyc_attr, i64
524-
from typing_extensions import Final
525524

526525
from testutil import assertRaises
527526

@@ -905,8 +904,7 @@ def test_undefined_native_int_tuple_via_any() -> None:
905904
assert o.t == (-13, 45)
906905

907906
[case testI64DefaultArgValues]
908-
from typing import Any, Iterator, Tuple
909-
from typing_extensions import Final
907+
from typing import Any, Final, Iterator, Tuple
910908

911909
MAGIC: Final = -113
912910

@@ -1206,7 +1204,7 @@ def test_magic_default() -> None:
12061204
assert a(MAGIC) == MAGIC
12071205

12081206
[case testI64UndefinedLocal]
1209-
from typing_extensions import Final
1207+
from typing import Final
12101208

12111209
from mypy_extensions import i64, i32
12121210

@@ -1338,8 +1336,7 @@ def test_many_locals() -> None:
13381336
assert a33 == 20
13391337

13401338
[case testI64GlueMethodsAndInheritance]
1341-
from typing import Any
1342-
from typing_extensions import Final
1339+
from typing import Final, Any
13431340

13441341
from mypy_extensions import i64, trait
13451342

mypyc/test-data/run-math.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Test cases for the math module (compile and run)
22

33
[case testMathOps]
4-
from typing import Any, Callable
5-
from typing_extensions import Final
4+
from typing import Any, Callable, Final
65
import math
76
from math import pi, e, tau, inf, nan
87
from testutil import assertRaises, float_vals, assertDomainError, assertMathRangeError

mypyc/test-data/run-multimodule.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def f(c: C) -> int:
155155
c = cast(C, o)
156156
return a_global + c.x + c.f() + d.x + d.f() + 1
157157
[file other.py]
158-
from typing_extensions import Final
158+
from typing import Final
159159
a_global: Final = int('5')
160160

161161
class C:
@@ -735,11 +735,11 @@ def foo() -> int:
735735
return X
736736

737737
[file other.py]
738-
from typing_extensions import Final
738+
from typing import Final
739739
X: Final = 10
740740

741741
[file other.py.2]
742-
from typing_extensions import Final
742+
from typing import Final
743743
X: Final = 20
744744

745745
[file driver.py]

mypyc/test-data/run-sets.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ def test_frozen_sets_from_iterables() -> None:
235235
assert g4() == frozenset({11, 21, 31})
236236

237237
[case testPrecomputedFrozenSets]
238-
from typing import Any
239-
from typing_extensions import Final
238+
from typing import Final, Any
240239

241240
CONST: Final = "CONST"
242241
non_const = "non_const"

mypyc/test-data/run-tuples.test

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ assert f(Sub(3, 2)) == 3
9797

9898
-- Ref: https://github.com/mypyc/mypyc/issues/924
9999
[case testNamedTupleClassSyntax]
100-
from typing import Dict, List, NamedTuple, Optional, Tuple, Union
101-
from typing_extensions import final
100+
from typing import Dict, List, NamedTuple, Optional, Tuple, Union, final
102101

103102
class FuncIR: pass
104103

@@ -147,8 +146,7 @@ assert Record.__annotations__ == {
147146
}, Record.__annotations__
148147

149148
[case testTupleOps]
150-
from typing import Tuple, List, Any, Optional
151-
from typing_extensions import Final
149+
from typing import Tuple, Final, List, Any, Optional
152150

153151
def f() -> Tuple[()]:
154152
return ()

mypyc/test-data/run-u8.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[case testU8BasicOps]
2-
from typing import Any, Tuple
2+
from typing import Any, Final, Tuple
33

44
from mypy_extensions import u8, i16, i32, i64
5-
from typing_extensions import Final
65

76
from testutil import assertRaises
87

test-data/unit/check-basic.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ class B(Enum):
405405
b = 10
406406

407407
[file b.py]
408-
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
409-
from typing_extensions import Final
408+
from typing import Final, List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
410409
from enum import Enum
411410
import a
412411
class A: pass

test-data/unit/check-enum.test

+7-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ reveal_type(Animal.DOG) # N: Revealed type is "Literal[__main__.Animal.DOG]?"
3131

3232
[case testEnumCreatedFromFinalValue]
3333
from enum import Enum
34-
from typing_extensions import Final
34+
from typing import Final
3535

3636
x: Final['str'] = 'ANT BEE CAT DOG'
3737
Animal = Enum('Animal', x)
@@ -975,8 +975,7 @@ else:
975975

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

981980
class Foo(Enum):
982981
A = 1
@@ -1130,8 +1129,7 @@ reveal_type(x3) # N: Revealed type is "Union[__main__.Foo, __main__.Bar]"
11301129
[builtins fixtures/bool.pyi]
11311130

11321131
[case testEnumReachabilityPEP484ExampleWithFinal]
1133-
from typing import Union
1134-
from typing_extensions import Final
1132+
from typing import Final, Union
11351133
from enum import Enum
11361134

11371135
class Empty(Enum):
@@ -1176,8 +1174,7 @@ def process(response: Union[str, Reason] = '') -> str:
11761174

11771175

11781176
[case testEnumReachabilityPEP484ExampleSingleton]
1179-
from typing import Union
1180-
from typing_extensions import Final
1177+
from typing import Final, Union
11811178
from enum import Enum
11821179

11831180
class Empty(Enum):
@@ -1200,8 +1197,7 @@ def func(x: Union[int, None, Empty] = _empty) -> int:
12001197
[builtins fixtures/primitives.pyi]
12011198

12021199
[case testEnumReachabilityPEP484ExampleSingletonWithMethod]
1203-
from typing import Union
1204-
from typing_extensions import Final
1200+
from typing import Final, Union
12051201
from enum import Enum
12061202

12071203
class Empty(Enum):
@@ -1331,8 +1327,7 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
13311327
[case testEnumReachabilityWithChainingDirectConflict]
13321328
# flags: --warn-unreachable
13331329
from enum import Enum
1334-
from typing import Literal
1335-
from typing_extensions import Final
1330+
from typing import Final, Literal
13361331

13371332
class Foo(Enum):
13381333
A = 1
@@ -1367,8 +1362,7 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
13671362
[case testEnumReachabilityWithChainingBigDisjoints]
13681363
# flags: --warn-unreachable
13691364
from enum import Enum
1370-
from typing import Literal
1371-
from typing_extensions import Final
1365+
from typing import Final, Literal
13721366

13731367
class Foo(Enum):
13741368
A = 1

test-data/unit/check-expressions.test

+1-2
Original file line numberDiff line numberDiff line change
@@ -2281,8 +2281,7 @@ def f(x: T) -> T:
22812281

22822282
[case testStrictEqualityWithALiteral]
22832283
# flags: --strict-equality
2284-
from typing import Literal
2285-
from typing_extensions import Final
2284+
from typing import Final, Literal
22862285

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

0 commit comments

Comments
 (0)