Skip to content

Update Literal imports in tests #18640

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 9, 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
4 changes: 2 additions & 2 deletions mypyc/test-data/run-misc.test
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ for a in sorted(s):
9 8 72

[case testDummyTypes]
from typing import Tuple, List, Dict, NamedTuple
from typing_extensions import Literal, TypedDict, NewType
from typing import Tuple, List, Dict, Literal, NamedTuple
from typing_extensions import TypedDict, NewType

class A:
pass
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ class B(Enum):
b = 10

[file b.py]
from typing import List, Optional, Union, Sequence, NamedTuple, Tuple, Type
from typing_extensions import Literal, Final, TypedDict
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type
from typing_extensions import Final, TypedDict
from enum import Enum
import a
class A: pass
Expand Down
33 changes: 17 additions & 16 deletions test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if int():

[case testEnumCreatedFromStringLiteral]
from enum import Enum
from typing_extensions import Literal
from typing import Literal

x: Literal['ANT BEE CAT DOG'] = 'ANT BEE CAT DOG'
Animal = Enum('Animal', x)
Expand Down Expand Up @@ -181,7 +181,7 @@ def infer_truth(truth: Truth) -> None:
[case testEnumTruthyness]
# mypy: warn-unreachable
import enum
from typing_extensions import Literal
from typing import Literal

class E(enum.Enum):
zero = 0
Expand Down Expand Up @@ -213,7 +213,7 @@ def main(zero: Literal[E.zero], one: Literal[E.one]) -> None:
[case testEnumTruthynessCustomDunderBool]
# mypy: warn-unreachable
import enum
from typing_extensions import Literal
from typing import Literal

class E(enum.Enum):
zero = 0
Expand Down Expand Up @@ -247,7 +247,7 @@ def main(zero: Literal[E.zero], one: Literal[E.one]) -> None:
[case testEnumTruthynessStrEnum]
# mypy: warn-unreachable
import enum
from typing_extensions import Literal
from typing import Literal

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

[case testEnumAttributeAccessMatrix]
from enum import Enum, IntEnum, IntFlag, Flag, EnumMeta, auto
from typing_extensions import Literal
from typing import Literal

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

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

[case testEnumReachabilityChecksBasic]
from enum import Enum
from typing_extensions import Literal
from typing import Literal

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

[case testEnumReachabilityChecksWithOrdering]
from enum import Enum
from typing_extensions import Literal
from typing import Literal

class Foo(Enum):
_order_ = "A B"
Expand Down Expand Up @@ -975,7 +975,8 @@ else:

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

class Foo(Enum):
A = 1
Expand Down Expand Up @@ -1040,7 +1041,7 @@ else:

[case testEnumReachabilityNoNarrowingForUnionMessiness]
from enum import Enum
from typing_extensions import Literal
from typing import Literal

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

[case testEnumReachabilityWithMultipleEnums]
from enum import Enum
from typing import Union
from typing_extensions import Literal
from typing import Literal, Union

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

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

class Foo(Enum):
A = 1
Expand Down Expand Up @@ -1488,8 +1490,7 @@ reveal_type(a._value_) # N: Revealed type is "Any"
# as the full type, regardless of the amount of elements
# the enum contains.
from enum import Enum
from typing import Union
from typing_extensions import Literal
from typing import Literal, Union

class Foo(Enum):
A = 1
Expand All @@ -1507,7 +1508,7 @@ def f(x: Foo):

[case testEnumTypeCompatibleWithLiteralUnion]
from enum import Enum
from typing_extensions import Literal
from typing import Literal

class E(Enum):
A = 1
Expand Down
9 changes: 4 additions & 5 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,7 @@ main:4: error: "A" not callable
-- assert_type()

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

[case testAssertTypeGeneric]
from typing import assert_type, TypeVar, Generic
from typing_extensions import Literal
from typing import assert_type, Literal, TypeVar, Generic
T = TypeVar("T")
def f(x: T) -> T: return x
assert_type(f(1), int)
Expand Down Expand Up @@ -2283,7 +2281,8 @@ def f(x: T) -> T:

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

def returns_a_or_b() -> Literal['a', 'b']:
...
Expand Down
6 changes: 4 additions & 2 deletions test-data/unit/check-final.test
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ class Child(Parent):
def __bar(self) -> None: ...

[case testFinalWithoutBool]
from typing_extensions import final, Literal
from typing import Literal
from typing_extensions import final

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

[case testFinalWithoutBoolButWithLen]
from typing_extensions import final, Literal
from typing import Literal
from typing_extensions import final

# Per Python data model, __len__ is called if __bool__ does not exist.
# In a @final class, __bool__ would not exist.
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5080,10 +5080,10 @@ plugins=<ROOT>/test-data/unit/plugins/config_data.py
import mod
reveal_type(mod.a)
[file mod.py]
from typing_extensions import Literal
from typing import Literal
a = 1
[file mod.py.2]
from typing_extensions import Literal
from typing import Literal
a: Literal[2] = 2
[builtins fixtures/tuple.pyi]
[out]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-isinstance.test
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ if isinstance(y, B):
# flags: --warn-unreachable

from abc import abstractmethod
from typing_extensions import Literal
from typing import Literal

class A0:
def f(self) -> Literal[0]:
Expand Down
Loading