Skip to content

Commit

Permalink
Avoid falsely marking non-submodules as submodule aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 30, 2023
1 parent 76741ca commit a03d700
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F823.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ def main():

for sys in range(5):
pass


import requests_mock as rm


def requests_mock(requests_mock: rm.Mocker):
print(rm.ANY)
9 changes: 9 additions & 0 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,15 @@ impl<'a> Checker<'a> {
return binding_id;
}

println!(
"same scope shadowed_id: {:?}",
&self.semantic.bindings[shadowed_id]
);
println!(
"same scope binding_id: {:?}",
&self.semantic.bindings[binding_id]
);

// Avoid shadowing builtins.
let shadowed = &self.semantic.bindings[shadowed_id];
if !matches!(
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff/src/rules/pyflakes/rules/undefined_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub(crate) fn undefined_local(
None
}
}) {
println!("shadowed: {:?}", shadowed);
println!("binding: {:?}", checker.semantic().binding(binding_id));
// Then it's probably an error.
diagnostics.push(Diagnostic::new(
UndefinedLocal {
Expand Down
7 changes: 6 additions & 1 deletion crates/ruff_python_semantic/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,12 @@ impl<'a> SemanticModel<'a> {
return None;
}

self.scopes[scope_id].get(qualified_name)
let binding_id = self.scopes[scope_id].get(qualified_name)?;
if !self.bindings[binding_id].kind.is_submodule_import() {
return None;
}

Some(binding_id)
}

/// Resolves the [`Expr`] to a fully-qualified symbol-name, if `value` resolves to an imported
Expand Down

0 comments on commit a03d700

Please sign in to comment.