Skip to content

Forbid usage of functools.singledispatch #1360

@nathanjmcdougall

Description

@nathanjmcdougall

Toward #1340.

singledispatch has semantics which don't play nicely with static analysis. Arguably, they're needlessly verbose.

I would prefer to refactor just use if-branch logic.

We should set up a Ruff rule for this, e.g. using example config from docs:

banned-api

Specific modules or module members that may not be imported or accessed. Note that this rule is only meant to flag accidental uses, and can be circumvented via eval or importlib.

Default value: {}

Type: dict[str, { "msg": str }]

Example usage:

pyproject.toml
ruff.toml

[lint.flake8-tidy-imports.banned-api]
"cgi".msg = "The cgi module is deprecated, see https://peps.python.org/pep-0594/#cgi."
"typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions