mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-10 05:39:12 +00:00
Respect noqa directives on ImportFrom
parents for type-checking rules (#4889)
This commit is contained in:
parent
c2a3e97b7f
commit
7b0fb1a3b4
5 changed files with 59 additions and 35 deletions
|
@ -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! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue