upgrade rustpython to remove tuple-constants (#5840)

c.f. https://github.com/astral-sh/RustPython-Parser/pull/28

Tests: No snapshots changed

---------

Co-authored-by: Zanie <contact@zanie.dev>
This commit is contained in:
David Szotten 2023-07-17 23:50:31 +01:00 committed by GitHub
parent e574a6a769
commit 52aa2fc875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 131 additions and 206 deletions

View file

@ -329,7 +329,6 @@ impl<'a> From<&'a ast::Constant> for ComparableConstant<'a> {
ast::Constant::Str(value) => Self::Str(value),
ast::Constant::Bytes(value) => Self::Bytes(value),
ast::Constant::Int(value) => Self::Int(value),
ast::Constant::Tuple(value) => Self::Tuple(value.iter().map(Into::into).collect()),
ast::Constant::Float(value) => Self::Float(value.to_bits()),
ast::Constant::Complex { real, imag } => Self::Complex {
real: real.to_bits(),

View file

@ -1392,7 +1392,6 @@ impl Truthiness {
Constant::Float(float) => Some(*float != 0.0),
Constant::Complex { real, imag } => Some(*real != 0.0 || *imag != 0.0),
Constant::Ellipsis => Some(true),
Constant::Tuple(elts) => Some(!elts.is_empty()),
},
Expr::JoinedStr(ast::ExprJoinedStr {
values,

View file

@ -1249,23 +1249,6 @@ impl<'a> Generator<'a> {
Constant::None => self.p("None"),
Constant::Bool(b) => self.p(if *b { "True" } else { "False" }),
Constant::Int(i) => self.p(&format!("{i}")),
Constant::Tuple(tup) => {
if let [elt] = &**tup {
self.p("(");
self.unparse_constant(elt);
self.p(",");
self.p(")");
} else {
self.p("(");
for (i, elt) in tup.iter().enumerate() {
if i != 0 {
self.p(", ");
}
self.unparse_constant(elt);
}
self.p(")");
}
}
Constant::Float(fp) => {
if fp.is_infinite() {
self.p(inf_str);

View file

@ -3,8 +3,8 @@
pub mod preorder;
use rustpython_parser::ast::{
self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, Decorator, ExceptHandler,
Expr, ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Decorator, ExceptHandler, Expr,
ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
};
/// A trait for AST visitors. Visits all nodes in the AST recursively in evaluation-order.
@ -27,9 +27,6 @@ pub trait Visitor<'a> {
fn visit_expr(&mut self, expr: &'a Expr) {
walk_expr(self, expr);
}
fn visit_constant(&mut self, constant: &'a Constant) {
walk_constant(self, constant);
}
fn visit_expr_context(&mut self, expr_context: &'a ExprContext) {
walk_expr_context(self, expr_context);
}
@ -507,7 +504,7 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
visitor.visit_expr(expr);
}
}
Expr::Constant(ast::ExprConstant { value, .. }) => visitor.visit_constant(value),
Expr::Constant(_) => {}
Expr::Attribute(ast::ExprAttribute { value, ctx, .. }) => {
visitor.visit_expr(value);
visitor.visit_expr_context(ctx);
@ -572,14 +569,6 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) {
}
}
pub fn walk_constant<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, constant: &'a Constant) {
if let Constant::Tuple(constants) = constant {
for constant in constants {
visitor.visit_constant(constant);
}
}
}
pub fn walk_comprehension<'a, V: Visitor<'a> + ?Sized>(
visitor: &mut V,
comprehension: &'a Comprehension,
@ -675,12 +664,7 @@ pub fn walk_pattern<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, pattern: &'a P
value,
range: _range,
}) => visitor.visit_expr(value),
Pattern::MatchSingleton(ast::PatternMatchSingleton {
value,
range: _range,
}) => {
visitor.visit_constant(value);
}
Pattern::MatchSingleton(_) => {}
Pattern::MatchSequence(ast::PatternMatchSequence {
patterns,
range: _range,

View file

@ -26,9 +26,7 @@ pub trait PreorderVisitor<'a> {
walk_decorator(self, decorator);
}
fn visit_constant(&mut self, constant: &'a Constant) {
walk_constant(self, constant);
}
fn visit_constant(&mut self, _constant: &'a Constant) {}
fn visit_bool_op(&mut self, bool_op: &'a BoolOp) {
walk_bool_op(self, bool_op);
@ -693,17 +691,6 @@ where
}
}
pub fn walk_constant<'a, V>(visitor: &mut V, constant: &'a Constant)
where
V: PreorderVisitor<'a> + ?Sized,
{
if let Constant::Tuple(constants) = constant {
for constant in constants {
visitor.visit_constant(constant);
}
}
}
pub fn walk_comprehension<'a, V>(visitor: &mut V, comprehension: &'a Comprehension)
where
V: PreorderVisitor<'a> + ?Sized,