Skip to content

Commit 2f2b8d1

Browse files
committed
Allow type checkers to generate an error when list[Self] instance variables are accessed
1 parent ae0d7a1 commit 2f2b8d1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

conformance/tests/generics_self_advanced.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ class ChildB(ParentB):
3333

3434
def method2(self) -> None:
3535
assert_type(self, Self)
36-
assert_type(self.a, list[Self])
37-
assert_type(self.a[0], Self)
36+
# Allow type checkers to error here, since Self definitions on
37+
# non-final classes are unsound.
38+
a = self.a # E?
39+
assert_type(a, list[Self])
40+
assert_type(a[0], Self)
3841
assert_type(self.method1(), Self)
3942

4043
@classmethod

0 commit comments

Comments
 (0)