Respect noqa directives on ImportFrom parents for type-checking rules (#4889)

This commit is contained in:
Charlie Marsh 2023-06-05 22:37:07 -04:00 committed by GitHub
parent c2a3e97b7f
commit 7b0fb1a3b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 35 deletions

View file

@ -2,6 +2,7 @@ use std::ops::{Deref, DerefMut};
use bitflags::bitflags;
use ruff_text_size::TextRange;
use rustpython_parser::ast::Ranged;
use ruff_index::{newtype_index, IndexSlice, IndexVec};
use ruff_python_ast::helpers;
@ -143,6 +144,19 @@ impl<'a> Binding<'a> {
_ => self.range,
}
}
/// Returns the range of the binding's parent.
pub fn parent_range(&self, semantic_model: &SemanticModel) -> Option<TextRange> {
self.source
.map(|node_id| semantic_model.stmts[node_id])
.and_then(|parent| {
if parent.is_import_from_stmt() {
Some(parent.range())
} else {
None
}
})
}
}
bitflags! {