Skip to content

Commit f6b4eae

Browse files
committed
Address review comments.
1 parent a01b0a4 commit f6b4eae

11 files changed

+62
-68
lines changed

conformance/results/mypy/generics_self_advanced.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Does not retain `Self` when accessing attribute through `type[Self]`.
88
output = """
99
generics_self_advanced.py:35: error: Expression is of type "ChildB", not "Self" [assert-type]
1010
generics_self_advanced.py:38: error: Expression is of type "ChildB", not "Self" [assert-type]
11-
generics_self_advanced.py:44: error: Expression is of type "type[ChildB]", not "type[Self]" [assert-type]
12-
generics_self_advanced.py:47: error: Expression is of type "ChildB", not "Self" [assert-type]
11+
generics_self_advanced.py:42: error: Expression is of type "type[ChildB]", not "type[Self]" [assert-type]
12+
generics_self_advanced.py:45: error: Expression is of type "ChildB", not "Self" [assert-type]
1313
"""
1414
conformance_automated = "Fail"
1515
errors_diff = """
1616
Line 35: Unexpected errors ['generics_self_advanced.py:35: error: Expression is of type "ChildB", not "Self" [assert-type]']
1717
Line 38: Unexpected errors ['generics_self_advanced.py:38: error: Expression is of type "ChildB", not "Self" [assert-type]']
18-
Line 44: Unexpected errors ['generics_self_advanced.py:44: error: Expression is of type "type[ChildB]", not "type[Self]" [assert-type]']
19-
Line 47: Unexpected errors ['generics_self_advanced.py:47: error: Expression is of type "ChildB", not "Self" [assert-type]']
18+
Line 42: Unexpected errors ['generics_self_advanced.py:42: error: Expression is of type "type[ChildB]", not "type[Self]" [assert-type]']
19+
Line 45: Unexpected errors ['generics_self_advanced.py:45: error: Expression is of type "ChildB", not "Self" [assert-type]']
2020
"""

conformance/results/mypy/generics_type_erasure.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ False negative on instance attribute access on type(node).
55
"""
66
output = """
77
generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [assert-type]
8-
generics_type_erasure.py:23: error: Expression is of type "Never", not "Any" [assert-type]
9-
generics_type_erasure.py:40: error: Argument 1 to "Node" has incompatible type "str"; expected "int | None" [arg-type]
10-
generics_type_erasure.py:42: error: Argument 1 to "Node" has incompatible type "int"; expected "str | None" [arg-type]
8+
generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [assert-type]
9+
generics_type_erasure.py:38: error: Argument 1 to "Node" has incompatible type "str"; expected "int | None" [arg-type]
10+
generics_type_erasure.py:40: error: Argument 1 to "Node" has incompatible type "int"; expected "str | None" [arg-type]
11+
generics_type_erasure.py:42: error: Access to generic instance variables via class is ambiguous [misc]
12+
generics_type_erasure.py:43: error: Access to generic instance variables via class is ambiguous [misc]
1113
generics_type_erasure.py:44: error: Access to generic instance variables via class is ambiguous [misc]
1214
generics_type_erasure.py:45: error: Access to generic instance variables via class is ambiguous [misc]
13-
generics_type_erasure.py:46: error: Access to generic instance variables via class is ambiguous [misc]
14-
generics_type_erasure.py:47: error: Access to generic instance variables via class is ambiguous [misc]
1515
"""
1616
conformance_automated = "Fail"
1717
errors_diff = """
18-
Line 48: Expected 1 errors
18+
Line 46: Expected 1 errors
19+
Line 19: Unexpected errors ['generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [assert-type]']
20+
Line 22: Unexpected errors ['generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [assert-type]']
1921
"""

conformance/results/pyre/generics_self_advanced.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ generics_self_advanced.py:25:7 Undefined or invalid type [11]: Annotation `Self`
88
generics_self_advanced.py:35:8 Assert type [70]: Expected `unknown` but got `ChildB`.
99
generics_self_advanced.py:37:8 Assert type [70]: Expected `unknown` but got `typing.Any`.
1010
generics_self_advanced.py:38:8 Assert type [70]: Expected `unknown` but got `ChildB`.
11-
generics_self_advanced.py:44:8 Assert type [70]: Expected `unknown` but got `Type[ChildB]`.
12-
generics_self_advanced.py:46:8 Assert type [70]: Expected `unknown` but got `typing.Any`.
13-
generics_self_advanced.py:47:8 Assert type [70]: Expected `unknown` but got `ChildB`.
11+
generics_self_advanced.py:42:8 Assert type [70]: Expected `unknown` but got `Type[ChildB]`.
12+
generics_self_advanced.py:44:8 Assert type [70]: Expected `unknown` but got `typing.Any`.
13+
generics_self_advanced.py:45:8 Assert type [70]: Expected `unknown` but got `ChildB`.
1414
"""
1515
conformance_automated = "Fail"
1616
errors_diff = """
1717
Line 25: Unexpected errors ['generics_self_advanced.py:25:7 Undefined or invalid type [11]: Annotation `Self` is not defined as a type.']
1818
Line 35: Unexpected errors ['generics_self_advanced.py:35:8 Assert type [70]: Expected `unknown` but got `ChildB`.']
1919
Line 37: Unexpected errors ['generics_self_advanced.py:37:8 Assert type [70]: Expected `unknown` but got `typing.Any`.']
2020
Line 38: Unexpected errors ['generics_self_advanced.py:38:8 Assert type [70]: Expected `unknown` but got `ChildB`.']
21-
Line 44: Unexpected errors ['generics_self_advanced.py:44:8 Assert type [70]: Expected `unknown` but got `Type[ChildB]`.']
22-
Line 46: Unexpected errors ['generics_self_advanced.py:46:8 Assert type [70]: Expected `unknown` but got `typing.Any`.']
23-
Line 47: Unexpected errors ['generics_self_advanced.py:47:8 Assert type [70]: Expected `unknown` but got `ChildB`.']
21+
Line 42: Unexpected errors ['generics_self_advanced.py:42:8 Assert type [70]: Expected `unknown` but got `Type[ChildB]`.']
22+
Line 44: Unexpected errors ['generics_self_advanced.py:44:8 Assert type [70]: Expected `unknown` but got `typing.Any`.']
23+
Line 45: Unexpected errors ['generics_self_advanced.py:45:8 Assert type [70]: Expected `unknown` but got `ChildB`.']
2424
"""

conformance/results/pyre/generics_type_erasure.toml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@ output = """
99
generics_type_erasure.py:17:0 Assert type [70]: Expected `Node[str]` but got `Node[typing_extensions.Literal['']]`.
1010
generics_type_erasure.py:18:0 Assert type [70]: Expected `Node[int]` but got `Node[typing_extensions.Literal[0]]`.
1111
generics_type_erasure.py:19:0 Assert type [70]: Expected `Node[typing.Any]` but got `Node[Variable[T]]`.
12-
generics_type_erasure.py:20:0 Assert type [70]: Expected `Node[Never]` but got `Node[Variable[T]]`.
13-
generics_type_erasure.py:22:0 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.
14-
generics_type_erasure.py:24:0 Assert type [70]: Expected `Never` but got `typing.Any`.
15-
generics_type_erasure.py:40:15 Incompatible parameter type [6]: In call `Node.__init__`, for 1st positional argument, expected `Optional[int]` but got `str`.
16-
generics_type_erasure.py:42:15 Incompatible parameter type [6]: In call `Node.__init__`, for 1st positional argument, expected `Optional[str]` but got `int`.
17-
generics_type_erasure.py:58:0 Assert type [70]: Expected `bytes` but got `typing.Any`.
12+
generics_type_erasure.py:21:0 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.
13+
generics_type_erasure.py:38:15 Incompatible parameter type [6]: In call `Node.__init__`, for 1st positional argument, expected `Optional[int]` but got `str`.
14+
generics_type_erasure.py:40:15 Incompatible parameter type [6]: In call `Node.__init__`, for 1st positional argument, expected `Optional[str]` but got `int`.
15+
generics_type_erasure.py:56:0 Assert type [70]: Expected `bytes` but got `typing.Any`.
1816
"""
1917
conformance_automated = "Fail"
2018
errors_diff = """
19+
Line 42: Expected 1 errors
20+
Line 43: Expected 1 errors
2121
Line 44: Expected 1 errors
2222
Line 45: Expected 1 errors
2323
Line 46: Expected 1 errors
24-
Line 47: Expected 1 errors
25-
Line 48: Expected 1 errors
26-
Lines 19, 20: Expected exactly one error (tag 'any-or-never1')
2724
Line 17: Unexpected errors ["generics_type_erasure.py:17:0 Assert type [70]: Expected `Node[str]` but got `Node[typing_extensions.Literal['']]`."]
2825
Line 18: Unexpected errors ['generics_type_erasure.py:18:0 Assert type [70]: Expected `Node[int]` but got `Node[typing_extensions.Literal[0]]`.']
2926
Line 19: Unexpected errors ['generics_type_erasure.py:19:0 Assert type [70]: Expected `Node[typing.Any]` but got `Node[Variable[T]]`.']
30-
Line 20: Unexpected errors ['generics_type_erasure.py:20:0 Assert type [70]: Expected `Node[Never]` but got `Node[Variable[T]]`.']
31-
Line 22: Unexpected errors ['generics_type_erasure.py:22:0 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.']
32-
Line 58: Unexpected errors ['generics_type_erasure.py:58:0 Assert type [70]: Expected `bytes` but got `typing.Any`.']
27+
Line 21: Unexpected errors ['generics_type_erasure.py:21:0 Assert type [70]: Expected `int` but got `typing_extensions.Literal[0]`.']
28+
Line 56: Unexpected errors ['generics_type_erasure.py:56:0 Assert type [70]: Expected `bytes` but got `typing.Any`.']
3329
"""

conformance/results/pyrefly/generics_type_erasure.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ conformance_automated = "Pass"
33
errors_diff = """
44
"""
55
output = """
6-
ERROR generics_type_erasure.py:20:12-33: assert_type(Node[Any], Node[Never]) failed [assert-type]
7-
ERROR generics_type_erasure.py:24:12-33: assert_type(Any, Never) failed [assert-type]
8-
ERROR generics_type_erasure.py:40:16-18: Argument `Literal['']` is not assignable to parameter `label` with type `int | None` in function `Node.__init__` [bad-argument-type]
9-
ERROR generics_type_erasure.py:42:16-17: Argument `Literal[0]` is not assignable to parameter `label` with type `str | None` in function `Node.__init__` [bad-argument-type]
10-
ERROR generics_type_erasure.py:44:1-16: Generic attribute `label` of class `Node` is not visible on the class [no-access]
11-
ERROR generics_type_erasure.py:45:1-16: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
12-
ERROR generics_type_erasure.py:46:1-11: Generic attribute `label` of class `Node` is not visible on the class [no-access]
13-
ERROR generics_type_erasure.py:47:1-11: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
14-
ERROR generics_type_erasure.py:48:1-15: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
6+
ERROR generics_type_erasure.py:38:16-18: Argument `Literal['']` is not assignable to parameter `label` with type `int | None` in function `Node.__init__` [bad-argument-type]
7+
ERROR generics_type_erasure.py:40:16-17: Argument `Literal[0]` is not assignable to parameter `label` with type `str | None` in function `Node.__init__` [bad-argument-type]
8+
ERROR generics_type_erasure.py:42:1-16: Generic attribute `label` of class `Node` is not visible on the class [no-access]
9+
ERROR generics_type_erasure.py:43:1-16: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
10+
ERROR generics_type_erasure.py:44:1-11: Generic attribute `label` of class `Node` is not visible on the class [no-access]
11+
ERROR generics_type_erasure.py:45:1-11: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
12+
ERROR generics_type_erasure.py:46:1-15: Generic attribute `label` of class `Node` is not visible on the class [missing-attribute]
1513
"""

conformance/results/pyright/generics_type_erasure.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
conformant = "Pass"
22
output = """
3-
generics_type_erasure.py:20:13 - error: "assert_type" mismatch: expected "Node[Never]" but received "Node[Unknown]" (reportAssertTypeFailure)
4-
generics_type_erasure.py:24:13 - error: "assert_type" mismatch: expected "Never" but received "Unknown" (reportAssertTypeFailure)
5-
generics_type_erasure.py:40:16 - error: Argument of type "Literal['']" cannot be assigned to parameter "label" of type "int | None" in function "__init__"
3+
generics_type_erasure.py:38:16 - error: Argument of type "Literal['']" cannot be assigned to parameter "label" of type "int | None" in function "__init__"
64
  Type "Literal['']" is not assignable to type "int | None"
75
    "Literal['']" is not assignable to "int"
86
    "Literal['']" is not assignable to "None" (reportArgumentType)
9-
generics_type_erasure.py:42:16 - error: Argument of type "Literal[0]" cannot be assigned to parameter "label" of type "str | None" in function "__init__"
7+
generics_type_erasure.py:40:16 - error: Argument of type "Literal[0]" cannot be assigned to parameter "label" of type "str | None" in function "__init__"
108
  Type "Literal[0]" is not assignable to type "str | None"
119
    "Literal[0]" is not assignable to "str"
1210
    "Literal[0]" is not assignable to "None" (reportArgumentType)
13-
generics_type_erasure.py:44:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
14-
generics_type_erasure.py:45:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
15-
generics_type_erasure.py:46:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
16-
generics_type_erasure.py:47:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
17-
generics_type_erasure.py:48:10 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
11+
generics_type_erasure.py:42:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
12+
generics_type_erasure.py:43:11 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
13+
generics_type_erasure.py:44:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
14+
generics_type_erasure.py:45:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
15+
generics_type_erasure.py:46:10 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
1816
"""
1917
conformance_automated = "Pass"
2018
errors_diff = """

conformance/results/results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ <h3>Python Type System Conformance Test Results</h3>
322322
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not infer the type of an unannotated `self` parameter to be type `Self`.</p><p>Does not retain `Self` when calling method that returns `Self`.</p><p>Does not infer the type of an unannotated `cls` parameter to be type `type[Self]`.</p><p>Does not retain `Self` when accessing attribute through `type[Self]`.</p></span></div></th>
323323
<th class="column col2 conformant">Pass</th>
324324
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not handle use of `Self` within class body correctly.</p><p>False negatives on assert_type uses.</p></span></div></th>
325-
<th class="column col2 conformant"><div class="hover-text">Pass*<span class="tooltip-text" id="bottom"><p>True positive: Writing to a variable that contains Self (with a class) should error</p></span></div></th>
325+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Doesn't allow accessing `Self` in a classmethod</p></span></div></th>
326326
<th class="column col2 conformant"><div class="hover-text">Pass*<span class="tooltip-text" id="bottom"><p>Treats attributes not initialized on the class as instance-only</p></span></div></th>
327327
</tr>
328328
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_self_attributes</th>
@@ -385,7 +385,7 @@ <h3>Python Type System Conformance Test Results</h3>
385385
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Infers Node[Never] instead of Node[Any] when argument is not provided.</p><p>False negative on instance attribute access on type(node).</p></span></div></th>
386386
<th class="column col2 conformant">Pass</th>
387387
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not erase unspecified type variables to `Any` prior to `assert_type` handling.</p><p>False negatives on instance attribute access on the type.</p><p>Does not infer type of `DefaultDict` with explicit type parameters on constructor.</p><p>False negatives on assert_type uses.</p></span></div></th>
388-
<th class="column col2 conformant"><div class="hover-text">Pass*<span class="tooltip-text" id="bottom"><p>True positive: Undefined type vars should be inferred as Never not Any (avoiding to introduce Any)</p></span></div></th>
388+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Infers Node[Never] instead of Node[Any] when argument is not provided.</p></span></div></th>
389389
<th class="column col2 conformant">Pass</th>
390390
</tr>
391391
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_typevartuple_args</th>
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
22
notes = """
3-
True positive: Writing to a variable that contains Self (with a class) should error
3+
Doesn't allow accessing `Self` in a classmethod
44
"""
5-
conformance_automated = "Pass"
5+
conformance_automated = "Fail"
66
errors_diff = """
7+
Line 43: Unexpected errors ['generics_self_advanced.py:43: error: Access to generic instance variables via class is ambiguous [misc]']
8+
Line 44: Unexpected errors ['generics_self_advanced.py:44: error: Access to generic instance variables via class is ambiguous [misc]']
79
"""
810
output = """
9-
generics_self_advanced.py:42: error: Access to generic instance variables via class is ambiguous [misc]
1011
generics_self_advanced.py:43: error: Access to generic instance variables via class is ambiguous [misc]
12+
generics_self_advanced.py:44: error: Access to generic instance variables via class is ambiguous [misc]
1113
"""
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
22
notes = """
3-
True positive: Undefined type vars should be inferred as Never not Any (avoiding to introduce Any)
3+
Infers Node[Never] instead of Node[Any] when argument is not provided.
44
"""
5-
conformance_automated = "Pass"
5+
conformance_automated = "Fail"
66
errors_diff = """
7+
Line 19: Unexpected errors ['generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [misc]']
8+
Line 22: Unexpected errors ['generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [misc]']
79
"""
810
output = """
911
generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [misc]
10-
generics_type_erasure.py:23: error: Expression is of type "Never", not "Any" [misc]
11-
generics_type_erasure.py:40: error: Argument 1 to "Node" has incompatible type "str"; expected "int | None" [arg-type]
12-
generics_type_erasure.py:42: error: Argument 1 to "Node" has incompatible type "int"; expected "str | None" [arg-type]
12+
generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [misc]
13+
generics_type_erasure.py:38: error: Argument 1 to "Node" has incompatible type "str"; expected "int | None" [arg-type]
14+
generics_type_erasure.py:40: error: Argument 1 to "Node" has incompatible type "int"; expected "str | None" [arg-type]
15+
generics_type_erasure.py:42: error: Access to generic instance variables via class is ambiguous [misc]
16+
generics_type_erasure.py:43: error: Access to generic instance variables via class is ambiguous [misc]
1317
generics_type_erasure.py:44: error: Access to generic instance variables via class is ambiguous [misc]
1418
generics_type_erasure.py:45: error: Access to generic instance variables via class is ambiguous [misc]
1519
generics_type_erasure.py:46: error: Access to generic instance variables via class is ambiguous [misc]
16-
generics_type_erasure.py:47: error: Access to generic instance variables via class is ambiguous [misc]
17-
generics_type_erasure.py:48: error: Access to generic instance variables via class is ambiguous [misc]
1820
"""

conformance/tests/generics_self_advanced.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ def method2(self) -> None:
3939

4040
@classmethod
4141
def method3(cls) -> None:
42-
a = cls.a # E?: zuban errors on accessing `Self` in a classmethod
43-
a_elem = cls.a[0] # E?: zuban errors on accessing `Self` in a classmethod
4442
assert_type(cls, type[Self])
45-
assert_type(a, list[Self])
46-
assert_type(a_elem, Self)
43+
assert_type(cls.a, list[Self])
44+
assert_type(cls.a[0], Self)
4745
assert_type(cls.method1(), Self)

0 commit comments

Comments
 (0)