Skip to content

Commit

Permalink
Don't treat straight imports of __future__ as '__future__' imports
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 15, 2023
1 parent 5ea3e42 commit 6c92add
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
19 changes: 1 addition & 18 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,24 +805,7 @@ where
}

for alias in names {
if &alias.name == "__future__" {
let name = alias.asname.as_ref().unwrap_or(&alias.name);
self.add_binding(
name,
alias.identifier(self.locator),
BindingKind::FutureImportation,
BindingFlags::empty(),
);

if self.enabled(Rule::LateFutureImport) {
if self.semantic.seen_futures_boundary() {
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::LateFutureImport,
stmt.range(),
));
}
}
} else if alias.name.contains('.') && alias.asname.is_none() {
if alias.name.contains('.') && alias.asname.is_none() {
// Given `import foo.bar`, `name` would be "foo", and `qualified_name` would be
// "foo.bar".
let name = alias.name.split('.').next().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,4 @@ F404.py:6:1: F404 `from __future__` imports must occur at the beginning of the f
8 | import __future__
|

F404.py:8:1: F404 `from __future__` imports must occur at the beginning of the file
|
6 | from __future__ import print_function
7 |
8 | import __future__
| ^^^^^^^^^^^^^^^^^ F404
|


0 comments on commit 6c92add

Please sign in to comment.