Skip to content

lambda-assignment

Pythonstyleno fixdefault: off

Reports a lambda assigned to a single name. An annotated assignment in a class body is left alone.

A def gives the function a real name in tracebacks and repr, takes annotations and a docstring, and reads as what it is. The lambda keeps its generic name, <lambda>.

To fix, write a def.

Reported
h = 1
f = lambda x: x
g: int = lambda: 1
h.attr = lambda: 1
j = (lambda: 1)()
k = [lambda: 1]
python:
lint:
rules:
lambda-assignment: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line lambda-assignment in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff E731 full