Skip to content

Commit 0b2aead

Browse files
added unit test for 18334
1 parent 9870139 commit 0b2aead

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test-data/unit/check-python312.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,21 @@ class Contra[T]:
465465
contra_pos: Contra[object] = Contra[int]() # E: Incompatible types in assignment (expression has type "Contra[int]", variable has type "Contra[object]")
466466
contra_neg: Contra[int] = Contra[object]()
467467

468+
469+
[case testPEP695SelfAttribute]
470+
# https://github.com/python/mypy/issues/18334
471+
from typing import Self
472+
473+
class Foo[T]:
474+
instance: Self
475+
def foo(self) -> T: ... # type:ignore[empty-body]
476+
477+
class Bar(Foo[int]): ...
478+
479+
# OK
480+
foo: Foo[object] = Bar()
481+
482+
468483
[case testPEP695InheritInvariant]
469484
class Invariant[T]:
470485
x: T

0 commit comments

Comments
 (0)