-
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.
Ensure that B006 autofixes are inserted after imports (#7629)
## Summary Fixes #7616 by ensuring that [B006](https://docs.astral.sh/ruff/rules/mutable-argument-default/#mutable-argument-default-b006) fixes are inserted after module imports. I have created a new test file, `B006_5.py`. This is mainly because I have been working on this on and off, and the merge conflicts were easier to handle in a separate file. If needed, I can move it into another file. ## Test Plan `cargo test`
- Loading branch information
Showing
9 changed files
with
514 additions
and
33 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B006_5.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,74 @@ | ||
# Move mutable arguments below imports and docstrings | ||
# https://github.com/astral-sh/ruff/issues/7616 | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
import os | ||
|
||
|
||
def import_module_with_values_wrong(value: dict[str, str] = {}): | ||
import os | ||
|
||
return 2 | ||
|
||
|
||
def import_modules_wrong(value: dict[str, str] = {}): | ||
import os | ||
import sys | ||
import itertools | ||
|
||
|
||
def from_import_module_wrong(value: dict[str, str] = {}): | ||
from os import path | ||
|
||
|
||
def from_imports_module_wrong(value: dict[str, str] = {}): | ||
from os import path | ||
from sys import version_info | ||
|
||
|
||
def import_and_from_imports_module_wrong(value: dict[str, str] = {}): | ||
import os | ||
from sys import version_info | ||
|
||
|
||
def import_docstring_module_wrong(value: dict[str, str] = {}): | ||
"""Docstring""" | ||
import os | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
"""Docstring""" | ||
import os; import sys | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
"""Docstring""" | ||
import os; import sys; x = 1 | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
"""Docstring""" | ||
import os; import sys | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
import os; import sys | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
import os; import sys; x = 1 | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): | ||
import os; import sys | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): import os | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): import os; import sys | ||
|
||
|
||
def import_module_wrong(value: dict[str, str] = {}): \ | ||
import os |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B006_6.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,5 @@ | ||
# Import followed by whitespace with no newline | ||
# Same as B006_2.py, but import instead of docstring | ||
|
||
def foobar(foor, bar={}): | ||
import os |
5 changes: 5 additions & 0 deletions
5
crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B006_7.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,5 @@ | ||
# Import with no newline | ||
# Same as B006_3.py, but import instead of docstring | ||
|
||
def foobar(foor, bar={}): | ||
import os |
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
Oops, something went wrong.