mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-12 21:36:47 +00:00
Remove Stmt::TryStar
(#6566)
## Summary Instead, we set an `is_star` flag on `Stmt::Try`. This is similar to the pattern we've migrated towards for `Stmt::For` (removing `Stmt::AsyncFor`) and friends. While these are significant differences for an interpreter, we tend to handle these cases identically or nearly identically. ## Test Plan `cargo test`
This commit is contained in:
parent
09c8b17661
commit
96d310fbab
33 changed files with 70 additions and 489 deletions
|
@ -73,8 +73,6 @@ pub enum Stmt {
|
|||
Raise(StmtRaise),
|
||||
#[is(name = "try_stmt")]
|
||||
Try(StmtTry),
|
||||
#[is(name = "try_star_stmt")]
|
||||
TryStar(StmtTryStar),
|
||||
#[is(name = "assert_stmt")]
|
||||
Assert(StmtAssert),
|
||||
#[is(name = "import_stmt")]
|
||||
|
@ -362,7 +360,8 @@ impl From<StmtRaise> for Stmt {
|
|||
}
|
||||
}
|
||||
|
||||
/// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try)
|
||||
/// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try) and
|
||||
/// [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtTry {
|
||||
pub range: TextRange,
|
||||
|
@ -370,6 +369,7 @@ pub struct StmtTry {
|
|||
pub handlers: Vec<ExceptHandler>,
|
||||
pub orelse: Vec<Stmt>,
|
||||
pub finalbody: Vec<Stmt>,
|
||||
pub is_star: bool,
|
||||
}
|
||||
|
||||
impl From<StmtTry> for Stmt {
|
||||
|
@ -378,22 +378,6 @@ impl From<StmtTry> for Stmt {
|
|||
}
|
||||
}
|
||||
|
||||
/// See also [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtTryStar {
|
||||
pub range: TextRange,
|
||||
pub body: Vec<Stmt>,
|
||||
pub handlers: Vec<ExceptHandler>,
|
||||
pub orelse: Vec<Stmt>,
|
||||
pub finalbody: Vec<Stmt>,
|
||||
}
|
||||
|
||||
impl From<StmtTryStar> for Stmt {
|
||||
fn from(payload: StmtTryStar) -> Self {
|
||||
Stmt::TryStar(payload)
|
||||
}
|
||||
}
|
||||
|
||||
/// See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct StmtAssert {
|
||||
|
@ -2666,11 +2650,6 @@ impl Ranged for crate::nodes::StmtTry {
|
|||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::nodes::StmtTryStar {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
}
|
||||
}
|
||||
impl Ranged for crate::nodes::StmtAssert {
|
||||
fn range(&self) -> TextRange {
|
||||
self.range
|
||||
|
@ -2739,7 +2718,6 @@ impl Ranged for crate::Stmt {
|
|||
Self::Match(node) => node.range(),
|
||||
Self::Raise(node) => node.range(),
|
||||
Self::Try(node) => node.range(),
|
||||
Self::TryStar(node) => node.range(),
|
||||
Self::Assert(node) => node.range(),
|
||||
Self::Import(node) => node.range(),
|
||||
Self::ImportFrom(node) => node.range(),
|
||||
|
@ -3086,7 +3064,7 @@ mod size_assertions {
|
|||
assert_eq_size!(Stmt, [u8; 144]);
|
||||
assert_eq_size!(StmtFunctionDef, [u8; 144]);
|
||||
assert_eq_size!(StmtClassDef, [u8; 104]);
|
||||
assert_eq_size!(StmtTry, [u8; 104]);
|
||||
assert_eq_size!(StmtTry, [u8; 112]);
|
||||
assert_eq_size!(Expr, [u8; 80]);
|
||||
assert_eq_size!(Constant, [u8; 40]);
|
||||
assert_eq_size!(Pattern, [u8; 96]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue