Treat class C: ... and class C(): ... equivalently (#8659)

## Summary

These should be seen as identical from the `ComparableAst` perspective.
This commit is contained in:
Charlie Marsh 2023-11-13 10:03:04 -08:00 committed by GitHub
parent a8e0d4ab4f
commit 345e1401cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 30 deletions

View file

@ -32,33 +32,20 @@ impl Normalizer {
impl Transformer for Normalizer {
fn visit_stmt(&self, stmt: &mut Stmt) {
match stmt {
Stmt::ClassDef(class_def) => {
// Treat `class C: ...` and `class C(): ...` equivalently.
if class_def
.arguments
.as_ref()
.is_some_and(|arguments| arguments.is_empty())
{
class_def.arguments = None;
}
}
Stmt::Delete(delete) => {
// Treat `del a, b` and `del (a, b)` equivalently.
delete.targets = delete
.targets
.clone()
.into_iter()
.flat_map(|target| {
if let Expr::Tuple(tuple) = target {
Left(tuple.elts.into_iter())
} else {
Right(std::iter::once(target))
}
})
.collect();
}
_ => {}
if let Stmt::Delete(delete) = stmt {
// Treat `del a, b` and `del (a, b)` equivalently.
delete.targets = delete
.targets
.clone()
.into_iter()
.flat_map(|target| {
if let Expr::Tuple(tuple) = target {
Left(tuple.elts.into_iter())
} else {
Right(std::iter::once(target))
}
})
.collect();
}
transformer::walk_stmt(self, stmt);