Allow inheriting from Self in TPS
#10897
Replies: 2 comments 2 replies
-
|
See code -- from typing import Self
class Base[T]:
def foo(self, /) -> T: ...
class Outer:
class Inner(Base[Self]): ...Assuming such usage of |
Beta Was this translation helpful? Give feedback.
-
|
It's not clear to me what problem you're trying to solve here. Perhaps if you start with the problem, we could suggest ways that you could solve it within the current type system. If you'd like to propose changes to the type system, the Python Typing forum would be a more appropriate forum. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
With the introduction of the Type Parameter Scope
Selfis(?) well defined in inheritance. I performed some tests (Pyright Playground) and all the typing features needed seem supported by Pyright. (Unlike mypy.)Just like
foo: ClassVar[T]works in Pyright (but errors per spec IIRC); could we allowclass Foo(Iterable[Self])to error but type correctly? The request is out-of-spec but to my uninformed eyes looks implementable with the existing features of Pyright.Beta Was this translation helpful? Give feedback.
All reactions