Allow inheriting from Self in TPS
#10897
Closed
Peilonrayz (Peilonrayz)
started this conversation in
Ideas
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 |
1 reply
|
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. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.All reactions