File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -2351,10 +2351,30 @@ reveal_type(gc.test()) # N: Revealed type is "builtins.list[__main__.D2]"
23512351from enum import Enum
23522352from typing import Self
23532353
2354+ # This enum has members and so is implicitly final.
2355+ # Foo and Self are interchangeable within the class.
23542356class 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]
You can’t perform that action at this time.
0 commit comments