singledispatch-method (PLE1519)
源自 Pylint 代码检查工具。
有时提供修复。
作用
检查使用 @singledispatch 修饰器的方法。
为什么这不好?
@singledispatch 修饰器旨在用于函数,而不是方法。
请改用 @singledispatchmethod 修饰器,或将该方法迁移到独立函数。
示例
建议改为
from functools import singledispatchmethod
class Class:
@singledispatchmethod
def method(self, arg): ...
修复安全性
此规则的修复被标记为不安全,因为从 @singledispatch 迁移到 @singledispatchmethod 可能会更改代码的行为。