mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
[flake8-bugbear
] Fix B028
to allow stacklevel
to be explicitly assigned as a positional argument (#14868)
This commit is contained in:
parent
3865fb6641
commit
172143ae77
3 changed files with 41 additions and 37 deletions
|
@ -5,13 +5,16 @@ Should emit:
|
||||||
B028 - on lines 8 and 9
|
B028 - on lines 8 and 9
|
||||||
"""
|
"""
|
||||||
|
|
||||||
warnings.warn(DeprecationWarning("test"))
|
warnings.warn("test", DeprecationWarning)
|
||||||
warnings.warn(DeprecationWarning("test"), source=None)
|
warnings.warn("test", DeprecationWarning, source=None)
|
||||||
warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
warnings.warn(DeprecationWarning("test"), stacklevel=1)
|
warnings.warn("test", DeprecationWarning, stacklevel=1)
|
||||||
|
warnings.warn("test", DeprecationWarning, 1)
|
||||||
|
warnings.warn("test", category=DeprecationWarning, stacklevel=1)
|
||||||
|
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
DeprecationWarning("test"),
|
"test",
|
||||||
|
DeprecationWarning,
|
||||||
# some comments here
|
# some comments here
|
||||||
source = None # no trailing comma
|
source = None # no trailing comma
|
||||||
)
|
)
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub(crate) fn no_explicit_stacklevel(checker: &mut Checker, call: &ast::ExprCall
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if call.arguments.find_keyword("stacklevel").is_some() {
|
if call.arguments.find_argument("stacklevel", 2).is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut diagnostic = Diagnostic::new(NoExplicitStacklevel, call.func.range());
|
let mut diagnostic = Diagnostic::new(NoExplicitStacklevel, call.func.range());
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
---
|
---
|
||||||
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
|
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
|
||||||
|
snapshot_kind: text
|
||||||
---
|
---
|
||||||
B028.py:8:1: B028 [*] No explicit `stacklevel` keyword argument found
|
B028.py:8:1: B028 [*] No explicit `stacklevel` keyword argument found
|
||||||
|
|
|
|
||||||
6 | """
|
6 | """
|
||||||
7 |
|
7 |
|
||||||
8 | warnings.warn(DeprecationWarning("test"))
|
8 | warnings.warn("test", DeprecationWarning)
|
||||||
| ^^^^^^^^^^^^^ B028
|
| ^^^^^^^^^^^^^ B028
|
||||||
9 | warnings.warn(DeprecationWarning("test"), source=None)
|
9 | warnings.warn("test", DeprecationWarning, source=None)
|
||||||
10 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
10 | warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
|
|
|
|
||||||
= help: Set `stacklevel=2`
|
= help: Set `stacklevel=2`
|
||||||
|
|
||||||
|
@ -16,48 +17,48 @@ B028.py:8:1: B028 [*] No explicit `stacklevel` keyword argument found
|
||||||
5 5 | B028 - on lines 8 and 9
|
5 5 | B028 - on lines 8 and 9
|
||||||
6 6 | """
|
6 6 | """
|
||||||
7 7 |
|
7 7 |
|
||||||
8 |-warnings.warn(DeprecationWarning("test"))
|
8 |-warnings.warn("test", DeprecationWarning)
|
||||||
8 |+warnings.warn(DeprecationWarning("test"), stacklevel=2)
|
8 |+warnings.warn("test", DeprecationWarning, stacklevel=2)
|
||||||
9 9 | warnings.warn(DeprecationWarning("test"), source=None)
|
9 9 | warnings.warn("test", DeprecationWarning, source=None)
|
||||||
10 10 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
10 10 | warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
11 11 | warnings.warn(DeprecationWarning("test"), stacklevel=1)
|
11 11 | warnings.warn("test", DeprecationWarning, stacklevel=1)
|
||||||
|
|
||||||
B028.py:9:1: B028 [*] No explicit `stacklevel` keyword argument found
|
B028.py:9:1: B028 [*] No explicit `stacklevel` keyword argument found
|
||||||
|
|
|
|
||||||
8 | warnings.warn(DeprecationWarning("test"))
|
8 | warnings.warn("test", DeprecationWarning)
|
||||||
9 | warnings.warn(DeprecationWarning("test"), source=None)
|
9 | warnings.warn("test", DeprecationWarning, source=None)
|
||||||
| ^^^^^^^^^^^^^ B028
|
| ^^^^^^^^^^^^^ B028
|
||||||
10 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
10 | warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
11 | warnings.warn(DeprecationWarning("test"), stacklevel=1)
|
11 | warnings.warn("test", DeprecationWarning, stacklevel=1)
|
||||||
|
|
|
|
||||||
= help: Set `stacklevel=2`
|
= help: Set `stacklevel=2`
|
||||||
|
|
||||||
ℹ Unsafe fix
|
ℹ Unsafe fix
|
||||||
6 6 | """
|
6 6 | """
|
||||||
7 7 |
|
7 7 |
|
||||||
8 8 | warnings.warn(DeprecationWarning("test"))
|
8 8 | warnings.warn("test", DeprecationWarning)
|
||||||
9 |-warnings.warn(DeprecationWarning("test"), source=None)
|
9 |-warnings.warn("test", DeprecationWarning, source=None)
|
||||||
10 9 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
10 9 | warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
10 |+warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2)
|
10 |+warnings.warn("test", DeprecationWarning, source=None, stacklevel=2)
|
||||||
11 11 | warnings.warn(DeprecationWarning("test"), stacklevel=1)
|
11 11 | warnings.warn("test", DeprecationWarning, stacklevel=1)
|
||||||
12 12 |
|
12 12 | warnings.warn("test", DeprecationWarning, 1)
|
||||||
13 13 | warnings.warn(
|
13 13 | warnings.warn("test", category=DeprecationWarning, stacklevel=1)
|
||||||
|
|
||||||
B028.py:13:1: B028 [*] No explicit `stacklevel` keyword argument found
|
B028.py:15:1: B028 [*] No explicit `stacklevel` keyword argument found
|
||||||
|
|
|
|
||||||
11 | warnings.warn(DeprecationWarning("test"), stacklevel=1)
|
13 | warnings.warn("test", category=DeprecationWarning, stacklevel=1)
|
||||||
12 |
|
14 |
|
||||||
13 | warnings.warn(
|
15 | warnings.warn(
|
||||||
| ^^^^^^^^^^^^^ B028
|
| ^^^^^^^^^^^^^ B028
|
||||||
14 | DeprecationWarning("test"),
|
16 | "test",
|
||||||
15 | # some comments here
|
17 | DeprecationWarning,
|
||||||
|
|
|
|
||||||
= help: Set `stacklevel=2`
|
= help: Set `stacklevel=2`
|
||||||
|
|
||||||
ℹ Unsafe fix
|
ℹ Unsafe fix
|
||||||
13 13 | warnings.warn(
|
16 16 | "test",
|
||||||
14 14 | DeprecationWarning("test"),
|
17 17 | DeprecationWarning,
|
||||||
15 15 | # some comments here
|
18 18 | # some comments here
|
||||||
16 |- source = None # no trailing comma
|
19 |- source = None # no trailing comma
|
||||||
16 |+ source = None, stacklevel=2 # no trailing comma
|
19 |+ source = None, stacklevel=2 # no trailing comma
|
||||||
17 17 | )
|
20 20 | )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue