Skip to content

Update Final imports in tests #18654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mypyc/test-data/alwaysdefined.test
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ IfConditionalAndNonConditional1: [x]
IfConditionalAndNonConditional2: []

[case testAlwaysDefinedExpressions]
from typing import Dict, List, Set, Optional, cast
from typing_extensions import Final
from typing import Dict, Final, List, Set, Optional, cast

import other

Expand Down Expand Up @@ -307,7 +306,7 @@ def f() -> int:

[file other.py]
# Not compiled
from typing_extensions import Final
from typing import Final

Y: Final = 3

Expand Down
3 changes: 1 addition & 2 deletions mypyc/test-data/commandline.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def f(x: int) -> int:
# cmd: test.py

[file test.py]
from typing import List, Any, AsyncIterable
from typing_extensions import Final
from typing import Final, List, Any, AsyncIterable
from mypy_extensions import trait, mypyc_attr
from functools import singledispatch

Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/exceptions-freq.test
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ L2:
hot blocks: [0, 1]

[case testRareBranch_freq]
from typing_extensions import Final
from typing import Final

x: Final = str()

Expand Down
12 changes: 6 additions & 6 deletions mypyc/test-data/irbuild-constant-fold.test
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ L0:
return 1

[case testIntConstantFoldingFinal]
from typing_extensions import Final
from typing import Final
X: Final = 5
Y: Final = 2 + 4

Expand All @@ -203,7 +203,7 @@ L0:
return 1

[case testIntConstantFoldingClassFinal]
from typing_extensions import Final
from typing import Final
class C:
X: Final = 5

Expand All @@ -222,7 +222,7 @@ L0:
return 1

[case testFloatConstantFolding]
from typing_extensions import Final
from typing import Final

N: Final = 1.5
N2: Final = 1.5 * 2
Expand Down Expand Up @@ -391,7 +391,7 @@ L2:
return 1

[case testStrConstantFolding]
from typing_extensions import Final
from typing import Final

S: Final = 'z'
N: Final = 2
Expand All @@ -416,7 +416,7 @@ L0:
return 1

[case testBytesConstantFolding]
from typing_extensions import Final
from typing import Final

N: Final = 2

Expand All @@ -438,7 +438,7 @@ L0:
return 1

[case testComplexConstantFolding]
from typing_extensions import Final
from typing import Final

N: Final = 1
FLOAT_N: Final = 1.5
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/irbuild-float.test
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ L0:
return r0

[case testFloatFinalConstant]
from typing_extensions import Final
from typing import Final

X: Final = 123.0
Y: Final = -1.0
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/irbuild-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ L2:
return 1

[case testI64FinalConstants]
from typing_extensions import Final
from typing import Final
from mypy_extensions import i64

A: Final = -1
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/irbuild-int.test
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ L0:
return r0

[case testFinalConstantFolding]
from typing_extensions import Final
from typing import Final

X: Final = -1
Y: Final = -(1 + 3*2)
Expand Down
4 changes: 2 additions & 2 deletions mypyc/test-data/irbuild-set.test
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ L0:
return r0

[case testOperatorInSetLiteral]
from typing_extensions import Final
from typing import Final

CONST: Final = "daylily"
non_const = 10
Expand Down Expand Up @@ -716,7 +716,7 @@ L0:
return r14

[case testForSetLiteral]
from typing_extensions import Final
from typing import Final

CONST: Final = 10
non_const = 20
Expand Down
2 changes: 1 addition & 1 deletion mypyc/test-data/refcount.test
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ L0:
return r2

[case testBorrowIntCompareFinal]
from typing_extensions import Final
from typing import Final

X: Final = 10

Expand Down
5 changes: 2 additions & 3 deletions mypyc/test-data/run-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ Traceback (most recent call last):
AttributeError: attribute 'x' of 'X' undefined

[case testClassMethods]
from typing import ClassVar, Any
from typing_extensions import final
from typing import ClassVar, Any, final
from mypy_extensions import mypyc_attr

from interp import make_interpreted_subclass
Expand Down Expand Up @@ -2543,7 +2542,7 @@ class Derived(Base):
assert Derived()() == 1

[case testClassWithFinalAttribute]
from typing_extensions import Final
from typing import Final

class C:
A: Final = -1
Expand Down
6 changes: 2 additions & 4 deletions mypyc/test-data/run-floats.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

[case testFloatOps]
from __future__ import annotations
from typing import Any, cast
from typing_extensions import Final
from typing import Final, Any, cast
from testutil import assertRaises, float_vals, FLOAT_MAGIC
import math

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

[case testFloatGlueMethodsAndInheritance]
from typing import Any
from typing_extensions import Final
from typing import Final, Any

from mypy_extensions import trait

Expand Down
11 changes: 4 additions & 7 deletions mypyc/test-data/run-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,10 @@ def test_isinstance() -> None:
assert narrow2("foobar") == 6

[case testI64ErrorValuesAndUndefined]
from typing import Any, Tuple
from typing import Any, Final, Tuple
import sys

from mypy_extensions import mypyc_attr, i64
from typing_extensions import Final

from testutil import assertRaises

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

[case testI64DefaultArgValues]
from typing import Any, Iterator, Tuple
from typing_extensions import Final
from typing import Any, Final, Iterator, Tuple

MAGIC: Final = -113

Expand Down Expand Up @@ -1206,7 +1204,7 @@ def test_magic_default() -> None:
assert a(MAGIC) == MAGIC

[case testI64UndefinedLocal]
from typing_extensions import Final
from typing import Final

from mypy_extensions import i64, i32

Expand Down Expand Up @@ -1338,8 +1336,7 @@ def test_many_locals() -> None:
assert a33 == 20

[case testI64GlueMethodsAndInheritance]
from typing import Any
from typing_extensions import Final
from typing import Final, Any

from mypy_extensions import i64, trait

Expand Down
3 changes: 1 addition & 2 deletions mypyc/test-data/run-math.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Test cases for the math module (compile and run)

[case testMathOps]
from typing import Any, Callable
from typing_extensions import Final
from typing import Any, Callable, Final
import math
from math import pi, e, tau, inf, nan
from testutil import assertRaises, float_vals, assertDomainError, assertMathRangeError
Expand Down
6 changes: 3 additions & 3 deletions mypyc/test-data/run-multimodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def f(c: C) -> int:
c = cast(C, o)
return a_global + c.x + c.f() + d.x + d.f() + 1
[file other.py]
from typing_extensions import Final
from typing import Final
a_global: Final = int('5')

class C:
Expand Down Expand Up @@ -735,11 +735,11 @@ def foo() -> int:
return X

[file other.py]
from typing_extensions import Final
from typing import Final
X: Final = 10

[file other.py.2]
from typing_extensions import Final
from typing import Final
X: Final = 20

[file driver.py]
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test-data/run-sets.test
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ def test_frozen_sets_from_iterables() -> None:
assert g4() == frozenset({11, 21, 31})

[case testPrecomputedFrozenSets]
from typing import Any
from typing_extensions import Final
from typing import Final, Any

CONST: Final = "CONST"
non_const = "non_const"
Expand Down
6 changes: 2 additions & 4 deletions mypyc/test-data/run-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ assert f(Sub(3, 2)) == 3

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

class FuncIR: pass

Expand Down Expand Up @@ -147,8 +146,7 @@ assert Record.__annotations__ == {
}, Record.__annotations__

[case testTupleOps]
from typing import Tuple, List, Any, Optional
from typing_extensions import Final
from typing import Tuple, Final, List, Any, Optional

def f() -> Tuple[()]:
return ()
Expand Down
3 changes: 1 addition & 2 deletions mypyc/test-data/run-u8.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[case testU8BasicOps]
from typing import Any, Tuple
from typing import Any, Final, Tuple

from mypy_extensions import u8, i16, i32, i64
from typing_extensions import Final

from testutil import assertRaises

Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ class B(Enum):
b = 10

[file b.py]
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
from typing_extensions import Final
from typing import Final, List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
from enum import Enum
import a
class A: pass
Expand Down
20 changes: 7 additions & 13 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ reveal_type(Animal.DOG) # N: Revealed type is "Literal[__main__.Animal.DOG]?"

[case testEnumCreatedFromFinalValue]
from enum import Enum
from typing_extensions import Final
from typing import Final

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

[case testEnumReachabilityChecksIndirect]
from enum import Enum
from typing import Literal
from typing_extensions import Final
from typing import Final, Literal

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

[case testEnumReachabilityPEP484ExampleWithFinal]
from typing import Union
from typing_extensions import Final
from typing import Final, Union
from enum import Enum

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


[case testEnumReachabilityPEP484ExampleSingleton]
from typing import Union
from typing_extensions import Final
from typing import Final, Union
from enum import Enum

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

[case testEnumReachabilityPEP484ExampleSingletonWithMethod]
from typing import Union
from typing_extensions import Final
from typing import Final, Union
from enum import Enum

class Empty(Enum):
Expand Down Expand Up @@ -1331,8 +1327,7 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
[case testEnumReachabilityWithChainingDirectConflict]
# flags: --warn-unreachable
from enum import Enum
from typing import Literal
from typing_extensions import Final
from typing import Final, Literal

class Foo(Enum):
A = 1
Expand Down Expand Up @@ -1367,8 +1362,7 @@ reveal_type(x) # N: Revealed type is "__main__.Foo"
[case testEnumReachabilityWithChainingBigDisjoints]
# flags: --warn-unreachable
from enum import Enum
from typing import Literal
from typing_extensions import Final
from typing import Final, Literal

class Foo(Enum):
A = 1
Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2281,8 +2281,7 @@ def f(x: T) -> T:

[case testStrictEqualityWithALiteral]
# flags: --strict-equality
from typing import Literal
from typing_extensions import Final
from typing import Final, Literal

def returns_a_or_b() -> Literal['a', 'b']:
...
Expand Down
Loading