The Enum Literal Expansion section states that a complete union of all literal members is equivalent to the enum type. test3 in [conformance/tests/enums_expansion.py](https://github.com/python/typing/blob/main/conformance/tests/enums_expansion.py) is meant to cover this, but doesn't catch some cases.
Both pyright-1.1.411 and zuban-0.9.0 reject the following.
class Answer(enum.Enum):
Yes = 1
No = 2
a: Answer = ...
x: Literal[Answer.Yes, Answer.No] = a # both report an error here
pyright: Type "Answer" is not assignable to declared type "Literal[...]"; zuban: Incompatible types in assignment.
Suggested test
def test4(a: Answer) -> None:
x: Literal[Answer.Yes, Answer.No] = a # E?
assert_type(a, Literal[Answer.Yes, Answer.No])
This came up from the discussion at https://discuss.python.org/t/treat-literal-of-all-elements-of-enum-equal-to-the-enum-in-type-annotations/108317
The Enum Literal Expansion section states that a complete union of all literal members is equivalent to the enum type.
test3in[conformance/tests/enums_expansion.py](https://github.com/python/typing/blob/main/conformance/tests/enums_expansion.py)is meant to cover this, but doesn't catch some cases.Both
pyright-1.1.411andzuban-0.9.0reject the following.pyright:
Type "Answer" is not assignable to declared type "Literal[...]"; zuban:Incompatible types in assignment.Suggested test
This came up from the discussion at https://discuss.python.org/t/treat-literal-of-all-elements-of-enum-equal-to-the-enum-in-type-annotations/108317