generic-function
What it does
Section titled “What it does”Reports a function outside a class whose parameters use a module-level TypeVar, ParamSpec or TypeVarTuple, when the target_version has type parameters (3.12 and later).
Why it matters
Section titled “Why it matters”Since Python 3.12 a function declares its type variables itself, def first[T](xs: list[T]) -> T:, so the variable is scoped to the function and a module-level declaration is not needed.
To fix, declare the type parameters on the function.
Example
Section titled “Example”...
from typing import TypeVarT = TypeVar("T")def f(x: T) -> T: return x
def g() -> T:...Configuration
Section titled “Configuration”python: lint: rules: generic-function: warn # off (default), warn, errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line generic-function in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | UP047 |
full |