Skip to content

Commit 84bed8b

Browse files
authored
Implemented conformance tests for Enums chapter. (#1764)
1 parent 9a21598 commit 84bed8b

39 files changed

+937
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
conformant = "Pass"
2+
errors_diff = """
3+
"""
4+
output = """
5+
enums_behaviors.py:39: error: Cannot extend enum with existing members: "Shape" [misc]
6+
"""
7+
conformance_automated = "Pass"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
conformant = "Pass"
2+
errors_diff = """
3+
"""
4+
output = """
5+
"""
6+
conformance_automated = "Pass"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
conformant = "Partial"
2+
notes = """
3+
Improperly applies narrowing to Flag subclass.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 53: Expected 1 errors
8+
Line 52: Unexpected errors ['enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]']
9+
"""
10+
output = """
11+
enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]
12+
"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
conformant = "Pass"
2+
notes = """
3+
Does not support special-cased handling of member name literal types in some cases (optional).
4+
"""
5+
conformance_automated = "Pass"
6+
errors_diff = """
7+
"""
8+
output = """
9+
enums_member_names.py:26: error: Expression is of type "str", not "Literal['RED', 'BLUE']" [assert-type]
10+
enums_member_names.py:30: error: Expression is of type "str", not "Literal['RED', 'BLUE', 'GREEN']" [assert-type]
11+
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not enforce declared type of `_value_`.
4+
Does not enforce assigned tuple types for enum members (optional).
5+
"""
6+
conformance_automated = "Fail"
7+
errors_diff = """
8+
Line 78: Expected 1 errors
9+
"""
10+
output = """
11+
enums_member_values.py:26: error: Expression is of type "Any", not "Literal[1, 3]" [assert-type]
12+
enums_member_values.py:54: error: Expression is of type "tuple[int, float, float]", not "Literal[1]" [assert-type]
13+
enums_member_values.py:68: error: Expression is of type "int", not "Literal[1]" [assert-type]
14+
enums_member_values.py:85: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
15+
enums_member_values.py:96: error: Expression is of type "EllipsisType", not "int" [assert-type]
16+
"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not treat attribute with annotation and no assignment as non-member.
4+
Does not reject use of annotation with enum member.
5+
Does not treat callables as non-members.
6+
Does not honor `enum.nonmember` to define non-member attribute.
7+
Does not honor `enum.member` as method decorator.
8+
Does not properly handle aliased enum members.
9+
Does not support `_ignore_` mechanism (optional).
10+
"""
11+
conformance_automated = "Fail"
12+
errors_diff = """
13+
Line 46: Expected 1 errors
14+
Line 78: Expected 1 errors
15+
Line 79: Expected 1 errors
16+
Line 112: Expected 1 errors
17+
Line 23: Unexpected errors ['enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]']
18+
Line 24: Unexpected errors ['enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]']
19+
Line 31: Unexpected errors ['enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]']
20+
Line 32: Unexpected errors ['enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]']
21+
Line 96: Unexpected errors ['enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]']
22+
Line 113: Unexpected errors ['enums_members.py:113: error: Expression is of type "member[Callable[[Example], None]]", not "Any" [assert-type]', 'enums_members.py:113: error: Parameter 1 of Literal[...] is invalid [valid-type]']
23+
"""
24+
output = """
25+
enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]
26+
enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]
27+
enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]
28+
enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]
29+
enums_members.py:80: error: Expression is of type "Callable[[Pet4], str]", not "Any" [assert-type]
30+
enums_members.py:80: error: Parameter 1 of Literal[...] is invalid [valid-type]
31+
enums_members.py:81: error: Expression is of type "Callable[[Pet4], None]", not "Any" [assert-type]
32+
enums_members.py:81: error: Parameter 1 of Literal[...] is invalid [valid-type]
33+
enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]
34+
enums_members.py:113: error: Expression is of type "member[Callable[[Example], None]]", not "Any" [assert-type]
35+
enums_members.py:113: error: Parameter 1 of Literal[...] is invalid [valid-type]
36+
enums_members.py:124: note: Revealed type is "Any"
37+
enums_members.py:124: note: 'reveal_type' always outputs 'Any' in unchecked functions
38+
enums_members.py:125: error: Expression is of type "Any", not "Literal[Example2.__B]" [assert-type]
39+
enums_members.py:125: note: "assert_type" expects everything to be "Any" in unchecked functions
40+
enums_members.py:142: error: Expression is of type "Literal[Pet5.DOG]", not "int" [assert-type]
41+
enums_members.py:143: error: Expression is of type "Literal[Pet5.FISH]", not "int" [assert-type]
42+
"""

conformance/results/mypy/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.10.0"
2-
test_duration = 1.5
2+
test_duration = 0.9
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not enforce that Enum classes are implicitly final.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 39: Expected 1 errors
8+
"""
9+
output = """
10+
"""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
conformant = "Partial"
2+
notes = """
3+
Does not support custom Enum classes based on EnumType metaclass.
4+
Does not support some functional forms for Enum class definitions (optional).
5+
"""
6+
conformance_automated = "Fail"
7+
errors_diff = """
8+
Line 75: Unexpected errors ['enums_definition.py:75:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color11.RED]` but got `int`.']
9+
"""
10+
output = """
11+
enums_definition.py:24:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 4 were provided.
12+
enums_definition.py:27:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
13+
enums_definition.py:28:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
14+
enums_definition.py:31:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
15+
enums_definition.py:33:12 Undefined attribute [16]: `Enum` has no attribute `RED`.
16+
enums_definition.py:38:12 Undefined attribute [16]: `Color7` has no attribute `RED`.
17+
enums_definition.py:39:12 Undefined attribute [16]: `Color8` has no attribute `RED`.
18+
enums_definition.py:75:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color11.RED]` but got `int`.
19+
"""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
conformant = "Pass"
2+
notes = """
3+
Does not perform type narrowing based on enum literal expansion (optional).
4+
"""
5+
conformance_automated = "Pass"
6+
errors_diff = """
7+
"""
8+
output = """
9+
enums_expansion.py:25:8 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Color.GREEN]` but got `Color`.
10+
enums_expansion.py:35:12 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Never` but got `Color`.
11+
enums_expansion.py:53:8 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[CustomFlags.FLAG3]` but got `CustomFlags`.
12+
"""

0 commit comments

Comments
 (0)