mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 09:31:09 +00:00
Remove Identifier
usages for isolating exception names (#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.
This commit is contained in:
parent
59dfd0e793
commit
01b05fe247
9 changed files with 107 additions and 174 deletions
|
@ -138,22 +138,6 @@ impl TryIdentifier for Pattern {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryIdentifier for ExceptHandler {
|
||||
/// Return the [`TextRange`] of a named exception in an [`ExceptHandler`].
|
||||
///
|
||||
/// For example, return the range of `e` in:
|
||||
/// ```python
|
||||
/// try:
|
||||
/// ...
|
||||
/// except ValueError as e:
|
||||
/// ...
|
||||
/// ```
|
||||
fn try_identifier(&self) -> Option<TextRange> {
|
||||
let ExceptHandler::ExceptHandler(ast::ExceptHandlerExceptHandler { name, .. }) = self;
|
||||
name.as_ref().map(Ranged::range)
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the [`TextRange`] of the `except` token in an [`ExceptHandler`].
|
||||
pub fn except(handler: &ExceptHandler, locator: &Locator) -> TextRange {
|
||||
IdentifierTokenizer::new(locator.contents(), handler.range())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue