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:
Charlie Marsh 2023-07-16 00:49:48 -04:00 committed by GitHub
parent 59dfd0e793
commit 01b05fe247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 174 deletions

View file

@ -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())