Fix ranges for global usages (#6917)

## Summary

The range of the usage from `Globals` should be the range of the
identifier, not the range of the full `global pandas` statement.

Closes https://github.com/astral-sh/ruff/issues/6914.
This commit is contained in:
Charlie Marsh 2023-08-27 11:27:07 -04:00 committed by GitHub
parent 381fc5b2a8
commit d0b051e447
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 30 deletions

View file

@ -5,7 +5,7 @@
use std::ops::Index;
use ruff_python_ast as ast;
use ruff_python_ast::Stmt;
use ruff_python_ast::{Ranged, Stmt};
use ruff_text_size::TextRange;
use rustc_hash::FxHashMap;
@ -75,9 +75,9 @@ impl<'a> GlobalsVisitor<'a> {
impl<'a> StatementVisitor<'a> for GlobalsVisitor<'a> {
fn visit_stmt(&mut self, stmt: &'a Stmt) {
match stmt {
Stmt::Global(ast::StmtGlobal { names, range }) => {
Stmt::Global(ast::StmtGlobal { names, range: _ }) => {
for name in names {
self.0.insert(name.as_str(), *range);
self.0.insert(name.as_str(), name.range());
}
}
Stmt::FunctionDef(_) | Stmt::ClassDef(_) => {