Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flake8-builtins] Skip lambda expressions in builtin-argument-shadowing (A002) #14144

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ async def func3(id, dir):
pass


# this is Ok for A002 (trigger A005 instead)
# https://github.com/astral-sh/ruff/issues/14135
map([], lambda float: ...)

from typing import override, overload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
lambda min, max: min
lambda id: id
lambda dir: dir

# Ok for A006 - should trigger A002 instead
# https://github.com/astral-sh/ruff/issues/14135
def func1(str, /, type, *complex, Exception, **getattr):
pass
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_diagnostics::Diagnostic;
use ruff_diagnostics::Violation;
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::Parameter;
use ruff_python_ast::{Expr, Parameter};
use ruff_python_semantic::analyze::visibility::{is_overload, is_override};
use ruff_text_size::Ranged;

Expand Down Expand Up @@ -70,6 +70,15 @@ pub(crate) fn builtin_argument_shadowing(checker: &mut Checker, parameter: &Para
&checker.settings.flake8_builtins.builtins_ignorelist,
checker.settings.target_version,
) {
// Ignore parameters in lambda expressions.
// (That is the domain of A006.)
if checker
.semantic()
.current_expression()
.is_some_and(Expr::is_lambda_expr)
{
return;
}
// Ignore `@override` and `@overload` decorated functions.
if checker
.semantic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,3 @@ A002.py:9:21: A002 Argument `dir` is shadowing a Python builtin
| ^^^ A002
10 | pass
|

A002.py:13:16: A002 Argument `float` is shadowing a Python builtin
|
13 | map([], lambda float: ...)
| ^^^^^ A002
14 |
15 | from typing import override, overload
|
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,3 @@ A002.py:5:17: A002 Argument `bytes` is shadowing a Python builtin
| ^^^^^ A002
6 | pass
|

A002.py:13:16: A002 Argument `float` is shadowing a Python builtin
|
13 | map([], lambda float: ...)
| ^^^^^ A002
14 |
15 | from typing import override, overload
|
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ A006.py:5:8: A006 Lambda argument `dir` is shadowing a Python builtin
4 | lambda id: id
5 | lambda dir: dir
| ^^^ A006
6 |
7 | # Ok for A006 - should trigger A002 instead
|
Loading