-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-bugbear
] Treat raise NotImplemented
-only bodies as stub f…
…unctions (#10990) ## Summary As discussed in #10083 (comment), stubs detection now also covers the case where the function body raises NotImplementedError and does nothing else. ## Test Plan Tests for the relevant cases were added in B006_8.py
- Loading branch information
1 parent
f48a794
commit 2971655
Showing
4 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B006_8.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def foo(a: list = []): | ||
raise NotImplementedError("") | ||
|
||
|
||
def bar(a: dict = {}): | ||
""" This one also has a docstring""" | ||
raise NotImplementedError("and has some text in here") | ||
|
||
|
||
def baz(a: list = []): | ||
"""This one raises a different exception""" | ||
raise IndexError() | ||
|
||
|
||
def qux(a: list = []): | ||
raise NotImplementedError | ||
|
||
|
||
def quux(a: list = []): | ||
raise NotImplemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...s/flake8_bugbear/snapshots/ruff_linter__rules__flake8_bugbear__tests__B006_B006_8.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs | ||
--- | ||
B006_8.py:1:19: B006 [*] Do not use mutable data structures for argument defaults | ||
| | ||
1 | def foo(a: list = []): | ||
| ^^ B006 | ||
2 | raise NotImplementedError("") | ||
| | ||
= help: Replace with `None`; initialize within function | ||
|
||
ℹ Unsafe fix | ||
1 |-def foo(a: list = []): | ||
1 |+def foo(a: list = None): | ||
2 2 | raise NotImplementedError("") | ||
3 3 | | ||
4 4 | | ||
|
||
B006_8.py:5:19: B006 [*] Do not use mutable data structures for argument defaults | ||
| | ||
5 | def bar(a: dict = {}): | ||
| ^^ B006 | ||
6 | """ This one also has a docstring""" | ||
7 | raise NotImplementedError("and has some text in here") | ||
| | ||
= help: Replace with `None`; initialize within function | ||
|
||
ℹ Unsafe fix | ||
2 2 | raise NotImplementedError("") | ||
3 3 | | ||
4 4 | | ||
5 |-def bar(a: dict = {}): | ||
5 |+def bar(a: dict = None): | ||
6 6 | """ This one also has a docstring""" | ||
7 7 | raise NotImplementedError("and has some text in here") | ||
8 8 | | ||
|
||
B006_8.py:10:19: B006 [*] Do not use mutable data structures for argument defaults | ||
| | ||
10 | def baz(a: list = []): | ||
| ^^ B006 | ||
11 | """This one raises a different exception""" | ||
12 | raise IndexError() | ||
| | ||
= help: Replace with `None`; initialize within function | ||
|
||
ℹ Unsafe fix | ||
7 7 | raise NotImplementedError("and has some text in here") | ||
8 8 | | ||
9 9 | | ||
10 |-def baz(a: list = []): | ||
10 |+def baz(a: list = None): | ||
11 11 | """This one raises a different exception""" | ||
12 |+ if a is None: | ||
13 |+ a = [] | ||
12 14 | raise IndexError() | ||
13 15 | | ||
14 16 | | ||
|
||
B006_8.py:15:19: B006 [*] Do not use mutable data structures for argument defaults | ||
| | ||
15 | def qux(a: list = []): | ||
| ^^ B006 | ||
16 | raise NotImplementedError | ||
| | ||
= help: Replace with `None`; initialize within function | ||
|
||
ℹ Unsafe fix | ||
12 12 | raise IndexError() | ||
13 13 | | ||
14 14 | | ||
15 |-def qux(a: list = []): | ||
15 |+def qux(a: list = None): | ||
16 16 | raise NotImplementedError | ||
17 17 | | ||
18 18 | | ||
|
||
B006_8.py:19:20: B006 [*] Do not use mutable data structures for argument defaults | ||
| | ||
19 | def quux(a: list = []): | ||
| ^^ B006 | ||
20 | raise NotImplemented | ||
| | ||
= help: Replace with `None`; initialize within function | ||
|
||
ℹ Unsafe fix | ||
16 16 | raise NotImplementedError | ||
17 17 | | ||
18 18 | | ||
19 |-def quux(a: list = []): | ||
19 |+def quux(a: list = None): | ||
20 20 | raise NotImplemented |