Closed
Description
Repro:
from typing import Generic, TypeVar, Type
_T = TypeVar('_T')
SelfType = TypeVar('SelfType', bound='Friend')
class Friend(Generic[_T]):
@classmethod
def make(cls: Type[SelfType]) -> SelfType: # E: Unsupported type Type["SelfType"]
return cls()
I suspect the issue is that the type should be:
def make(cls: Type[SelfType[T]]) -> SelfType[T]:
return cls()
But there is no way to express that that I can tell.
Using an instance method behaves as expected:
from typing import Generic, TypeVar, Type
_T = TypeVar('_T')
SelfType = TypeVar('SelfType', bound='Friend')
class Friend(Generic[_T]):
other = None # type: Friend
def make(self: SelfType) -> SelfType:
return self
Metadata
Metadata
Assignees
Labels
No labels