-
Consider the following: from abc import ABC, abstractmethod
from typing import Type, TypeVar
_ASub = TypeVar("_ASub", bound="A")
class A(ABC):
@abstractmethod
def some_method(self) -> str: ...
def some_factory_method(self: _ASub) -> _ASub:
return type(self)() # Pyright complains that `A` is abstract
class ActualASub(A):
def some_method(self) -> str:
return "some string"
ActualASub().some_factory_method() This runs fine, but pyright complains. If this is by design, then the following should also raise an error, but it doesn't. # Use the code snippet above, but replace `some_factory_method` with the following classmethod.
@classmethod
def some_factory_method(cls: Type[_ASub]) -> _ASub:
return cls() It seems to be that either none or both of the snippets must pass type checking. But currently, the first one doesn't and the second one does. |
Beta Was this translation helpful? Give feedback.
Answered by
erictraut
Jun 21, 2021
Replies: 1 comment
-
Yes, this is a bug. I'd appreciate it if you could file a formal bug report with your excellent code sample above. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dnaaun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is a bug. I'd appreciate it if you could file a formal bug report with your excellent code sample above. Thanks!