readinto()
我正在尝试向从派生的自定义类中声明的方法添加参数类型RawIOBase
,如下所示:
from io import RawIOBase
class Reader(RawIOBase):
def readinto(self, buf: bytearray) -> int:
pass # actual implementation omitted
但 pyright 抱怨道:
io.py:6:9 - error: Method "readinto" overrides class "_RawIOBase" in an incompatible manner
Parameter 2 type mismatch: base parameter is type "WriteableBuffer", override parameter is type "bytearray"
"Buffer" is not assignable to "bytearray" (reportIncompatibleMethodOverride)
1 error, 0 warnings, 0 informations
我该如何解决这个问题?注意:我知道我可以完全删除类型提示。我想改为为其分配正确的类型。
我正在使用 Python 3.13.3 和 pyright 1.1.400。