-
According to https://docs.python.org/3.13/library/abc.html#abc.abstractmethod
Code sample from #644 in pyright playground import abc
class A(abc.ABC):
@abc.abstractmethod
def get(self, arg1: str, arg2: bool):
pass
class B(A): # expected to fail typecheck
def not_get(self): print('Ok')
class C(A):
def get(self, arg1: str): print('Still Ok')
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Pyright is working correctly here. The class definition of If you attempt to instantiate |
Beta Was this translation helpful? Give feedback.
-
Oh, I see, thanks In my particular case, I had something like: class B(A):
@classmethod
def many(cls, n: int):
for _ in range(n):
yield cls()
# yield B() And |
Beta Was this translation helpful? Give feedback.
Pyright is working correctly here. The class definition of
B
is fine. You can create subclasses ofB
that provide the missing abstract method implementation.If you attempt to instantiate
B
, pyright will report an error. Also, if you markB
as@final
, then pyright will report an error.