You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add conformance test for full literal-union equivalency of enums
The spec's Enum Literal Expansion section states that a type checker
should treat a complete union of all literal members as equivalent to
the enum type. Add test to cover cases failing in some checkers.
Also refreshes all three quoted spec passages, which had drifted from
the section as rewritten in a6eeccf ("new type system concepts section",
Reported in #2323.
* Update conformance results for the new enum expansion test
Four checkers accept the full-literal-union equivalency and are
unaffected: mypy, pyrefly, pycroscope and ty (mypy and ty remain
"Partial" for the pre-existing `Flag` narrowing gap only). Three drop
from "Pass" to "Partial":
* pyright and zuban reject both the assignment and the `assert_type`.
* basilisk rejects only the assignment; it reports the `assert_type` in
test1 as redundant, so it does treat the two types as equivalent
there.
Does not accept an enum-typed value where a complete union of all literal members is declared, although it treats the two as equivalent for `assert_type`.
4
+
"""
5
+
conformance_automated = "Fail"
3
6
errors_diff = """
7
+
Line 85: Unexpected errors ['enums_expansion.py:85:5: error: Type mismatch: `x` is annotated `Literal[Answer.Yes, Answer.No]` (answer.yes | answer.no) but assigned answer [assignment_compatibility]']
4
8
"""
5
9
output = """
6
-
enums_expansion.py:25:9: error: Redundant `assert_type` with `Literal[Color.GREEN]` on enum-typed parameter [enums_expansion]
7
-
enums_expansion.py:53:9: error: Redundant `assert_type` with `Literal[CustomFlags.FLAG3]` on enum-typed parameter [enums_expansion]
10
+
enums_expansion.py:28:9: error: Redundant `assert_type` with `Literal[Color.GREEN]` on enum-typed parameter [enums_expansion]
11
+
enums_expansion.py:56:9: error: Redundant `assert_type` with `Literal[CustomFlags.FLAG3]` on enum-typed parameter [enums_expansion]
12
+
enums_expansion.py:85:5: error: Type mismatch: `x` is annotated `Literal[Answer.Yes, Answer.No]` (answer.yes | answer.no) but assigned answer [assignment_compatibility]
Copy file name to clipboardExpand all lines: conformance/results/ty/enums_expansion.toml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,5 +2,5 @@ conformance_automated = "Pass"
2
2
errors_diff = """
3
3
"""
4
4
output = """
5
-
enums_expansion.py:53:9: error[type-assertion-failure] Type `CustomFlags & ~Literal[CustomFlags.FLAG1] & ~Literal[CustomFlags.FLAG2]` does not match asserted type `Literal[CustomFlags.FLAG3]`
5
+
enums_expansion.py:56:9: error[type-assertion-failure] Type `CustomFlags & ~Literal[CustomFlags.FLAG1] & ~Literal[CustomFlags.FLAG2]` does not match asserted type `Literal[CustomFlags.FLAG3]`
Does not treat a complete union of all literal members as equivalent to the enum type.
4
+
"""
5
+
conformance_automated = "Fail"
2
6
errors_diff = """
7
+
Line 85: Unexpected errors ['enums_expansion.py:85: error: Incompatible types in assignment (expression has type "Answer", variable has type "Literal[Answer.Yes, Answer.No]") [assignment]']
8
+
Line 86: Unexpected errors ['enums_expansion.py:86: error: Expression is of type "Answer", not "Literal[Answer.Yes, Answer.No]" [misc]']
3
9
"""
4
10
output = """
5
-
enums_expansion.py:35: error: Statement is unreachable [unreachable]
6
-
enums_expansion.py:53: error: Expression is of type "CustomFlags", not "Literal[CustomFlags.FLAG3]" [misc]
11
+
enums_expansion.py:38: error: Statement is unreachable [unreachable]
12
+
enums_expansion.py:56: error: Expression is of type "CustomFlags", not "Literal[CustomFlags.FLAG3]" [misc]
13
+
enums_expansion.py:85: error: Incompatible types in assignment (expression has type "Answer", variable has type "Literal[Answer.Yes, Answer.No]") [assignment]
14
+
enums_expansion.py:86: error: Expression is of type "Answer", not "Literal[Answer.Yes, Answer.No]" [misc]
0 commit comments