Skip to content

Commit d586ae4

Browse files
authored
Fixed a bug in the conformance test for ClassVar qualifier (#1742)
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.
1 parent 2d2e8ee commit d586ae4

15 files changed

+160
-130
lines changed

conformance/results/mypy/classes_classvar.toml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ Does not reject use of ClassVar in TypeAlias definition.
77
Does not infer type of ClassVar from assignment if no type is provided.
88
"""
99
output = """
10-
classes_classvar.py:36: error: ClassVar[...] must have at most one type argument [valid-type]
11-
classes_classvar.py:37: error: Invalid type: try using Literal[3] instead? [valid-type]
12-
classes_classvar.py:38: error: Name "var" is not defined [name-defined]
13-
classes_classvar.py:43: error: ClassVar cannot contain type variables [misc]
10+
classes_classvar.py:37: error: ClassVar[...] must have at most one type argument [valid-type]
11+
classes_classvar.py:38: error: Invalid type: try using Literal[3] instead? [valid-type]
12+
classes_classvar.py:39: error: Name "var" is not defined [name-defined]
1413
classes_classvar.py:44: error: ClassVar cannot contain type variables [misc]
15-
classes_classvar.py:50: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment]
16-
classes_classvar.py:52: error: Name "Final" is not defined [name-defined]
17-
classes_classvar.py:53: error: Invalid type: ClassVar nested inside other type [valid-type]
18-
classes_classvar.py:59: error: Invalid type: ClassVar nested inside other type [valid-type]
19-
classes_classvar.py:61: error: ClassVar can only be used for assignments in class body [misc]
14+
classes_classvar.py:45: error: ClassVar cannot contain type variables [misc]
15+
classes_classvar.py:51: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "list[str]") [assignment]
16+
classes_classvar.py:53: error: Variable should not be annotated with both ClassVar and Final [misc]
17+
classes_classvar.py:54: error: Invalid type: ClassVar nested inside other type [valid-type]
18+
classes_classvar.py:60: error: Invalid type: ClassVar nested inside other type [valid-type]
2019
classes_classvar.py:62: error: ClassVar can only be used for assignments in class body [misc]
2120
classes_classvar.py:63: error: ClassVar can only be used for assignments in class body [misc]
22-
classes_classvar.py:65: error: ClassVar can only be used for assignments in class body [misc]
23-
classes_classvar.py:69: error: ClassVar can only be used for assignments in class body [misc]
24-
classes_classvar.py:76: error: Expression is of type "Any", not "float" [assert-type]
25-
classes_classvar.py:100: error: Cannot assign to class variable "stats" via instance [misc]
26-
classes_classvar.py:129: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment]
27-
classes_classvar.py:129: note: "ProtoAImpl" is missing following "ProtoA" protocol member:
28-
classes_classvar.py:129: note: z
29-
classes_classvar.py:129: note: Protocol member ProtoA.x expected class variable, got instance variable
30-
classes_classvar.py:129: note: Protocol member ProtoA.y expected class variable, got instance variable
21+
classes_classvar.py:64: error: ClassVar can only be used for assignments in class body [misc]
22+
classes_classvar.py:66: error: ClassVar can only be used for assignments in class body [misc]
23+
classes_classvar.py:70: error: ClassVar can only be used for assignments in class body [misc]
24+
classes_classvar.py:77: error: Expression is of type "Any", not "float" [assert-type]
25+
classes_classvar.py:101: error: Cannot assign to class variable "stats" via instance [misc]
26+
classes_classvar.py:130: error: Incompatible types in assignment (expression has type "ProtoAImpl", variable has type "ProtoA") [assignment]
27+
classes_classvar.py:130: note: "ProtoAImpl" is missing following "ProtoA" protocol member:
28+
classes_classvar.py:130: note: z
29+
classes_classvar.py:130: note: Protocol member ProtoA.x expected class variable, got instance variable
30+
classes_classvar.py:130: note: Protocol member ProtoA.y expected class variable, got instance variable
3131
"""
3232
conformance_automated = "Fail"
3333
errors_diff = """
34-
Line 45: Expected 1 errors
35-
Line 70: Expected 1 errors
36-
Line 59: Unexpected errors ['classes_classvar.py:59: error: Invalid type: ClassVar nested inside other type [valid-type]']
37-
Line 76: Unexpected errors ['classes_classvar.py:76: error: Expression is of type "Any", not "float" [assert-type]']
34+
Line 46: Expected 1 errors
35+
Line 71: Expected 1 errors
36+
Line 60: Unexpected errors ['classes_classvar.py:60: error: Invalid type: ClassVar nested inside other type [valid-type]']
37+
Line 77: Unexpected errors ['classes_classvar.py:77: error: Expression is of type "Any", not "float" [assert-type]']
3838
"""

conformance/results/mypy/dataclasses_final.toml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ Doesn't support Final nested inside ClassVar.
55
"""
66
conformance_automated = "Fail"
77
errors_diff = """
8-
Line 16: Expected 1 errors
9-
Line 6: Unexpected errors ['dataclasses_final.py:6: error: Final name must be initialized with a value [misc]']
10-
Line 8: Unexpected errors ['dataclasses_final.py:8: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]']
11-
Line 13: Unexpected errors ['dataclasses_final.py:13: error: Expression is of type "Any", not "int" [assert-type]']
8+
Line 27: Expected 1 errors
9+
Line 38: Expected 1 errors
10+
Line 41: Expected 1 errors
11+
Line 16: Unexpected errors ['dataclasses_final.py:16: error: Final name must be initialized with a value [misc]']
12+
Line 18: Unexpected errors ['dataclasses_final.py:18: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]']
13+
Line 24: Unexpected errors ['dataclasses_final.py:24: error: Expression is of type "Any", not "int" [assert-type]']
14+
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]']
15+
Line 40: Unexpected errors ['dataclasses_final.py:40: error: Cannot assign to final attribute "final_with_default" [misc]']
1216
"""
1317
output = """
14-
dataclasses_final.py:6: error: Final name must be initialized with a value [misc]
15-
dataclasses_final.py:8: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
16-
dataclasses_final.py:13: error: Expression is of type "Any", not "int" [assert-type]
17-
dataclasses_final.py:24: error: Cannot assign to final attribute "final_no_default" [misc]
18-
dataclasses_final.py:25: error: Cannot assign to final attribute "final_with_default" [misc]
19-
dataclasses_final.py:26: error: Cannot access final instance attribute "final_no_default" on class object [misc]
20-
dataclasses_final.py:26: error: Cannot assign to final attribute "final_no_default" [misc]
21-
dataclasses_final.py:27: error: Cannot assign to final attribute "final_with_default" [misc]
18+
dataclasses_final.py:16: error: Final name must be initialized with a value [misc]
19+
dataclasses_final.py:18: error: Final can be only used as an outermost qualifier in a variable annotation [valid-type]
20+
dataclasses_final.py:24: error: Expression is of type "Any", not "int" [assert-type]
21+
dataclasses_final.py:35: error: Cannot assign to final attribute "final_no_default" [misc]
22+
dataclasses_final.py:36: error: Cannot assign to final attribute "final_with_default" [misc]
23+
dataclasses_final.py:37: error: Cannot access final instance attribute "final_no_default" on class object [misc]
24+
dataclasses_final.py:37: error: Cannot assign to final attribute "final_no_default" [misc]
25+
dataclasses_final.py:40: error: Cannot assign to final attribute "final_with_default" [misc]
2226
"""

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.0
2+
test_duration = 1.4

conformance/results/pyre/classes_classvar.toml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ Does not reject use of ClassVar in type alias definition.
1111
Does not infer type from initialization for bare ClassVar.
1212
"""
1313
output = """
14-
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.
15-
classes_classvar.py:33:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.
16-
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.
17-
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.
18-
classes_classvar.py:36:10 Invalid type parameters [24]: Generic type `CV` expects 1 type parameter, received 2.
19-
classes_classvar.py:37:10 Invalid type [31]: Expression `typing.ClassVar[3]` is not a valid type.
20-
classes_classvar.py:38:13 Unbound name [10]: Name `var` is used but not defined in the current scope.
21-
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]]`.
22-
classes_classvar.py:52:10 Unbound name [10]: Name `Final` is used but not defined in the current scope.
23-
classes_classvar.py:63:8 Undefined attribute [16]: `ClassA` has no attribute `xx`.
24-
classes_classvar.py:66:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.
25-
classes_classvar.py:76:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.
26-
classes_classvar.py:79:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.
27-
classes_classvar.py:100:0 Invalid assignment [41]: Assigning to class variable through instance, did you mean to assign to `Starship.stats` instead?
28-
classes_classvar.py:129:0 Incompatible variable type [9]: a is declared to have type `ProtoA` but is used as type `ProtoAImpl`.
14+
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad1` is declared in class `ClassA` to have type `typing.Any` but is never initialized.
15+
classes_classvar.py:34:0 Uninitialized attribute [13]: Attribute `bad4` is declared in class `ClassA` to have type `Variable[T]` but is never initialized.
16+
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.
17+
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.
18+
classes_classvar.py:37:10 Invalid type parameters [24]: Generic type `CV` expects 1 type parameter, received 2.
19+
classes_classvar.py:38:10 Invalid type [31]: Expression `typing.ClassVar[3]` is not a valid type.
20+
classes_classvar.py:39:13 Unbound name [10]: Name `var` is used but not defined in the current scope.
21+
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]]`.
22+
classes_classvar.py:64:8 Undefined attribute [16]: `ClassA` has no attribute `xx`.
23+
classes_classvar.py:67:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.
24+
classes_classvar.py:77:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `float` but got `typing.Any`.
25+
classes_classvar.py:80:0 Uninitialized attribute [13]: Attribute `damage` is declared in class `BasicStarship` to have type `int` but is never initialized.
26+
classes_classvar.py:101:0 Invalid assignment [41]: Assigning to class variable through instance, did you mean to assign to `Starship.stats` instead?
27+
classes_classvar.py:130:0 Incompatible variable type [9]: a is declared to have type `ProtoA` but is used as type `ProtoAImpl`.
2928
"""
3029
conformance_automated = "Fail"
3130
errors_diff = """
32-
Line 43: Expected 1 errors
3331
Line 44: Expected 1 errors
3432
Line 45: Expected 1 errors
33+
Line 46: Expected 1 errors
3534
Line 53: Expected 1 errors
36-
Line 61: Expected 1 errors
35+
Line 54: Expected 1 errors
3736
Line 62: Expected 1 errors
38-
Line 65: Expected 1 errors
39-
Line 69: Expected 1 errors
37+
Line 63: Expected 1 errors
38+
Line 66: Expected 1 errors
4039
Line 70: Expected 1 errors
41-
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.']
42-
Line 66: Unexpected errors ['classes_classvar.py:66:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.']
43-
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`.']
44-
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.']
40+
Line 71: Expected 1 errors
41+
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.']
42+
Line 67: Unexpected errors ['classes_classvar.py:67:8 Incompatible return type [7]: Expected `CV[int]` but got `int`.']
43+
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`.']
44+
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.']
4545
"""

conformance/results/pyre/dataclasses_final.toml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ Mis-handles Final nested inside ClassVar.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
7-
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.']
8-
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]`.']
7+
Line 38: Expected 1 errors
8+
Line 41: Expected 1 errors
9+
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.']
10+
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]`.']
11+
Line 37: Unexpected errors ['dataclasses_final.py:37:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.']
12+
Line 40: Unexpected errors ['dataclasses_final.py:40:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.']
913
"""
1014
output = """
11-
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`.
12-
dataclasses_final.py:8:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.
13-
dataclasses_final.py:13:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.
14-
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`.
15-
dataclasses_final.py:24:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_no_default`.
16-
dataclasses_final.py:25:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_with_default`.
17-
dataclasses_final.py:26:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.
18-
dataclasses_final.py:27:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.
15+
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`.
16+
dataclasses_final.py:18:4 Invalid type [31]: Expression `Final[int]` is not a valid type. Final cannot be nested.
17+
dataclasses_final.py:24:0 Incompatible parameter type [6]: In call `assert_type`, for 1st positional argument, expected `int` but got `Final[int]`.
18+
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`.
19+
dataclasses_final.py:35:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_no_default`.
20+
dataclasses_final.py:36:0 Invalid assignment [41]: Cannot reassign final attribute `d.final_with_default`.
21+
dataclasses_final.py:37:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_no_default`.
22+
dataclasses_final.py:40:0 Invalid assignment [41]: Cannot reassign final attribute `D.final_with_default`.
1923
"""

conformance/results/pyre/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.21"
2-
test_duration = 1.9
2+
test_duration = 3.4

0 commit comments

Comments
 (0)