问题描述
当以更明确的方式实现abstractmethod
时,我收到类型警告,为什么会这样呢?
我有以下界面
from typing import Any
from abc import abstractmethod,ABCMeta
class SaveDataInterface(Metaclass=ABCMeta):
@abstractmethod
def save_data(self,data: Any,*args,**kwargs):
...
实现以下FileSaver
类时,mypy会引发错误error: Signature of "save_data" incompatible with supertype "SaveDataInterface"
class FileSaver(SaveDataInterface):
def save_data(self,data: str,file_path: str,**kwargs):
with open(file_path,'w') as file:
file.write(data)
在我看来FileSaver.save_data
某种程度上破坏了abstractmethod
save_data
功能,还有另一种方法来实现更明确的功能签名吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)