Skip to content

Commit

Permalink
[ruff F401 #10390 #10391] fixture tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plredmond committed Apr 27, 2024
1 parent 3687485 commit e57f900
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'''__init__.py without __all__
Stdlib and third party imports are unsafe removals
First party imports get changed to redundant aliases
'''



import os # Ok: is used
_ = os



import sys # F401: remove unused



import used # Ok: is used
_ = used







import aliased as aliased # Ok: is redundant alias



import renamed as bees # Ok: is aliased



import unused # F401: change to redundant alias
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'''__init__.py with __all__
First party imports get added to __all__
Stdlib and third party imports are unsafe removals
'''



import os # Ok: is used
_ = os



import sys # F401: remove unused



import argparse # Ok: is exported



import used # Ok: is used
_ = used



import aliased as aliased # Ok: is redundant alias



import renamed as bees # Ok: is aliased



import unused # F401: add to __all__



__all__ = ["argparse"]
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/rules/pyflakes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ mod tests {
#[test_case(Rule::UnusedImport, Path::new("F401_21.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_22.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_23.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_24/__init__.py"))]
#[test_case(Rule::UnusedImport, Path::new("F401_25_dunder_all/__init__.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.py"))]
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.ipynb"))]
#[test_case(Rule::UndefinedLocalWithImportStar, Path::new("F403.py"))]
Expand Down
5 changes: 3 additions & 2 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Violation for UnusedImport {

fn is_first_party(checker: &Checker, qualified_name: &str) -> bool {
use isort::{ImportSection, ImportType};
match isort::categorize(
let category = isort::categorize(
qualified_name,
None,
&checker.settings.src,
Expand All @@ -127,7 +127,8 @@ fn is_first_party(checker: &Checker, qualified_name: &str) -> bool {
checker.settings.isort.no_sections,
&checker.settings.isort.section_order,
&checker.settings.isort.default_section,
) {
);
match category {
ImportSection::Known(ImportType::FirstParty | ImportType::LocalFolder) => true,
_ => false,
}
Expand Down

0 comments on commit e57f900

Please sign in to comment.