Ignore NPY201 inside except blocks for compatibility with older numpy versions (#12490)

This commit is contained in:
Alex Waygood 2024-07-24 21:03:23 +01:00 committed by GitHub
parent e52be0951a
commit 928ffd6650
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 413 additions and 30 deletions

View file

@ -124,7 +124,21 @@ pub struct SemanticModel<'a> {
/// Modules that have been seen by the semantic model.
pub seen: Modules,
/// Exceptions that have been handled by the current scope.
/// Exceptions that are handled by the current `try` block.
///
/// For example, if we're visiting the `x = 1` assignment below,
/// `AttributeError` is considered to be a "handled exception",
/// but `TypeError` is not:
///
/// ```py
/// try:
/// try:
/// foo()
/// except TypeError:
/// pass
/// except AttributeError:
/// pass
/// ```
pub handled_exceptions: Vec<Exceptions>,
/// Map from [`ast::ExprName`] node (represented as a [`NameId`]) to the [`Binding`] to which
@ -1193,6 +1207,14 @@ impl<'a> SemanticModel<'a> {
.expect("No statement found")
}
/// Returns an [`Iterator`] over the statements, starting from the given [`NodeId`].
/// through to any parents.
pub fn statements(&self, node_id: NodeId) -> impl Iterator<Item = &'a Stmt> + '_ {
self.nodes
.ancestor_ids(node_id)
.filter_map(move |id| self.nodes[id].as_statement())
}
/// Given a [`Stmt`], return its parent, if any.
#[inline]
pub fn parent_statement(&self, node_id: NodeId) -> Option<&'a Stmt> {