A lambda is assigned to a name where a def would give it that name
What it finds
square = lambda x: x * x makes a function whose name in tracebacks and repr is <lambda>, and that cannot have a docstring or annotations. def square(x): return x * x does the same with a proper name. Reported are assignments of a lambda to a single name; lambdas passed as arguments or stored in containers and attributes are left alone.
From the rule's source, lambda_assignment.rs.
square = lambda x: x * xtx0 reports: square holds a lambda; def square(...) gives the function its name def sort(items): key: object = lambda item: item.nametx0 reports: key holds a lambda handlers = {"a": lambda: 1} obj.callback = lambda: 2 return sorted(items, key=lambda i: i) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:lambda-assignment" = "note"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:lambda-assignment] reason="..."tx0 explain tx0/python:lambda-assignment shows the same in the terminal. Found a false positive? Report it.