Skip to content

Commit 7453d9c

Browse files
committed
Clarify enums and dataclasses, more thorough test
1 parent 41e84fe commit 7453d9c

27 files changed

+181
-88
lines changed

conformance/results/mypy/dataclasses_usage.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ notes = """
33
Does not detect unannotated usage of `dataclasses.field()`.
44
"""
55
output = """
6-
dataclasses_usage.py:35: error: Accessing "__init__" on an instance is unsound, since instance.__init__ could be from an incompatible subclass [misc]
7-
dataclasses_usage.py:50: error: Missing positional argument "unit_price" in call to "InventoryItem" [call-arg]
8-
dataclasses_usage.py:51: error: Argument 2 to "InventoryItem" has incompatible type "str"; expected "float" [arg-type]
9-
dataclasses_usage.py:52: error: Too many arguments for "InventoryItem" [call-arg]
10-
dataclasses_usage.py:61: error: Attributes without a default cannot follow attributes with one [misc]
11-
dataclasses_usage.py:67: error: Attributes without a default cannot follow attributes with one [misc]
12-
dataclasses_usage.py:73: error: Attributes without a default cannot follow attributes with one [misc]
13-
dataclasses_usage.py:83: error: Too many arguments for "DC4" [call-arg]
14-
dataclasses_usage.py:88: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
15-
dataclasses_usage.py:127: error: Too many arguments for "DC7" [call-arg]
16-
dataclasses_usage.py:130: error: Missing positional argument "y" in call to "DC8" [call-arg]
17-
dataclasses_usage.py:179: error: Too many arguments for "DC13" [call-arg]
6+
dataclasses_usage.py:36: error: Accessing "__init__" on an instance is unsound, since instance.__init__ could be from an incompatible subclass [misc]
7+
dataclasses_usage.py:51: error: Missing positional argument "unit_price" in call to "InventoryItem" [call-arg]
8+
dataclasses_usage.py:52: error: Argument 2 to "InventoryItem" has incompatible type "str"; expected "float" [arg-type]
9+
dataclasses_usage.py:53: error: Too many arguments for "InventoryItem" [call-arg]
10+
dataclasses_usage.py:62: error: Attributes without a default cannot follow attributes with one [misc]
11+
dataclasses_usage.py:68: error: Attributes without a default cannot follow attributes with one [misc]
12+
dataclasses_usage.py:74: error: Attributes without a default cannot follow attributes with one [misc]
13+
dataclasses_usage.py:84: error: Too many arguments for "DC4" [call-arg]
14+
dataclasses_usage.py:89: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
15+
dataclasses_usage.py:128: error: Too many arguments for "DC7" [call-arg]
16+
dataclasses_usage.py:131: error: Missing positional argument "y" in call to "DC8" [call-arg]
17+
dataclasses_usage.py:180: error: Too many arguments for "DC13" [call-arg]
18+
dataclasses_usage.py:246: error: Too many arguments for "DC19" [call-arg]
1819
"""
1920
conformance_automated = "Pass"
2021
errors_diff = """

conformance/results/mypy/enums_definition.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ conformant = "Pass"
22
errors_diff = """
33
"""
44
output = """
5+
enums_definition.py:92: error: "type[Color12]" has no attribute "BLUE" [attr-defined]
56
"""
67
conformance_automated = "Pass"

conformance/results/mypy/namedtuples_define_class.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ namedtuples_define_class.py:68: error: Too many values to unpack (2 expected, 3
1818
namedtuples_define_class.py:77: error: NamedTuple field name cannot start with an underscore: _y [misc]
1919
namedtuples_define_class.py:87: error: Non-default NamedTuple fields cannot follow default fields [misc]
2020
namedtuples_define_class.py:114: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" [misc]
21-
namedtuples_define_class.py:118: error: Too many arguments for "ConditionalField" [call-arg]
22-
namedtuples_define_class.py:137: error: Argument 2 to "Property" has incompatible type "float"; expected "str" [arg-type]
23-
namedtuples_define_class.py:144: error: NamedTuple should be a single base [misc]
21+
namedtuples_define_class.py:116: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" [misc]
22+
namedtuples_define_class.py:120: error: Too many arguments for "ConditionalField" [call-arg]
23+
namedtuples_define_class.py:121: error: Too many arguments for "ConditionalField" [call-arg]
24+
namedtuples_define_class.py:140: error: Argument 2 to "Property" has incompatible type "float"; expected "str" [arg-type]
25+
namedtuples_define_class.py:147: error: NamedTuple should be a single base [misc]
2426
"""
2527
conformance_automated = "Fail"
2628
errors_diff = """
@@ -30,5 +32,6 @@ Line 60: Unexpected errors ['namedtuples_define_class.py:60: error: Invalid stat
3032
Line 66: Unexpected errors ['namedtuples_define_class.py:66: error: Missing positional argument "units" in call to "Point2" [call-arg]']
3133
Line 68: Unexpected errors ['namedtuples_define_class.py:68: error: Too many values to unpack (2 expected, 3 provided) [misc]']
3234
Line 114: Unexpected errors ['namedtuples_define_class.py:114: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" [misc]']
33-
Line 118: Unexpected errors ['namedtuples_define_class.py:118: error: Too many arguments for "ConditionalField" [call-arg]']
35+
Line 116: Unexpected errors ['namedtuples_define_class.py:116: error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]" [misc]']
36+
Line 120: Unexpected errors ['namedtuples_define_class.py:120: error: Too many arguments for "ConditionalField" [call-arg]']
3437
"""

conformance/results/mypy/typeddicts_class_syntax.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ typeddicts_class_syntax.py:39: error: Invalid statement in TypedDict definition;
99
typeddicts_class_syntax.py:45: error: Unexpected keyword argument "metaclass" for "__init_subclass__" of "TypedDict" [call-arg]
1010
typeddicts_class_syntax.py:50: error: Unexpected keyword argument "other" for "__init_subclass__" of "TypedDict" [call-arg]
1111
typeddicts_class_syntax.py:58: error: Invalid statement in TypedDict definition; expected "field_name: field_type" [misc]
12-
typeddicts_class_syntax.py:62: error: Extra key "y" for TypedDict "ConditionalField" [typeddict-unknown-key]
12+
typeddicts_class_syntax.py:60: error: Invalid statement in TypedDict definition; expected "field_name: field_type" [misc]
13+
typeddicts_class_syntax.py:64: error: Extra key "y" for TypedDict "ConditionalField" [typeddict-unknown-key]
14+
typeddicts_class_syntax.py:65: error: Extra keys ("y", "z") for TypedDict "ConditionalField" [typeddict-unknown-key]
1315
"""
1416
conformance_automated = "Fail"
1517
errors_diff = """
1618
Line 58: Unexpected errors ['typeddicts_class_syntax.py:58: error: Invalid statement in TypedDict definition; expected "field_name: field_type" [misc]']
17-
Line 62: Unexpected errors ['typeddicts_class_syntax.py:62: error: Extra key "y" for TypedDict "ConditionalField" [typeddict-unknown-key]']
19+
Line 60: Unexpected errors ['typeddicts_class_syntax.py:60: error: Invalid statement in TypedDict definition; expected "field_name: field_type" [misc]']
20+
Line 64: Unexpected errors ['typeddicts_class_syntax.py:64: error: Extra key "y" for TypedDict "ConditionalField" [typeddict-unknown-key]']
1821
"""

conformance/results/pyrefly/dataclasses_usage.toml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ conformance_automated = "Pass"
33
errors_diff = """
44
"""
55
output = """
6-
ERROR dataclasses_usage.py:50:19-27: Missing argument `unit_price` in function `InventoryItem.__init__` [missing-argument]
7-
ERROR dataclasses_usage.py:51:28-35: Argument `Literal['price']` is not assignable to parameter `unit_price` with type `float` in function `InventoryItem.__init__` [bad-argument-type]
8-
ERROR dataclasses_usage.py:52:36-37: Expected 3 positional arguments, got 4 in function `InventoryItem.__init__` [bad-argument-count]
9-
ERROR dataclasses_usage.py:61:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
10-
ERROR dataclasses_usage.py:67:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
11-
ERROR dataclasses_usage.py:73:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
12-
ERROR dataclasses_usage.py:83:13-14: Expected 1 positional argument, got 2 in function `DC4.__init__` [bad-argument-count]
13-
ERROR dataclasses_usage.py:88:14-40: `str` is not assignable to `int` [bad-assignment]
14-
ERROR dataclasses_usage.py:127:8-9: Expected 1 positional argument, got 2 in function `DC7.__init__` [bad-argument-count]
15-
ERROR dataclasses_usage.py:130:4-7: Missing argument `y` in function `DC8.__init__` [missing-argument]
16-
ERROR dataclasses_usage.py:179:6-7: Expected 0 positional arguments, got 1 in function `object.__init__` [bad-argument-count]
6+
ERROR dataclasses_usage.py:51:19-27: Missing argument `unit_price` in function `InventoryItem.__init__` [missing-argument]
7+
ERROR dataclasses_usage.py:52:28-35: Argument `Literal['price']` is not assignable to parameter `unit_price` with type `float` in function `InventoryItem.__init__` [bad-argument-type]
8+
ERROR dataclasses_usage.py:53:36-37: Expected 3 positional arguments, got 4 in function `InventoryItem.__init__` [bad-argument-count]
9+
ERROR dataclasses_usage.py:62:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
10+
ERROR dataclasses_usage.py:68:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
11+
ERROR dataclasses_usage.py:74:5-6: Dataclass field `b` without a default may not follow dataclass field with a default [bad-class-definition]
12+
ERROR dataclasses_usage.py:84:13-14: Expected 1 positional argument, got 2 in function `DC4.__init__` [bad-argument-count]
13+
ERROR dataclasses_usage.py:89:14-40: `str` is not assignable to `int` [bad-assignment]
14+
ERROR dataclasses_usage.py:128:8-9: Expected 1 positional argument, got 2 in function `DC7.__init__` [bad-argument-count]
15+
ERROR dataclasses_usage.py:131:4-7: Missing argument `y` in function `DC8.__init__` [missing-argument]
16+
ERROR dataclasses_usage.py:180:6-7: Expected 0 positional arguments, got 1 in function `object.__init__` [bad-argument-count]
17+
ERROR dataclasses_usage.py:246:12-13: Expected 2 positional arguments, got 3 in function `DC19.__init__` [bad-argument-count]
1718
"""

conformance/results/pyrefly/enums_definition.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ conformance_automated = "Pass"
33
errors_diff = """
44
"""
55
output = """
6+
ERROR enums_definition.py:92:1-13: Class `Color12` has no class attribute `BLUE` [missing-attribute]
67
"""

conformance/results/pyrefly/namedtuples_define_class.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ERROR namedtuples_define_class.py:70:20-22: Expected 2 positional arguments, got
1515
ERROR namedtuples_define_class.py:77:5-7: NamedTuple field name may not start with an underscore: `_y` [bad-class-definition]
1616
ERROR namedtuples_define_class.py:87:5-13: NamedTuple field 'latitude' without a default may not follow NamedTuple field with a default [bad-class-definition]
1717
ERROR namedtuples_define_class.py:107:5-6: Cannot override named tuple element `x` [bad-override]
18-
ERROR namedtuples_define_class.py:137:19-22: Argument `float` is not assignable to parameter `value` with type `str` in function `Property.__new__` [bad-argument-type]
19-
ERROR namedtuples_define_class.py:144:7-11: Named tuples do not support multiple inheritance [invalid-inheritance]
18+
ERROR namedtuples_define_class.py:121:24-25: Expected 2 positional arguments, got 3 in function `ConditionalField.__new__` [bad-argument-count]
19+
ERROR namedtuples_define_class.py:140:19-22: Argument `float` is not assignable to parameter `value` with type `str` in function `Property.__new__` [bad-argument-type]
20+
ERROR namedtuples_define_class.py:147:7-11: Named tuples do not support multiple inheritance [invalid-inheritance]
2021
"""

conformance/results/pyrefly/typeddicts_class_syntax.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ ERROR typeddicts_class_syntax.py:35:9-16: TypedDict members must be declared in
88
ERROR typeddicts_class_syntax.py:40:9-16: TypedDict members must be declared in the form `field: Annotation` with no assignment [bad-class-definition]
99
ERROR typeddicts_class_syntax.py:45:7-20: Metaclass of `BadTypedDict2` has type `type[Any]` that is not a simple class type [invalid-inheritance]
1010
ERROR typeddicts_class_syntax.py:50:7-20: TypedDict does not support keyword argument `other` [bad-typed-dict]
11+
ERROR typeddicts_class_syntax.py:65:17-32: No matching overload found for function `ConditionalField.__init__` called with arguments: (x=Literal[1], y=Literal[2], z=Literal[3]) [no-matching-overload]
1112
"""

conformance/results/pyright/dataclasses_usage.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
conformant = "Pass"
22
output = """
3-
dataclasses_usage.py:50:6 - error: Argument missing for parameter "unit_price" (reportCallIssue)
4-
dataclasses_usage.py:51:28 - error: Argument of type "Literal['price']" cannot be assigned to parameter "unit_price" of type "float" in function "__init__"
3+
dataclasses_usage.py:51:6 - error: Argument missing for parameter "unit_price" (reportCallIssue)
4+
dataclasses_usage.py:52:28 - error: Argument of type "Literal['price']" cannot be assigned to parameter "unit_price" of type "float" in function "__init__"
55
  "Literal['price']" is not assignable to "float" (reportArgumentType)
6-
dataclasses_usage.py:52:36 - error: Expected 3 positional arguments (reportCallIssue)
7-
dataclasses_usage.py:61:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
8-
dataclasses_usage.py:67:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
9-
dataclasses_usage.py:73:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
10-
dataclasses_usage.py:83:13 - error: Expected 1 positional argument (reportCallIssue)
11-
dataclasses_usage.py:88:14 - error: Type "str" is not assignable to declared type "int"
6+
dataclasses_usage.py:53:36 - error: Expected 3 positional arguments (reportCallIssue)
7+
dataclasses_usage.py:62:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
8+
dataclasses_usage.py:68:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
9+
dataclasses_usage.py:74:5 - error: Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)
10+
dataclasses_usage.py:84:13 - error: Expected 1 positional argument (reportCallIssue)
11+
dataclasses_usage.py:89:14 - error: Type "str" is not assignable to declared type "int"
1212
  "str" is not assignable to "int" (reportAssignmentType)
13-
dataclasses_usage.py:127:8 - error: Expected 1 positional argument (reportCallIssue)
14-
dataclasses_usage.py:130:1 - error: Argument missing for parameter "y" (reportCallIssue)
15-
dataclasses_usage.py:179:6 - error: Expected 0 positional arguments (reportCallIssue)
16-
dataclasses_usage.py:228:9 - error: Dataclass field without type annotation will cause runtime exception (reportGeneralTypeIssues)
13+
dataclasses_usage.py:128:8 - error: Expected 1 positional argument (reportCallIssue)
14+
dataclasses_usage.py:131:1 - error: Argument missing for parameter "y" (reportCallIssue)
15+
dataclasses_usage.py:180:6 - error: Expected 0 positional arguments (reportCallIssue)
16+
dataclasses_usage.py:229:9 - error: Dataclass field without type annotation will cause runtime exception (reportGeneralTypeIssues)
17+
dataclasses_usage.py:246:12 - error: Expected 2 positional arguments (reportCallIssue)
1718
"""
1819
conformance_automated = "Pass"
1920
errors_diff = """

conformance/results/pyright/enums_definition.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ conformant = "Pass"
22
errors_diff = """
33
"""
44
output = """
5+
enums_definition.py:92:9 - error: Cannot access attribute "BLUE" for class "type[Color12]"
6+
  Attribute "BLUE" is unknown (reportAttributeAccessIssue)
57
"""
68
conformance_automated = "Pass"

0 commit comments

Comments
 (0)