Remove RefEquality usages from Context (#4257)

This commit is contained in:
Charlie Marsh 2023-05-06 15:55:14 -04:00 committed by GitHub
parent b98b604071
commit 983bb31577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 18 deletions

View file

@ -1571,14 +1571,14 @@ where
test,
body,
orelse,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::IfWithSameArms) {
flake8_simplify::rules::if_with_same_arms(
self,
stmt,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::NeedlessBool) {
@ -1595,14 +1595,14 @@ where
test,
body,
orelse,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::IfElseBlockInsteadOfIfExp) {
flake8_simplify::rules::use_ternary_operator(
self,
stmt,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self
@ -1616,7 +1616,7 @@ where
test,
body,
orelse,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::TypeCheckWithoutTypeError) {
@ -1625,7 +1625,7 @@ where
body,
test,
orelse,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::OutdatedVersionBlock) {
@ -1683,7 +1683,7 @@ where
self,
stmt,
body,
self.ctx.current_stmt_parent().map(Into::into),
self.ctx.current_stmt_parent(),
);
}
if self.settings.rules.enabled(Rule::RedefinedLoopName) {
@ -2734,7 +2734,7 @@ where
flake8_comprehensions::rules::unnecessary_generator_set(
self,
expr,
self.ctx.current_expr_parent().map(Into::into),
self.ctx.current_expr_parent(),
func,
args,
keywords,
@ -2744,7 +2744,7 @@ where
flake8_comprehensions::rules::unnecessary_generator_dict(
self,
expr,
self.ctx.current_expr_parent().map(Into::into),
self.ctx.current_expr_parent(),
func,
args,
keywords,
@ -2849,7 +2849,7 @@ where
flake8_comprehensions::rules::unnecessary_map(
self,
expr,
self.ctx.current_expr_parent().map(Into::into),
self.ctx.current_expr_parent(),
func,
args,
);

View file

@ -6,7 +6,6 @@ use smallvec::smallvec;
use ruff_python_ast::call_path::{collect_call_path, from_unqualified_name, CallPath};
use ruff_python_ast::helpers::from_relative_import;
use ruff_python_ast::types::RefEquality;
use ruff_python_ast::typing::AnnotationKind;
use ruff_python_stdlib::path::is_python_stub_file;
use ruff_python_stdlib::typing::TYPING_EXTENSIONS;
@ -35,7 +34,7 @@ pub struct Context<'a> {
// Map from binding index to indexes of bindings that shadow it in other scopes.
pub shadowed_bindings:
std::collections::HashMap<BindingId, Vec<BindingId>, BuildNoHashHasher<BindingId>>,
pub exprs: Vec<RefEquality<'a, Expr>>,
pub exprs: Vec<&'a Expr>,
// Body iteration; used to peek at siblings.
pub body: &'a [Stmt],
pub body_index: usize,
@ -313,7 +312,7 @@ impl<'a> Context<'a> {
}
pub fn push_expr(&mut self, expr: &'a Expr) {
self.exprs.push(RefEquality(expr));
self.exprs.push(expr);
}
pub fn pop_expr(&mut self) {
@ -350,17 +349,17 @@ impl<'a> Context<'a> {
}
/// Return the parent `Expr` of the current `Expr`.
pub fn current_expr_parent(&self) -> Option<&RefEquality<'a, Expr>> {
self.exprs.iter().rev().nth(1)
pub fn current_expr_parent(&self) -> Option<&'a Expr> {
self.exprs.iter().rev().nth(1).copied()
}
/// Return the grandparent `Expr` of the current `Expr`.
pub fn current_expr_grandparent(&self) -> Option<&RefEquality<'a, Expr>> {
self.exprs.iter().rev().nth(2)
pub fn current_expr_grandparent(&self) -> Option<&'a Expr> {
self.exprs.iter().rev().nth(2).copied()
}
/// Return an [`Iterator`] over the current `Expr` parents.
pub fn expr_ancestors(&self) -> impl Iterator<Item = &RefEquality<'a, Expr>> {
pub fn expr_ancestors(&self) -> impl Iterator<Item = &&Expr> {
self.exprs.iter().rev().skip(1)
}