Skip to content

Commit

Permalink
Implemented conformance tests for Enums chapter. (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
erictraut authored Jun 4, 2024
1 parent 9a21598 commit 84bed8b
Show file tree
Hide file tree
Showing 39 changed files with 937 additions and 6 deletions.
7 changes: 7 additions & 0 deletions conformance/results/mypy/enums_behaviors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
conformant = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39: error: Cannot extend enum with existing members: "Shape" [misc]
"""
conformance_automated = "Pass"
6 changes: 6 additions & 0 deletions conformance/results/mypy/enums_definition.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Pass"
errors_diff = """
"""
output = """
"""
conformance_automated = "Pass"
12 changes: 12 additions & 0 deletions conformance/results/mypy/enums_expansion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
conformant = "Partial"
notes = """
Improperly applies narrowing to Flag subclass.
"""
conformance_automated = "Fail"
errors_diff = """
Line 53: Expected 1 errors
Line 52: Unexpected errors ['enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]']
"""
output = """
enums_expansion.py:52: error: Expression is of type "Literal[CustomFlags.FLAG3]", not "CustomFlags" [assert-type]
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/enums_member_names.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
conformant = "Pass"
notes = """
Does not support special-cased handling of member name literal types in some cases (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_member_names.py:26: error: Expression is of type "str", not "Literal['RED', 'BLUE']" [assert-type]
enums_member_names.py:30: error: Expression is of type "str", not "Literal['RED', 'BLUE', 'GREEN']" [assert-type]
"""
16 changes: 16 additions & 0 deletions conformance/results/mypy/enums_member_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
conformant = "Partial"
notes = """
Does not enforce declared type of `_value_`.
Does not enforce assigned tuple types for enum members (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 78: Expected 1 errors
"""
output = """
enums_member_values.py:26: error: Expression is of type "Any", not "Literal[1, 3]" [assert-type]
enums_member_values.py:54: error: Expression is of type "tuple[int, float, float]", not "Literal[1]" [assert-type]
enums_member_values.py:68: error: Expression is of type "int", not "Literal[1]" [assert-type]
enums_member_values.py:85: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment]
enums_member_values.py:96: error: Expression is of type "EllipsisType", not "int" [assert-type]
"""
42 changes: 42 additions & 0 deletions conformance/results/mypy/enums_members.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
conformant = "Partial"
notes = """
Does not treat attribute with annotation and no assignment as non-member.
Does not reject use of annotation with enum member.
Does not treat callables as non-members.
Does not honor `enum.nonmember` to define non-member attribute.
Does not honor `enum.member` as method decorator.
Does not properly handle aliased enum members.
Does not support `_ignore_` mechanism (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 46: Expected 1 errors
Line 78: Expected 1 errors
Line 79: Expected 1 errors
Line 112: Expected 1 errors
Line 23: Unexpected errors ['enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]']
Line 24: Unexpected errors ['enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]']
Line 31: Unexpected errors ['enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]']
Line 32: Unexpected errors ['enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]']
Line 96: Unexpected errors ['enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]']
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]']
"""
output = """
enums_members.py:23: error: Expression is of type "Literal[Pet.genus]", not "str" [assert-type]
enums_members.py:24: error: Expression is of type "Literal[Pet.species]", not "str" [assert-type]
enums_members.py:31: error: Expression is of type "Literal[Pet2.genus]", not "str" [assert-type]
enums_members.py:32: error: Expression is of type "Literal[Pet2.species]", not "str" [assert-type]
enums_members.py:80: error: Expression is of type "Callable[[Pet4], str]", not "Any" [assert-type]
enums_members.py:80: error: Parameter 1 of Literal[...] is invalid [valid-type]
enums_members.py:81: error: Expression is of type "Callable[[Pet4], None]", not "Any" [assert-type]
enums_members.py:81: error: Parameter 1 of Literal[...] is invalid [valid-type]
enums_members.py:96: error: Expression is of type "Literal[TrafficLight.AMBER]", not "Literal[TrafficLight.YELLOW]" [assert-type]
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]
enums_members.py:124: note: Revealed type is "Any"
enums_members.py:124: note: 'reveal_type' always outputs 'Any' in unchecked functions
enums_members.py:125: error: Expression is of type "Any", not "Literal[Example2.__B]" [assert-type]
enums_members.py:125: note: "assert_type" expects everything to be "Any" in unchecked functions
enums_members.py:142: error: Expression is of type "Literal[Pet5.DOG]", not "int" [assert-type]
enums_members.py:143: error: Expression is of type "Literal[Pet5.FISH]", not "int" [assert-type]
"""
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.10.0"
test_duration = 1.5
test_duration = 0.9
10 changes: 10 additions & 0 deletions conformance/results/pyre/enums_behaviors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
conformant = "Partial"
notes = """
Does not enforce that Enum classes are implicitly final.
"""
conformance_automated = "Fail"
errors_diff = """
Line 39: Expected 1 errors
"""
output = """
"""
19 changes: 19 additions & 0 deletions conformance/results/pyre/enums_definition.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
conformant = "Partial"
notes = """
Does not support custom Enum classes based on EnumType metaclass.
Does not support some functional forms for Enum class definitions (optional).
"""
conformance_automated = "Fail"
errors_diff = """
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`.']
"""
output = """
enums_definition.py:24:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 4 were provided.
enums_definition.py:27:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:28:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:31:9 Too many arguments [19]: Call `Enum.__new__` expects 1 positional argument, 2 were provided.
enums_definition.py:33:12 Undefined attribute [16]: `Enum` has no attribute `RED`.
enums_definition.py:38:12 Undefined attribute [16]: `Color7` has no attribute `RED`.
enums_definition.py:39:12 Undefined attribute [16]: `Color8` has no attribute `RED`.
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`.
"""
12 changes: 12 additions & 0 deletions conformance/results/pyre/enums_expansion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
conformant = "Pass"
notes = """
Does not perform type narrowing based on enum literal expansion (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
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`.
enums_expansion.py:35:12 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Never` but got `Color`.
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`.
"""
13 changes: 13 additions & 0 deletions conformance/results/pyre/enums_member_names.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
conformant = "Pass"
notes = """
Does not support special-cased handling of member name literal types (optional).
"""
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_member_names.py:21:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal['RED']` but got `str`.
enums_member_names.py:22:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal['RED']` but got `typing.Any`.
enums_member_names.py:26:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal['BLUE'], typing_extensions.Literal['RED']]` but got `typing.Any`.
enums_member_names.py:30:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal['BLUE'], typing_extensions.Literal['GREEN'], typing_extensions.Literal['RED']]` but got `typing.Any`.
"""
23 changes: 23 additions & 0 deletions conformance/results/pyre/enums_member_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
conformant = "Partial"
notes = """
Does not enforce declared type of `_value_`.
Does not enforce assigned tuple types for enum members (optional).
Does not evaluate literal types for enum member values (optional).
Does not evaluate literal types for auto values (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 78: Expected 1 errors
Line 85: Expected 1 errors
Line 75: Unexpected errors ['enums_member_values.py:75:0 Uninitialized attribute [13]: Attribute `_value_` is declared in class `Color3` to have type `Color3` but is never initialized.']
"""
output = """
enums_member_values.py:21:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:22:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:26:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal[1], typing_extensions.Literal[3]]` but got `typing.Any`.
enums_member_values.py:30:4 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `Union[typing_extensions.Literal[1], typing_extensions.Literal[2], typing_extensions.Literal[3]]` but got `typing.Any`.
enums_member_values.py:54:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:68:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[1]` but got `typing.Any`.
enums_member_values.py:75:0 Uninitialized attribute [13]: Attribute `_value_` is declared in class `Color3` to have type `Color3` but is never initialized.
enums_member_values.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `typing.Any`.
"""
43 changes: 43 additions & 0 deletions conformance/results/pyre/enums_members.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
conformant = "Partial"
notes = """
Does not reject use of annotation with enum member.
Does not treat callables as non-members.
Does not treat annotated attributes as non-members.
Does not honor `enum.nonmember` to define non-member attribute.
Does not honor `enum.member` as method decorator.
Does not properly handle aliased enum members.
Rejects use of `_ignore_`.
Does not support `_ignore_` mechanism (optional).
"""
conformance_automated = "Fail"
errors_diff = """
Line 46: Expected 1 errors
Line 78: Expected 1 errors
Line 79: Expected 1 errors
Line 112: Expected 1 errors
Line 125: Expected 1 errors
Line 23: Unexpected errors ['enums_members.py:23:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.']
Line 24: Unexpected errors ['enums_members.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.']
Line 31: Unexpected errors ['enums_members.py:31:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.']
Line 32: Unexpected errors ['enums_members.py:32:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.']
Line 96: Unexpected errors ['enums_members.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[TrafficLight.YELLOW]` but got `typing_extensions.Literal[TrafficLight.AMBER]`.']
Line 113: Unexpected errors ['enums_members.py:113:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Example.c]` but got `member[typing.Callable(Example.c)[[Named(self, Example)], None]]`.']
Line 124: Unexpected errors ['enums_members.py:124:8 Revealed type [-1]: Revealed type for `enums_members.Example2._Example2__B` is `typing_extensions.Literal[Example2._Example2__B]` (final).']
Line 135: Unexpected errors ['enums_members.py:135:4 Inconsistent override [15]: `_ignore_` overrides attribute defined in `Enum` inconsistently. Type `Pet5` is not a subtype of the overridden attribute `typing.Union[typing.List[str], str]`.']
"""
output = """
enums_members.py:15:0 Uninitialized attribute [13]: Attribute `genus` is declared in class `Pet` to have type `Pet` but is never initialized.
enums_members.py:15:0 Uninitialized attribute [13]: Attribute `species` is declared in class `Pet` to have type `Pet` but is never initialized.
enums_members.py:23:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.
enums_members.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet`.
enums_members.py:31:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.
enums_members.py:32:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `str` but got `Pet2`.
enums_members.py:80:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Pet4.species]` but got `str`.
enums_members.py:81:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Pet4.speak]` but got `typing.Callable(Pet4.speak)[[Named(self, Pet4)], None]`.
enums_members.py:96:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[TrafficLight.YELLOW]` but got `typing_extensions.Literal[TrafficLight.AMBER]`.
enums_members.py:113:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `typing_extensions.Literal[Example.c]` but got `member[typing.Callable(Example.c)[[Named(self, Example)], None]]`.
enums_members.py:124:8 Revealed type [-1]: Revealed type for `enums_members.Example2._Example2__B` is `typing_extensions.Literal[Example2._Example2__B]` (final).
enums_members.py:135:4 Inconsistent override [15]: `_ignore_` overrides attribute defined in `Enum` inconsistently. Type `Pet5` is not a subtype of the overridden attribute `typing.Union[typing.List[str], str]`.
enums_members.py:142:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Pet5`.
enums_members.py:143:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Pet5`.
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "pyre 0.9.21"
test_duration = 4.1
test_duration = 2.6
7 changes: 7 additions & 0 deletions conformance/results/pyright/enums_behaviors.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
conformant = "Pass"
errors_diff = """
"""
output = """
enums_behaviors.py:39:21 - error: Enum class "Shape" is final and cannot be subclassed (reportGeneralTypeIssues)
"""
conformance_automated = "Pass"
6 changes: 6 additions & 0 deletions conformance/results/pyright/enums_definition.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Pass"
errors_diff = """
"""
output = """
"""
conformance_automated = "Pass"
16 changes: 16 additions & 0 deletions conformance/results/pyright/enums_expansion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
conformant = "Partial"
notes = """
Applies type narrowing incorrectly for `a is E` pattern where `E` is an enum member.
"""
conformance_automated = "Fail"
errors_diff = """
Line 78: Unexpected errors ['enums_expansion.py:78:12 - error: Expression of type "list[Never]" is incompatible with return type "list[Answer]"']
"""
output = """
enums_expansion.py:53:21 - error: "assert_type" mismatch: expected "Literal[CustomFlags.FLAG3]" but received "CustomFlags" (reportAssertTypeFailure)
enums_expansion.py:78:12 - error: Expression of type "list[Never]" is incompatible with return type "list[Answer]"
  "list[Never]" is incompatible with "list[Answer]"
    Type parameter "_T@list" is invariant, but "Never" is not the same as "Answer"
    Consider switching from "list" to "Sequence" which is covariant (reportReturnType)
"""
6 changes: 6 additions & 0 deletions conformance/results/pyright/enums_member_names.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Pass"
conformance_automated = "Pass"
errors_diff = """
"""
output = """
"""
14 changes: 14 additions & 0 deletions conformance/results/pyright/enums_member_values.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
conformant = "Pass"
conformance_automated = "Pass"
errors_diff = """
"""
output = """
enums_member_values.py:50:12 - error: Argument missing for parameter "radius" (reportCallIssue)
enums_member_values.py:51:15 - error: Arguments missing for parameters "mass", "radius" (reportCallIssue)
enums_member_values.py:54:13 - error: "assert_type" mismatch: expected "Literal[1]" but received "Any" (reportAssertTypeFailure)
enums_member_values.py:68:13 - error: "assert_type" mismatch: expected "Literal[1]" but received "int" (reportAssertTypeFailure)
enums_member_values.py:78:13 - error: Expression of type "Literal['green']" is incompatible with declared type "int"
  "Literal['green']" is incompatible with "int" (reportAssignmentType)
enums_member_values.py:85:24 - error: Cannot assign to attribute "_value_" for class "Planet2*"
  "int" is incompatible with "str" (reportAttributeAccessIssue)
"""
Loading

0 comments on commit 84bed8b

Please sign in to comment.