Skip to content

Commit

Permalink
Fixed a bug in the conformance test for ClassVar qualifier (#1742)
Browse files Browse the repository at this point in the history
Fixed a bug in the conformance test for `ClassVar` qualifier. The test was not importing `Final`, so it was not really testing what it intended.
Also added some additional comments to the recently-added test for `dataclasses_final` for consistency with other tests.
  • Loading branch information
erictraut authored May 21, 2024
1 parent 2d2e8ee commit d586ae4
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 130 deletions.
44 changes: 22 additions & 22 deletions conformance/results/mypy/classes_classvar.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ Does not reject use of ClassVar in TypeAlias definition.
Does not infer type of ClassVar from assignment if no type is provided.
"""
output = """
classes_classvar.py:36: error: ClassVar[...] must have at most one type argument [valid-type]
classes_classvar.py:37: error: Invalid type: try using Literal[3] instead? [valid-type]
classes_classvar.py:38: error: Name "var" is not defined [name-defined]
classes_classvar.py:43: error: ClassVar cannot contain type variables [misc]
classes_classvar.py:37: error: ClassVar[...] must have at most one type argument [valid-type]
classes_classvar.py:38: error: Invalid type: try using Literal[3] instead? [valid-type]
classes_classvar.py:39: error: Name "var" is not defined [name-defined]
classes_classvar.py:44: error: ClassVar cannot contain type variables [misc]
classes_classvar.py:50: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment]
classes_classvar.py:52: error: Name "Final" is not defined [name-defined]
classes_classvar.py:53: error: Invalid type: ClassVar nested inside other type [valid-type]
classes_classvar.py:59: error: Invalid type: ClassVar nested inside other type [valid-type]
classes_classvar.py:61: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:45: error: ClassVar cannot contain type variables [misc]
classes_classvar.py:51: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment]
classes_classvar.py:53: error: Variable should not be annotated with both ClassVar and Final [misc]
classes_classvar.py:54: error: Invalid type: ClassVar nested inside other type [valid-type]
classes_classvar.py:60: error: Invalid type: ClassVar nested inside other type [valid-type]
classes_classvar.py:62: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:63: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:65: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:69: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:76: error: Expression is of type "Any", not "float" [assert-type]
classes_classvar.py:100: error: Cannot assign to class variable "stats" via instance [misc]
classes_classvar.py:129: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment]
classes_classvar.py:129: note: "ProtoAImpl" is missing following "ProtoA" protocol member:
classes_classvar.py:129: note: z
classes_classvar.py:129: note: Protocol member ProtoA.x expected class variable, got instance variable
classes_classvar.py:129: note: Protocol member ProtoA.y expected class variable, got instance variable
classes_classvar.py:64: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:66: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:70: error: ClassVar can only be used for assignments in class body [misc]
classes_classvar.py:77: error: Expression is of type "Any", not "float" [assert-type]
classes_classvar.py:101: error: Cannot assign to class variable "stats" via instance [misc]
classes_classvar.py:130: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment]
classes_classvar.py:130: note: "ProtoAImpl" is missing following "ProtoA" protocol member:
classes_classvar.py:130: note: z
classes_classvar.py:130: note: Protocol member ProtoA.x expected class variable, got instance variable
classes_classvar.py:130: note: Protocol member ProtoA.y expected class variable, got instance variable
"""
conformance_automated = "Fail"
errors_diff = """
Line 45: Expected 1 errors
Line 70: Expected 1 errors
Line 59: Unexpected errors ['classes_classvar.py:59: error: Invalid type: ClassVar nested inside other type [valid-type]']
Line 76: Unexpected errors ['classes_classvar.py:76: error: Expression is of type "Any", not "float" [assert-type]']
Line 46: Expected 1 errors
Line 71: Expected 1 errors
Line 60: Unexpected errors ['classes_classvar.py:60: error: Invalid type: ClassVar nested inside other type [valid-type]']
Line 77: Unexpected errors ['classes_classvar.py:77: error: Expression is of type "Any", not "float" [assert-type]']
"""
28 changes: 16 additions & 12 deletions conformance/results/mypy/dataclasses_final.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ Doesn't support Final nested inside ClassVar.
"""
conformance_automated = "Fail"
errors_diff = """
Line 16: Expected 1 errors
Line 6: Unexpected errors ['dataclasses_final.py:6: error: Final name must be initialized with a value [misc]']
Line 8: Unexpected errors ['dataclasses_final.py:8: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]']
Line 13: Unexpected errors ['dataclasses_final.py:13: error: Expression is of type "Any", not "int" [assert-type]']
Line 27: Expected 1 errors
Line 38: Expected 1 errors
Line 41: Expected 1 errors
Line 16: Unexpected errors ['dataclasses_final.py:16: error: Final name must be initialized with a value [misc]']
Line 18: Unexpected errors ['dataclasses_final.py:18: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]']
Line 24: Unexpected errors ['dataclasses_final.py:24: error: Expression is of type "Any", not "int" [assert-type]']
Line 37: Unexpected errors ['dataclasses_final.py:37: error: Cannot access final instance attribute "final_no_default" on class object [misc]', 'dataclasses_final.py:37: error: Cannot assign to final attribute "final_no_default" [misc]']
Line 40: Unexpected errors ['dataclasses_final.py:40: error: Cannot assign to final attribute "final_with_default" [misc]']
"""
output = """
dataclasses_final.py:6: error: Final name must be initialized with a value [misc]
dataclasses_final.py:8: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
dataclasses_final.py:13: error: Expression is of type "Any", not "int" [assert-type]
dataclasses_final.py:24: error: Cannot assign to final attribute "final_no_default" [misc]
dataclasses_final.py:25: error: Cannot assign to final attribute "final_with_default" [misc]
dataclasses_final.py:26: error: Cannot access final instance attribute "final_no_default" on class object [misc]
dataclasses_final.py:26: error: Cannot assign to final attribute "final_no_default" [misc]
dataclasses_final.py:27: error: Cannot assign to final attribute "final_with_default" [misc]
dataclasses_final.py:16: error: Final name must be initialized with a value [misc]
dataclasses_final.py:18: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
dataclasses_final.py:24: error: Expression is of type "Any", not "int" [assert-type]
dataclasses_final.py:35: error: Cannot assign to final attribute "final_no_default" [misc]
dataclasses_final.py:36: error: Cannot assign to final attribute "final_with_default" [misc]
dataclasses_final.py:37: error: Cannot access final instance attribute "final_no_default" on class object [misc]
dataclasses_final.py:37: error: Cannot assign to final attribute "final_no_default" [misc]
dataclasses_final.py:40: error: Cannot assign to final attribute "final_with_default" [misc]
"""
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.0
test_duration = 1.4
46 changes: 23 additions & 23 deletions conformance/results/pyre/classes_classvar.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ Does not reject use of ClassVar in type alias definition.
Does not infer type from initialization for bare ClassVar.
"""
output = """
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad5` is declared in class `ClassA` to have type `typing.List[Variable[T]]` but is never initialized.
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad6` is declared in class `ClassA` to have type `typing.Callable[classes_classvar.P, typing.Any]` but is never initialized.
classes_classvar.py:36:10 Invalid type parameters [24]: Generic type `CV` expects 1 type parameter, received 2.
classes_classvar.py:37:10 Invalid type [31]: Expression `typing.ClassVar[3]` is not a valid type.
classes_classvar.py:38:13 Unbound name [10]: Name `var` is used but not defined in the current scope.
classes_classvar.py:50:4 Incompatible attribute type [8]: Attribute `bad8` declared in class `ClassA` has type `List[str]` but is used as type `Dict[Variable[_KT], Variable[_VT]]`.
classes_classvar.py:52:10 Unbound name [10]: Name `Final` is used but not defined in the current scope.
classes_classvar.py:63:8 Undefined attribute [16]: `ClassA` has no attribute `xx`.
classes_classvar.py:66:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.
classes_classvar.py:76:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.
classes_classvar.py:79:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.
classes_classvar.py:100:0 Invalid assignment [41]: Assigning to class variable through instance, did you mean to assign to `Starship.stats` instead?
classes_classvar.py:129:0 Incompatible variable type [9]: a is declared to have type `ProtoA` but is used as type `ProtoAImpl`.
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad5` is declared in class `ClassA` to have type `typing.List[Variable[T]]` but is never initialized.
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad6` is declared in class `ClassA` to have type `typing.Callable[classes_classvar.P, typing.Any]` but is never initialized.
classes_classvar.py:37:10 Invalid type parameters [24]: Generic type `CV` expects 1 type parameter, received 2.
classes_classvar.py:38:10 Invalid type [31]: Expression `typing.ClassVar[3]` is not a valid type.
classes_classvar.py:39:13 Unbound name [10]: Name `var` is used but not defined in the current scope.
classes_classvar.py:51:4 Incompatible attribute type [8]: Attribute `bad8` declared in class `ClassA` has type `List[str]` but is used as type `Dict[Variable[_KT], Variable[_VT]]`.
classes_classvar.py:64:8 Undefined attribute [16]: `ClassA` has no attribute `xx`.
classes_classvar.py:67:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.
classes_classvar.py:77:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.
classes_classvar.py:80:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.
classes_classvar.py:101:0 Invalid assignment [41]: Assigning to class variable through instance, did you mean to assign to `Starship.stats` instead?
classes_classvar.py:130:0 Incompatible variable type [9]: a is declared to have type `ProtoA` but is used as type `ProtoAImpl`.
"""
conformance_automated = "Fail"
errors_diff = """
Line 43: Expected 1 errors
Line 44: Expected 1 errors
Line 45: Expected 1 errors
Line 46: Expected 1 errors
Line 53: Expected 1 errors
Line 61: Expected 1 errors
Line 54: Expected 1 errors
Line 62: Expected 1 errors
Line 65: Expected 1 errors
Line 69: Expected 1 errors
Line 63: Expected 1 errors
Line 66: Expected 1 errors
Line 70: Expected 1 errors
Line 33: Unexpected errors ['classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.', 'classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.', 'classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad5` is declared in class `ClassA` to have type `typing.List[Variable[T]]` but is never initialized.', 'classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad6` is declared in class `ClassA` to have type `typing.Callable[classes_classvar.P, typing.Any]` but is never initialized.']
Line 66: Unexpected errors ['classes_classvar.py:66:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.']
Line 76: Unexpected errors ['classes_classvar.py:76:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.']
Line 79: Unexpected errors ['classes_classvar.py:79:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.']
Line 71: Expected 1 errors
Line 34: Unexpected errors ['classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.', 'classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.', 'classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad5` is declared in class `ClassA` to have type `typing.List[Variable[T]]` but is never initialized.', 'classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad6` is declared in class `ClassA` to have type `typing.Callable[classes_classvar.P, typing.Any]` but is never initialized.']
Line 67: Unexpected errors ['classes_classvar.py:67:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.']
Line 77: Unexpected errors ['classes_classvar.py:77:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.']
Line 80: Unexpected errors ['classes_classvar.py:80:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.']
"""
24 changes: 14 additions & 10 deletions conformance/results/pyre/dataclasses_final.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ Mis-handles Final nested inside ClassVar.
"""
conformance_automated = "Fail"
errors_diff = """
Line 8: Unexpected errors ['dataclasses_final.py:8:4 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.', 'dataclasses_final.py:8:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.']
Line 13: Unexpected errors ['dataclasses_final.py:13:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.']
Line 38: Expected 1 errors
Line 41: Expected 1 errors
Line 18: Unexpected errors ['dataclasses_final.py:18:4 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.', 'dataclasses_final.py:18:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.']
Line 24: Unexpected errors ['dataclasses_final.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.']
Line 37: Unexpected errors ['dataclasses_final.py:37:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.']
Line 40: Unexpected errors ['dataclasses_final.py:40:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.']
"""
output = """
dataclasses_final.py:8:4 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.
dataclasses_final.py:8:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.
dataclasses_final.py:13:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.
dataclasses_final.py:16:0 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.
dataclasses_final.py:24:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_no_default`.
dataclasses_final.py:25:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_with_default`.
dataclasses_final.py:26:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.
dataclasses_final.py:27:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.
dataclasses_final.py:18:4 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.
dataclasses_final.py:18:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.
dataclasses_final.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.
dataclasses_final.py:27:0 Incompatible attribute type [8]: Attribute `final_classvar` declared in class `D` has type `Final[int]` but is used as type `int`.
dataclasses_final.py:35:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_no_default`.
dataclasses_final.py:36:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_with_default`.
dataclasses_final.py:37:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.
dataclasses_final.py:40:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.
"""
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 = 1.9
test_duration = 3.4
Loading

0 comments on commit d586ae4

Please sign in to comment.