Skip to content

Commit

Permalink
Ignore dunder imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tjkuson committed Aug 1, 2023
1 parent d1bda83 commit 542d555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions crates/ruff/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,16 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::DeprecatedImport) {
pyupgrade::rules::deprecated_import(checker, stmt, names, module, level);
}
if checker.enabled(Rule::ImportPrivateName) {
pylint::rules::import_private_name(
checker,
stmt,
names,
module,
level,
checker.module_path,
);
}
if checker.enabled(Rule::UnnecessaryBuiltinImport) {
if let Some(module) = module {
pyupgrade::rules::unnecessary_builtin_import(checker, stmt, module, names);
Expand Down
6 changes: 2 additions & 4 deletions crates/ruff/src/rules/pylint/rules/import_private_name.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use rustpython_parser::ast::{Alias, Ranged, Stmt};
use ruff_python_ast::{Alias, Ranged, Stmt};

use crate::checkers::ast::Checker;

Expand Down Expand Up @@ -105,9 +105,7 @@ pub(crate) fn import_private_name(
));
}
for name in names {
// It is common to import the package version as `__version__` and
// to name translation functions `_`. Ignore these names.
if matches!(name.name.as_str(), "__version__" | "_") {
if matches!(name.name.as_str(), "_") || name.name.starts_with("__") {
continue;
}
if name.name.starts_with('_') {
Expand Down

0 comments on commit 542d555

Please sign in to comment.