mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 16:40:19 +00:00
Allow removal of typing
from exempt-modules
(#9214)
## Summary If you remove `typing` from `exempt-modules`, we tend to panic, since we try to add `TYPE_CHECKING` to `from typing import ...` statements while concurrently attempting to remove other members from that import. This PR adds special-casing for typing imports to avoid such panics. Closes https://github.com/astral-sh/ruff/issues/5331 Closes https://github.com/astral-sh/ruff/issues/9196. Closes https://github.com/astral-sh/ruff/issues/9197.
This commit is contained in:
parent
29846f5b09
commit
4b4160eb48
10 changed files with 235 additions and 35 deletions
|
@ -761,6 +761,7 @@ impl<'a> SemanticModel<'a> {
|
|||
{
|
||||
return Some(ImportedName {
|
||||
name: format!("{name}.{member}"),
|
||||
source,
|
||||
range: self.nodes[source].range(),
|
||||
context: binding.context,
|
||||
});
|
||||
|
@ -785,6 +786,7 @@ impl<'a> SemanticModel<'a> {
|
|||
{
|
||||
return Some(ImportedName {
|
||||
name: (*name).to_string(),
|
||||
source,
|
||||
range: self.nodes[source].range(),
|
||||
context: binding.context,
|
||||
});
|
||||
|
@ -806,6 +808,7 @@ impl<'a> SemanticModel<'a> {
|
|||
{
|
||||
return Some(ImportedName {
|
||||
name: format!("{name}.{member}"),
|
||||
source,
|
||||
range: self.nodes[source].range(),
|
||||
context: binding.context,
|
||||
});
|
||||
|
@ -1828,6 +1831,8 @@ pub enum ReadResult {
|
|||
pub struct ImportedName {
|
||||
/// The name to which the imported symbol is bound.
|
||||
name: String,
|
||||
/// The statement from which the symbol is imported.
|
||||
source: NodeId,
|
||||
/// The range at which the symbol is imported.
|
||||
range: TextRange,
|
||||
/// The context in which the symbol is imported.
|
||||
|
@ -1842,6 +1847,10 @@ impl ImportedName {
|
|||
pub const fn context(&self) -> ExecutionContext {
|
||||
self.context
|
||||
}
|
||||
|
||||
pub fn statement<'a>(&self, semantic: &'a SemanticModel) -> &'a Stmt {
|
||||
semantic.statement(self.source)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ranged for ImportedName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue