Python3 抽象方法,参数与重写方法不同

问题描述

Parent 类有一个抽象方法,我需要在子类/方法方法中使用不同数量和类型的参数。

from abc import ABC,abstractmethod


class Parent(ABC):
    """Parent"""
    @abstractmethod
    def method(self,*args):
        """method"""


class Child1(Parent):
    """Child1"""
    def method(self,arg1: int):
        print(arg1)


class Child2(Parent):
    """Child2"""
    def method(self,arg1: str,arg2: dict):
        print(arg1,arg2)

对于此代码,pylint 向我显示一个警告:

[W0221(arguments-difer),Child1.method] 参数不同于 重写的“方法方法

是否可以解决 pylint 警告并继续在子类中使用不同的参数? 我不想在子方法中使用 *args

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)