mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
Ignore NPY201
inside except
blocks for compatibility with older numpy versions (#12490)
This commit is contained in:
parent
e52be0951a
commit
928ffd6650
8 changed files with 413 additions and 30 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue