Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions crates/ruff_linter/src/rules/pylint/rules/unnecessary_lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// change the argument names, which can lead to a change in behavior when
/// callers pass arguments by name.
///
/// For example, replacing `foo = lambda x, y: func(x, y)` with `foo = func`,
/// where `func` is defined as `def func(a, b): return a + b`, would be a
/// breaking change for callers that execute the lambda by passing arguments by
/// name, as in: `foo(x=1, y=2)`. Since `func` does not define the arguments
/// `x` and `y`, unlike the lambda, the call would raise a `TypeError`.
/// For example:
///
/// ```python
/// def func(a, b):
/// return a + b
///
///
/// foo = lambda x, y: func(x, y)
/// ```
///
/// Replacing the assignment to `foo` with `foo = func` would be a breaking
/// change for callers that execute the lambda by passing arguments by name, as
/// in: `foo(x=1, y=2)`. Since `func` does not define the arguments `x` and `y`,
/// unlike the lambda, the call would raise a `TypeError`.
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "v0.1.2")]
#[violation_metadata(stable_since = "0.15.0")]
pub(crate) struct UnnecessaryLambda;

impl Violation for UnnecessaryLambda {
Expand Down