Skip to content

Commit 71904cb

Browse files
committed
Add test without members
1 parent c1bff2f commit 71904cb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test-data/unit/check-selftype.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,10 +2351,30 @@ reveal_type(gc.test()) # N: Revealed type is "builtins.list[__main__.D2]"
23512351
from enum import Enum
23522352
from typing import Self
23532353

2354+
# This enum has members and so is implicitly final.
2355+
# Foo and Self are interchangeable within the class.
23542356
class Foo(Enum):
23552357
A = 1
23562358

23572359
@classmethod
2358-
def foo(self) -> Self:
2360+
def foo(cls) -> Self:
23592361
return Foo.A
2362+
2363+
@classmethod
2364+
def foo2(cls) -> Self:
2365+
return cls.bar()
2366+
2367+
@classmethod
2368+
def bar(cls) -> Foo:
2369+
...
2370+
2371+
# This enum is empty and should not be assignable to Self
2372+
class Bar(Enum):
2373+
@classmethod
2374+
def foo(cls) -> Self:
2375+
return cls.bar() # E: Incompatible return value type (got "Bar", expected "Self")
2376+
2377+
@classmethod
2378+
def bar(cls) -> Bar:
2379+
...
23602380
[builtins fixtures/classmethod.pyi]

0 commit comments

Comments
 (0)