Skip to content

Commit b41e509

Browse files
Do not require an error for a generic class attribute (#2008)
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. --------- Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent dcffbae commit b41e509

5 files changed

Lines changed: 1 addition & 6 deletions

File tree

conformance/results/mypy/generics_type_erasure.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
conformant = "Partial"
22
notes = """
33
Infers `Node[Never]` instead of `Node[Any]` when argument is not provided.
4-
False negative on instance attribute access on `type(node)`.
54
"""
65
output = """
76
generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [assert-type]
@@ -15,7 +14,6 @@ generics_type_erasure.py:45: error: Access to generic instance variables via cla
1514
"""
1615
conformance_automated = "Fail"
1716
errors_diff = """
18-
Line 46: Expected 1 errors
1917
Line 19: Unexpected errors ['generics_type_erasure.py:19: error: Expression is of type "Node[Never]", not "Node[Any]" [assert-type]']
2018
Line 22: Unexpected errors ['generics_type_erasure.py:22: error: Expression is of type "Never", not "Any" [assert-type]']
2119
"""

conformance/results/results.html

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conformance/results/ty/generics_type_erasure.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Line 42: Expected 1 errors
88
Line 43: Expected 1 errors
99
Line 44: Expected 1 errors
1010
Line 45: Expected 1 errors
11-
Line 46: Expected 1 errors
1211
"""
1312
output = """
1413
generics_type_erasure.py:38:16: error[invalid-argument-type] Argument to `Node.__init__` is incorrect: Expected `int | None`, found `Literal[""]`

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

docs/spec/generics.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ class instance that does not have an instance attribute with the same name::
400400
Node[int].x # Error
401401
Node.x = 1 # Error
402402
Node.x # Error
403-
type(p).x # Error
404403
p.x # Ok (evaluates to int)
405404
Node[int]().x # Ok (evaluates to int)
406405
p.x = 1 # Ok, but assigning to instance attribute

0 commit comments

Comments
 (0)