跳到内容

singledispatchmethod-函数 (PLE1520)

源自 Pylint 代码检查工具。

有时提供修复。

作用

检查使用 @singledispatchmethod 装饰的非方法函数。

为什么这不好?

@singledispatchmethod 装饰器旨在用于方法,而不是函数。

请使用 @singledispatch 装饰器代替。

示例

from functools import singledispatchmethod


@singledispatchmethod
def func(arg): ...

建议改为

from functools import singledispatch


@singledispatch
def func(arg): ...

修复安全性

此规则的修复被标记为不安全,因为从 @singledispatchmethod 迁移到 @singledispatch 可能会更改代码的行为。