mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:50:38 +00:00
Avoid shadowing diagnostics for @override
methods (#12415)
Closes https://github.com/astral-sh/ruff/issues/12412.
This commit is contained in:
parent
c0a2b49bac
commit
4bcc96ae51
4 changed files with 50 additions and 30 deletions
|
@ -5,7 +5,21 @@ def func1(str, /, type, *complex, Exception, **getattr):
|
|||
async def func2(bytes):
|
||||
pass
|
||||
|
||||
|
||||
async def func3(id, dir):
|
||||
pass
|
||||
|
||||
|
||||
map([], lambda float: ...)
|
||||
|
||||
from typing import override, overload
|
||||
|
||||
|
||||
@override
|
||||
def func4(id, dir):
|
||||
pass
|
||||
|
||||
|
||||
@overload
|
||||
def func4(id, dir):
|
||||
pass
|
||||
|
|
|
@ -3,6 +3,7 @@ use ruff_python_ast::Parameter;
|
|||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_diagnostics::Violation;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::analyze::visibility::{is_overload, is_override};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
@ -69,6 +70,19 @@ pub(crate) fn builtin_argument_shadowing(checker: &mut Checker, parameter: &Para
|
|||
&checker.settings.flake8_builtins.builtins_ignorelist,
|
||||
checker.source_type,
|
||||
) {
|
||||
// Ignore `@override` and `@overload` decorated functions.
|
||||
if checker
|
||||
.semantic()
|
||||
.current_statement()
|
||||
.as_function_def_stmt()
|
||||
.is_some_and(|function_def| {
|
||||
is_override(&function_def.decorator_list, checker.semantic())
|
||||
|| is_overload(&function_def.decorator_list, checker.semantic())
|
||||
})
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checker.diagnostics.push(Diagnostic::new(
|
||||
BuiltinArgumentShadowing {
|
||||
name: parameter.name.to_string(),
|
||||
|
|
|
@ -43,30 +43,24 @@ A002.py:5:17: A002 Argument `bytes` is shadowing a Python builtin
|
|||
6 | pass
|
||||
|
|
||||
|
||||
A002.py:8:17: A002 Argument `id` is shadowing a Python builtin
|
||||
|
|
||||
6 | pass
|
||||
7 |
|
||||
8 | async def func3(id, dir):
|
||||
| ^^ A002
|
||||
9 | pass
|
||||
|
|
||||
|
||||
A002.py:8:21: A002 Argument `dir` is shadowing a Python builtin
|
||||
|
|
||||
6 | pass
|
||||
7 |
|
||||
8 | async def func3(id, dir):
|
||||
| ^^^ A002
|
||||
9 | pass
|
||||
|
|
||||
|
||||
A002.py:11:16: A002 Argument `float` is shadowing a Python builtin
|
||||
A002.py:9:17: A002 Argument `id` is shadowing a Python builtin
|
||||
|
|
||||
9 | pass
|
||||
10 |
|
||||
11 | map([], lambda float: ...)
|
||||
9 | async def func3(id, dir):
|
||||
| ^^ A002
|
||||
10 | pass
|
||||
|
|
||||
|
||||
A002.py:9:21: A002 Argument `dir` is shadowing a Python builtin
|
||||
|
|
||||
9 | async def func3(id, dir):
|
||||
| ^^^ 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
|
||||
|
|
||||
|
||||
|
||||
|
|
|
@ -43,12 +43,10 @@ A002.py:5:17: A002 Argument `bytes` is shadowing a Python builtin
|
|||
6 | pass
|
||||
|
|
||||
|
||||
A002.py:11:16: A002 Argument `float` is shadowing a Python builtin
|
||||
A002.py:13:16: A002 Argument `float` is shadowing a Python builtin
|
||||
|
|
||||
9 | pass
|
||||
10 |
|
||||
11 | map([], lambda float: ...)
|
||||
13 | map([], lambda float: ...)
|
||||
| ^^^^^ A002
|
||||
14 |
|
||||
15 | from typing import override, overload
|
||||
|
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue