Skip to content

Commit a2eb418

Browse files
committed
Modified generics_type_erasure.py test to not require an error when accessing a generic attribute on a class when a subtype could provide specialization for that generic attribute.
Pyright recently made a modification to eliminate a false positive error in this case. See microsoft/pyright#10303 for details. I don't think the conformance test should mandate an error in this case. The spec certainly doesn't say anything about it, and the error is potentially a false positive.
1 parent 089d7d3 commit a2eb418

File tree

9 files changed

+11
-18
lines changed

9 files changed

+11
-18
lines changed

conformance/results/mypy/generics_type_erasure.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ generics_type_erasure.py:45: error: Access to generic instance variables via cla
1515
"""
1616
conformance_automated = "Fail"
1717
errors_diff = """
18-
Line 46: Expected 1 errors
1918
Line 19: Unexpected errors ['generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [assert-type]']
2019
Line 22: Unexpected errors ['generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [assert-type]']
2120
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.15.0"
2-
test_duration = 1.8
2+
test_duration = 1.6

conformance/results/pyre/generics_type_erasure.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Line 42: Expected 1 errors
2020
Line 43: Expected 1 errors
2121
Line 44: Expected 1 errors
2222
Line 45: Expected 1 errors
23-
Line 46: Expected 1 errors
2423
Line 17: Unexpected errors ["generics_type_erasure.py:17:0 Assert type [70]: Expected `Node[str]` but got `Node[typing_extensions.Literal['']]`."]
2524
Line 18: Unexpected errors ['generics_type_erasure.py:18:0 Assert type [70]: Expected `Node[int]` but got `Node[typing_extensions.Literal[0]]`.']
2625
Line 19: Unexpected errors ['generics_type_erasure.py:19:0 Assert type [70]: Expected `Node[typing.Any]` but got `Node[Variable[T]]`.']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.23"
2-
test_duration = 9.8
2+
test_duration = 10.4

conformance/results/pyright/generics_type_erasure.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
conformant = "Partial"
2-
notes = """
3-
Missing error regarding `type(instance).generic_attribute`.
4-
"""
1+
conformant = "Pass"
52
output = """
63
generics_type_erasure.py:38:16 - error: Argument of type "Literal['']" cannot be assigned to parameter "label" of type "int | None" in function "__init__"
74
  Type "Literal['']" is not assignable to type "int | None"
@@ -16,7 +13,6 @@ generics_type_erasure.py:43:11 - error: Access to generic instance variable thro
1613
generics_type_erasure.py:44:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
1714
generics_type_erasure.py:45:6 - error: Access to generic instance variable through class is ambiguous (reportGeneralTypeIssues)
1815
"""
19-
conformance_automated = "Fail"
16+
conformance_automated = "Pass"
2017
errors_diff = """
21-
Line 46: Expected 1 errors
2218
"""

conformance/results/pytype/generics_type_erasure.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ Line 42: Expected 1 errors
1010
Line 43: Expected 1 errors
1111
Line 44: Expected 1 errors
1212
Line 45: Expected 1 errors
13-
Line 46: Expected 1 errors
1413
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pytype 2024.10.11"
2-
test_duration = 33.6
2+
test_duration = 36.2

conformance/results/results.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.15.0</div>
162-
<div class='tc-time'>1.8sec</div>
162+
<div class='tc-time'>1.6sec</div>
163163
</th>
164164
<th class='tc-header'><div class='tc-name'>pyright 1.1.400</div>
165165
<div class='tc-time'>1.1sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>9.8sec</div>
168+
<div class='tc-time'>10.4sec</div>
169169
</th>
170170
<th class='tc-header'><div class='tc-name'>pytype 2024.10.11</div>
171-
<div class='tc-time'>33.6sec</div>
171+
<div class='tc-time'>36.2sec</div>
172172
</th>
173173
</tr>
174174
<tr><th class="column" colspan="5">
@@ -356,7 +356,7 @@ <h3>Python Type System Conformance Test Results</h3>
356356
</tr>
357357
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_type_erasure</th>
358358
<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>
359-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>no error for `type(n1).label`</p></span></div></th>
359+
<th class="column col2 conformant">Pass</th>
360360
<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>
361361
<th class="column col2 not-conformant">Unsupported</th>
362362
</tr>
@@ -491,7 +491,7 @@ <h3>Python Type System Conformance Test Results</h3>
491491
</tr>
492492
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_typealiastype</th>
493493
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly rejects some recursive type aliases using TypeAliasType.</p><p>Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.</p></span></div></th>
494-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>incorrectly allows undefined self reference</p></span></div></th>
494+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly allows undefined self reference.</p></span></div></th>
495495
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Support for TypeAliasType is not implemented.</p></span></div></th>
496496
<th class="column col2 not-conformant"><div class="hover-text">Unsupported<span class="tooltip-text" id="bottom"><p>Support for TypeAliasType is not implemented.</p></span></div></th>
497497
</tr>

conformance/tests/generics_type_erasure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, label: T | None = None) -> None:
4343
Node[int].label # E
4444
Node.label = 1 # E
4545
Node.label # E
46-
type(n1).label # E
46+
type(n1).label # E?
4747
assert_type(n1.label, int)
4848
assert_type(Node[int]().label, int)
4949
n1.label = 1 # OK

0 commit comments

Comments
 (0)