Skip to content

singledispatchmethod-function (PLE1520)#

Derived from the Pylint linter.

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for non-method functions decorated with @singledispatchmethod.

Why is this bad?#

The @singledispatchmethod decorator is intended for use with methods, not functions.

Instead, use the @singledispatch decorator.

Example#

from functools import singledispatchmethod


@singledispatchmethod
def func(arg):
    ...

Use instead:

from functools import singledispatchmethod


@singledispatch
def func(arg):
    ...

Fix safety#

This rule's fix is marked as unsafe, as migrating from @singledispatchmethod to @singledispatch may change the behavior of the code.