Skip to content

Commit

Permalink
Fix after return rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 8, 2023
1 parent 2f36ae7 commit 26a4a83
Show file tree
Hide file tree
Showing 54 changed files with 479 additions and 556 deletions.
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand Down Expand Up @@ -39,7 +40,12 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
}

impl NeedsParentheses for ExprAttribute {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_await.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -17,7 +18,12 @@ impl FormatNodeRule<ExprAwait> for FormatExprAwait {
}

impl NeedsParentheses for ExprAwait {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
11 changes: 8 additions & 3 deletions crates/ruff_python_formatter/src/expression/expr_bin_op.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::comments::trailing_comments;
use crate::comments::{trailing_comments, Comments};
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parenthesize,
};
Expand Down Expand Up @@ -171,8 +171,13 @@ impl FormatRule<Operator, PyFormatContext<'_>> for FormatOperator {
}

impl NeedsParentheses for ExprBinOp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => {
if should_binary_break_right_side_first(self) {
Parentheses::Custom
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_bool_op.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -20,7 +21,12 @@ impl FormatNodeRule<ExprBoolOp> for FormatExprBoolOp {
}

impl NeedsParentheses for ExprBoolOp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_call.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -18,8 +19,13 @@ impl FormatNodeRule<ExprCall> for FormatExprCall {
}

impl NeedsParentheses for ExprCall {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::expression::parentheses::{
};
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};

use crate::comments::Comments;
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::ExprCompare;

Expand All @@ -21,7 +22,12 @@ impl FormatNodeRule<ExprCompare> for FormatExprCompare {
}

impl NeedsParentheses for ExprCompare {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_constant.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand Down Expand Up @@ -41,8 +42,13 @@ impl FormatNodeRule<ExprConstant> for FormatExprConstant {
}

impl NeedsParentheses for ExprConstant {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_dict.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -20,8 +21,13 @@ impl FormatNodeRule<ExprDict> for FormatExprDict {
}

impl NeedsParentheses for ExprDict {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_dict_comp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -20,8 +21,13 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
}

impl NeedsParentheses for ExprDictComp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,7 +16,12 @@ impl FormatNodeRule<ExprFormattedValue> for FormatExprFormattedValue {
}

impl NeedsParentheses for ExprFormattedValue {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,8 +16,13 @@ impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
}

impl NeedsParentheses for ExprGeneratorExp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_if_exp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -20,7 +21,12 @@ impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
}

impl NeedsParentheses for ExprIfExp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_joined_str.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,7 +16,12 @@ impl FormatNodeRule<ExprJoinedStr> for FormatExprJoinedStr {
}

impl NeedsParentheses for ExprJoinedStr {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_lambda.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,7 +16,12 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
}

impl NeedsParentheses for ExprLambda {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
11 changes: 8 additions & 3 deletions crates/ruff_python_formatter/src/expression/expr_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::comments::dangling_comments;
use crate::comments::{dangling_comments, Comments};
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand Down Expand Up @@ -57,8 +57,13 @@ impl FormatNodeRule<ExprList> for FormatExprList {
}

impl NeedsParentheses for ExprList {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_list_comp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,8 +16,13 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
}

impl NeedsParentheses for ExprListComp {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand Down Expand Up @@ -26,8 +27,13 @@ impl FormatNodeRule<ExprName> for FormatExprName {
}

impl NeedsParentheses for ExprName {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}

Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_named_expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand All @@ -15,7 +16,12 @@ impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
}

impl NeedsParentheses for ExprNamedExpr {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source)
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
}
}
10 changes: 8 additions & 2 deletions crates/ruff_python_formatter/src/expression/expr_set.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::comments::Comments;
use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
};
Expand Down Expand Up @@ -34,8 +35,13 @@ impl FormatNodeRule<ExprSet> for FormatExprSet {
}

impl NeedsParentheses for ExprSet {
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
fn needs_parentheses(
&self,
parenthesize: Parenthesize,
source: &str,
comments: &Comments,
) -> Parentheses {
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
Parentheses::Optional => Parentheses::Never,
parentheses => parentheses,
}
Expand Down
Loading

0 comments on commit 26a4a83

Please sign in to comment.