forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
Identifier
usages for isolating exception names (astral-sh#5797
) ## Summary The motivating change here is to remove `let range = except_handler.try_identifier().unwrap();` and instead just do `name.range()`, since exception names now have ranges attached to them by the parse. This also required some refactors (which are improvements) to the built-in attribute shadowing rules, since at least one invocation relied on passing in the exception handler and calling `.try_identifier()`. Now that we have easy access to identifiers, we can remove the whole `AnyShadowing` abstraction.
- Loading branch information
1 parent
59dfd0e
commit 01b05fe
Showing
9 changed files
with
103 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,5 @@ | ||
use ruff_text_size::TextRange; | ||
use rustpython_parser::ast::{ExceptHandler, Expr, Ranged, Stmt}; | ||
|
||
use ruff_python_ast::identifier::{Identifier, TryIdentifier}; | ||
use ruff_python_stdlib::builtins::BUILTINS; | ||
|
||
pub(super) fn shadows_builtin(name: &str, ignorelist: &[String]) -> bool { | ||
BUILTINS.contains(&name) && ignorelist.iter().all(|ignore| ignore != name) | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
pub(crate) enum AnyShadowing<'a> { | ||
Expression(&'a Expr), | ||
Statement(&'a Stmt), | ||
ExceptHandler(&'a ExceptHandler), | ||
} | ||
|
||
impl Identifier for AnyShadowing<'_> { | ||
fn identifier(&self) -> TextRange { | ||
match self { | ||
AnyShadowing::Expression(expr) => expr.range(), | ||
AnyShadowing::Statement(stmt) => stmt.identifier(), | ||
AnyShadowing::ExceptHandler(handler) => handler.try_identifier().unwrap(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> From<&'a Stmt> for AnyShadowing<'a> { | ||
fn from(value: &'a Stmt) -> Self { | ||
AnyShadowing::Statement(value) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a Expr> for AnyShadowing<'a> { | ||
fn from(value: &'a Expr) -> Self { | ||
AnyShadowing::Expression(value) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a ExceptHandler> for AnyShadowing<'a> { | ||
fn from(value: &'a ExceptHandler) -> Self { | ||
AnyShadowing::ExceptHandler(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.