Format Compare Op

<!--
Thank you for contributing to Ruff! To help us out with reviewing, please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

This PR adds basic formatting for compare operations.

The implementation currently breaks diffeently when nesting binary like expressions. I haven't yet figured out what Black's logic is in that case but I think that this by itself is already an improvement worth merging.

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

I added a few new tests 

<!-- How was it tested? -->
This commit is contained in:
Micha Reiser 2023-06-23 09:35:29 +02:00 committed by GitHub
parent 2142bf6141
commit 3e12bdff45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 735 additions and 244 deletions

View file

@ -0,0 +1,61 @@
a == b
a != b
a < b
a <= b
a > b
a >= b
a is b
a is not b
a in b
a not in b
(a ==
# comment
b
)
(a == # comment
b
)
a < b > c == d
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ccccccccccccccccccccccccccccc == ddddddddddddddddddddd
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
ff,
] < [ccccccccccccccccccccccccccccc, dddd] < ddddddddddddddddddddddddddddddddddddddddddd
return 1 == 2 and (
name,
description,
self_default,
self_selected,
self_auto_generated,
self_parameters,
self_meta_data,
self_schedule,
) == (
name,
description,
othr_default,
othr_selected,
othr_auto_generated,
othr_parameters,
othr_meta_data,
othr_schedule,
)
(name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule)
((name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule))
[
(
a
+ [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
]
>= c
)
]

View file

@ -1,23 +1,96 @@
use crate::comments::{leading_comments, Comments};
use crate::expression::binary_like::{BinaryLayout, FormatBinaryLike};
use crate::expression::parentheses::{ use crate::expression::parentheses::{
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize, default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
}; };
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; use crate::prelude::*;
use crate::FormatNodeRule;
use crate::comments::Comments; use ruff_formatter::{
use ruff_formatter::{write, Buffer, FormatResult}; write, FormatError, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
use rustpython_parser::ast::ExprCompare; };
use ruff_python_ast::prelude::Expr;
use rustpython_parser::ast::{CmpOp, ExprCompare};
#[derive(Default)] #[derive(Default)]
pub struct FormatExprCompare; pub struct FormatExprCompare {
parentheses: Option<Parentheses>,
}
impl FormatRuleWithOptions<ExprCompare, PyFormatContext<'_>> for FormatExprCompare {
type Options = Option<Parentheses>;
fn with_options(mut self, options: Self::Options) -> Self {
self.parentheses = options;
self
}
}
impl FormatNodeRule<ExprCompare> for FormatExprCompare { impl FormatNodeRule<ExprCompare> for FormatExprCompare {
fn fmt_fields(&self, _item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> {
item.fmt_binary(self.parentheses, f)
}
}
impl<'ast> FormatBinaryLike<'ast> for ExprCompare {
type FormatOperator = FormatOwnedWithRule<CmpOp, FormatCmpOp, PyFormatContext<'ast>>;
fn binary_layout(&self) -> BinaryLayout {
if self.ops.len() == 1 {
match self.comparators.as_slice() {
[right] => BinaryLayout::from_left_right(&self.left, right),
[..] => BinaryLayout::Default,
}
} else {
BinaryLayout::Default
}
}
fn fmt_default(&self, f: &mut PyFormatter<'ast, '_>) -> FormatResult<()> {
let ExprCompare {
range: _,
left,
ops,
comparators,
} = self;
let comments = f.context().comments().clone();
write!(f, [group(&left.format())])?;
assert_eq!(comparators.len(), ops.len());
for (operator, comparator) in ops.iter().zip(comparators) {
let leading_comparator_comments = comments.leading_comments(comparator);
if leading_comparator_comments.is_empty() {
write!(f, [soft_line_break_or_space()])?;
} else {
// Format the expressions leading comments **before** the operator
write!( write!(
f, f,
[not_yet_implemented_custom_text( [
"NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right" hard_line_break(),
)] leading_comments(leading_comparator_comments)
) ]
)?;
}
write!(f, [operator.format(), space(), group(&comparator.format())])?;
}
Ok(())
}
fn left(&self) -> FormatResult<&Expr> {
Ok(self.left.as_ref())
}
fn right(&self) -> FormatResult<&Expr> {
self.comparators.last().ok_or(FormatError::SyntaxError)
}
fn operator(&self) -> Self::FormatOperator {
let op = *self.ops.first().unwrap();
op.into_format()
} }
} }
@ -28,6 +101,61 @@ impl NeedsParentheses for ExprCompare {
source: &str, source: &str,
comments: &Comments, comments: &Comments,
) -> Parentheses { ) -> Parentheses {
default_expression_needs_parentheses(self.into(), parenthesize, source, comments) match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
parentheses @ Parentheses::Optional => match self.binary_layout() {
BinaryLayout::Default => parentheses,
BinaryLayout::ExpandRight
| BinaryLayout::ExpandLeft
| BinaryLayout::ExpandRightThenLeft
if self
.comparators
.last()
.map_or(false, |right| comments.has_leading_comments(right)) =>
{
parentheses
}
_ => Parentheses::Custom,
},
parentheses => parentheses,
}
}
}
#[derive(Copy, Clone)]
pub struct FormatCmpOp;
impl<'ast> AsFormat<PyFormatContext<'ast>> for CmpOp {
type Format<'a> = FormatRefWithRule<'a, CmpOp, FormatCmpOp, PyFormatContext<'ast>>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(self, FormatCmpOp)
}
}
impl<'ast> IntoFormat<PyFormatContext<'ast>> for CmpOp {
type Format = FormatOwnedWithRule<CmpOp, FormatCmpOp, PyFormatContext<'ast>>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(self, FormatCmpOp)
}
}
impl FormatRule<CmpOp, PyFormatContext<'_>> for FormatCmpOp {
fn fmt(&self, item: &CmpOp, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
let operator = match item {
CmpOp::Eq => "==",
CmpOp::NotEq => "!=",
CmpOp::Lt => "<",
CmpOp::LtE => "<=",
CmpOp::Gt => ">",
CmpOp::GtE => ">=",
CmpOp::Is => "is",
CmpOp::IsNot => "is not",
CmpOp::In => "in",
CmpOp::NotIn => "not in",
};
text(operator).fmt(f)
} }
} }

View file

@ -76,7 +76,7 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
Expr::Await(expr) => expr.format().fmt(f), Expr::Await(expr) => expr.format().fmt(f),
Expr::Yield(expr) => expr.format().fmt(f), Expr::Yield(expr) => expr.format().fmt(f),
Expr::YieldFrom(expr) => expr.format().fmt(f), Expr::YieldFrom(expr) => expr.format().fmt(f),
Expr::Compare(expr) => expr.format().fmt(f), Expr::Compare(expr) => expr.format().with_options(Some(parentheses)).fmt(f),
Expr::Call(expr) => expr.format().fmt(f), Expr::Call(expr) => expr.format().fmt(f),
Expr::FormattedValue(expr) => expr.format().fmt(f), Expr::FormattedValue(expr) => expr.format().fmt(f),
Expr::JoinedStr(expr) => expr.format().fmt(f), Expr::JoinedStr(expr) => expr.format().fmt(f),

View file

@ -19,11 +19,9 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,4 +1,6 @@ @@ -1,4 +1,4 @@
-for ((x in {}) or {})["a"] in x: -for ((x in {}) or {})["a"] in x:
+for ((NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right) or {})[ +for ((x in {}) or {})["NOT_YET_IMPLEMENTED_STRING"] in x:
+ "NOT_YET_IMPLEMENTED_STRING"
+] in x:
pass pass
-pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip()) -pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
-lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x -lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
@ -34,9 +32,7 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
## Ruff Output ## Ruff Output
```py ```py
for ((NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right) or {})[ for ((x in {}) or {})["NOT_YET_IMPLEMENTED_STRING"] in x:
"NOT_YET_IMPLEMENTED_STRING"
] in x:
pass pass
pem_spam = lambda x: True pem_spam = lambda x: True
lambda x: True lambda x: True

View file

@ -249,7 +249,7 @@ instruction()#comment with bad spacing
-if "PYTHON" in os.environ: -if "PYTHON" in os.environ:
- add_compiler(compiler_from_env()) - add_compiler(compiler_from_env())
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if "NOT_YET_IMPLEMENTED_STRING" in os.environ:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else: else:
# for compiler in compilers.values(): # for compiler in compilers.values():
@ -283,15 +283,13 @@ instruction()#comment with bad spacing
+ parameters.children[-1], + parameters.children[-1],
+ ] # type: ignore + ] # type: ignore
if ( if (
- self._proc is not None self._proc is not None
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
# has the child process finished? # has the child process finished?
- and self._returncode is None and self._returncode is None
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
# the child process has finished, but the # the child process has finished, but the
# transport hasn't been notified yet? # transport hasn't been notified yet?
- and self._proc.poll() is None - and self._proc.poll() is None
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + and NOT_IMPLEMENTED_call() is None
): ):
pass pass
# no newline before or after # no newline before or after
@ -349,7 +347,7 @@ instruction()#comment with bad spacing
while True: while True:
if False: if False:
continue continue
@@ -141,24 +111,18 @@ @@ -141,24 +111,19 @@
# and round and round we go # and round and round we go
# let's return # let's return
@ -374,13 +372,14 @@ instruction()#comment with bad spacing
def _init_host(self, parsed) -> None: def _init_host(self, parsed) -> None:
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore - if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
+ if ( + if (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # type: ignore + parsed.hostname
+ is None # type: ignore
+ or not NOT_IMPLEMENTED_call() + or not NOT_IMPLEMENTED_call()
+ ): + ):
pass pass
@@ -167,7 +131,7 @@ @@ -167,7 +132,7 @@
####################### #######################
@ -440,7 +439,7 @@ not_shareables = [
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
] ]
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if "NOT_YET_IMPLEMENTED_STRING" in os.environ:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else: else:
# for compiler in compilers.values(): # for compiler in compilers.values():
@ -474,12 +473,12 @@ def inline_comments_in_brackets_ruin_everything():
parameters.children[-1], parameters.children[-1],
] # type: ignore ] # type: ignore
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right self._proc is not None
# has the child process finished? # has the child process finished?
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and self._returncode is None
# the child process has finished, but the # the child process has finished, but the
# transport hasn't been notified yet? # transport hasn't been notified yet?
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and NOT_IMPLEMENTED_call() is None
): ):
pass pass
# no newline before or after # no newline before or after
@ -516,7 +515,8 @@ CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type:
class Test: class Test:
def _init_host(self, parsed) -> None: def _init_host(self, parsed) -> None:
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # type: ignore parsed.hostname
is None # type: ignore
or not NOT_IMPLEMENTED_call() or not NOT_IMPLEMENTED_call()
): ):
pass pass

View file

@ -83,7 +83,7 @@ def func():
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
embedded = [] embedded = []
for exc in exc_value.exceptions: for exc in exc_value.exceptions:
- if exc not in _seen: if exc not in _seen:
- embedded.append( - embedded.append(
- # This should be left alone (before) - # This should be left alone (before)
- traceback.TracebackException.from_exception( - traceback.TracebackException.from_exception(
@ -97,7 +97,6 @@ def func():
- ) - )
- # This should be left alone (after) - # This should be left alone (after)
- ) - )
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# everything is fine if the expression isn't nested # everything is fine if the expression isn't nested
@ -130,7 +129,7 @@ def func():
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
embedded = [] embedded = []
for exc in exc_value.exceptions: for exc in exc_value.exceptions:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if exc not in _seen:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# everything is fine if the expression isn't nested # everything is fine if the expression isn't nested

View file

@ -101,8 +101,7 @@ if __name__ == "__main__":
-for i in range(100): -for i in range(100):
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): +for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
# first we do this # first we do this
- if i % 33 == 0: if i % 33 == 0:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
break break
# then we do this # then we do this
@ -117,11 +116,11 @@ if __name__ == "__main__":
-try: -try:
- with open(some_other_file) as w: - with open(some_other_file) as w:
- w.write(data) - w.write(data)
-
-except OSError:
- print("problems")
+NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtTry
-except OSError:
- print("problems")
-
-import sys -import sys
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
@ -151,7 +150,7 @@ if __name__ == "__main__":
-if __name__ == "__main__": -if __name__ == "__main__":
- main() - main()
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if __name__ == "NOT_YET_IMPLEMENTED_STRING":
+ NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call()
``` ```
@ -170,7 +169,7 @@ while True:
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
# first we do this # first we do this
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if i % 33 == 0:
break break
# then we do this # then we do this
@ -223,7 +222,7 @@ def g():
... ...
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if __name__ == "NOT_YET_IMPLEMENTED_STRING":
NOT_IMPLEMENTED_call() NOT_IMPLEMENTED_call()
``` ```

View file

@ -105,7 +105,7 @@ def g():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,59 +1,46 @@ @@ -1,11 +1,11 @@
-"""Docstring.""" -"""Docstring."""
+"NOT_YET_IMPLEMENTED_STRING" +"NOT_YET_IMPLEMENTED_STRING"
@ -121,13 +121,8 @@ def g():
t = leaf.type t = leaf.type
p = leaf.parent # trailing comment p = leaf.parent # trailing comment
v = leaf.value @@ -16,44 +16,51 @@
if t == token.COMMENT: # another trailing comment
- if t in ALWAYS_NO_SPACE:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
pass
- if t == token.COMMENT: # another trailing comment
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: # another trailing comment
return DOUBLESPACE return DOUBLESPACE
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}" - assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
@ -136,12 +131,11 @@ def g():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
- prevp = preceding_leaf(p) - prevp = preceding_leaf(p)
- if not prevp or prevp.type in OPENING_BRACKETS:
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
- if prevp.type == token.EQUAL: if prevp.type == token.EQUAL:
- if prevp.parent and prevp.parent.type in { - if prevp.parent and prevp.parent.type in {
- syms.typedargslist, - syms.typedargslist,
- syms.varargslist, - syms.varargslist,
@ -149,11 +143,20 @@ def g():
- syms.arglist, - syms.arglist,
- syms.argument, - syms.argument,
- }: - }:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + if (
+ if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + prevp.parent
+ and prevp.parent.type
+ in {
+ syms.typedargslist,
+ syms.varargslist,
+ syms.parameters,
+ syms.arglist,
+ syms.argument,
+ }
+ ):
return NO return NO
- elif prevp.type == token.DOUBLESTAR: elif prevp.type == token.DOUBLESTAR:
- if prevp.parent and prevp.parent.type in { - if prevp.parent and prevp.parent.type in {
- syms.typedargslist, - syms.typedargslist,
- syms.varargslist, - syms.varargslist,
@ -161,8 +164,17 @@ def g():
- syms.arglist, - syms.arglist,
- syms.dictsetmaker, - syms.dictsetmaker,
- }: - }:
+ elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + if (
+ if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + prevp.parent
+ and prevp.parent.type
+ in {
+ syms.typedargslist,
+ syms.varargslist,
+ syms.parameters,
+ syms.arglist,
+ syms.dictsetmaker,
+ }
+ ):
return NO return NO
@ -181,15 +193,7 @@ def g():
t = leaf.type t = leaf.type
p = leaf.parent p = leaf.parent
@@ -61,29 +48,23 @@ @@ -67,11 +74,11 @@
# Comment because comments
- if t in ALWAYS_NO_SPACE:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
pass
- if t == token.COMMENT:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
return DOUBLESPACE return DOUBLESPACE
# Another comment because more comments # Another comment because more comments
@ -201,13 +205,12 @@ def g():
- prevp = preceding_leaf(p) - prevp = preceding_leaf(p)
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
- if not prevp or prevp.type in OPENING_BRACKETS: if not prevp or prevp.type in OPENING_BRACKETS:
+ if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
# Start of the line or a bracketed expression. # Start of the line or a bracketed expression.
# More than one line for the comment. @@ -79,11 +86,15 @@
return NO return NO
- if prevp.type == token.EQUAL: if prevp.type == token.EQUAL:
- if prevp.parent and prevp.parent.type in { - if prevp.parent and prevp.parent.type in {
- syms.typedargslist, - syms.typedargslist,
- syms.varargslist, - syms.varargslist,
@ -215,8 +218,17 @@ def g():
- syms.arglist, - syms.arglist,
- syms.argument, - syms.argument,
- }: - }:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + if (
+ if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + prevp.parent
+ and prevp.parent.type
+ in {
+ syms.typedargslist,
+ syms.varargslist,
+ syms.parameters,
+ syms.arglist,
+ syms.argument,
+ }
+ ):
return NO return NO
``` ```
@ -236,9 +248,9 @@ def f():
p = leaf.parent # trailing comment p = leaf.parent # trailing comment
v = leaf.value v = leaf.value
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if t in ALWAYS_NO_SPACE:
pass pass
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: # another trailing comment if t == token.COMMENT: # another trailing comment
return DOUBLESPACE return DOUBLESPACE
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
@ -246,15 +258,35 @@ def f():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if prevp.type == token.EQUAL:
if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if (
prevp.parent
and prevp.parent.type
in {
syms.typedargslist,
syms.varargslist,
syms.parameters,
syms.arglist,
syms.argument,
}
):
return NO return NO
elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: elif prevp.type == token.DOUBLESTAR:
if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if (
prevp.parent
and prevp.parent.type
in {
syms.typedargslist,
syms.varargslist,
syms.parameters,
syms.arglist,
syms.dictsetmaker,
}
):
return NO return NO
@ -273,9 +305,9 @@ def g():
# Comment because comments # Comment because comments
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if t in ALWAYS_NO_SPACE:
pass pass
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if t == token.COMMENT:
return DOUBLESPACE return DOUBLESPACE
# Another comment because more comments # Another comment because more comments
@ -285,13 +317,23 @@ def g():
if not prev: if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if not prevp or prevp.type in OPENING_BRACKETS:
# Start of the line or a bracketed expression. # Start of the line or a bracketed expression.
# More than one line for the comment. # More than one line for the comment.
return NO return NO
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if prevp.type == token.EQUAL:
if prevp.parent and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if (
prevp.parent
and prevp.parent.type
in {
syms.typedargslist,
syms.varargslist,
syms.parameters,
syms.arglist,
syms.argument,
}
):
return NO return NO
``` ```

View file

@ -281,7 +281,8 @@ last_call()
~int and not v1 ^ 123 + v2 | True ~int and not v1 ^ 123 + v2 | True
(~int) and (not ((v1 ^ (123 + v2)) | True)) (~int) and (not ((v1 ^ (123 + v2)) | True))
-+(really ** -(confusing ** ~(operator**-precedence))) -+(really ** -(confusing ** ~(operator**-precedence)))
-flags & ~select.EPOLLIN and waiters.write_task is not None ++really ** -confusing ** ~operator**-precedence
flags & ~select.EPOLLIN and waiters.write_task is not None
-lambda arg: None -lambda arg: None
-lambda a=True: a -lambda a=True: a
-lambda a, b, c=True: a -lambda a, b, c=True: a
@ -304,8 +305,6 @@ last_call()
-) -)
-{"2.7": dead, "3.7": (long_live or die_hard)} -{"2.7": dead, "3.7": (long_live or die_hard)}
-{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}} -{"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
++really ** -confusing ** ~operator**-precedence
+flags & ~select.EPOLLIN and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+lambda x: True +lambda x: True
+lambda x: True +lambda x: True
+lambda x: True +lambda x: True
@ -364,17 +363,17 @@ last_call()
- 4, - 4,
- 5, - 5,
-] -]
-[
- 4,
- *a,
- 5,
-]
+[1, 2, 3] +[1, 2, 3]
+[NOT_YET_IMPLEMENTED_ExprStarred] +[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred] +[NOT_YET_IMPLEMENTED_ExprStarred]
+[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5] +[NOT_YET_IMPLEMENTED_ExprStarred, 4, 5]
+[4, NOT_YET_IMPLEMENTED_ExprStarred, 5] +[4, NOT_YET_IMPLEMENTED_ExprStarred, 5]
[ [
- 4,
- *a,
- 5,
-]
-[
this_is_a_very_long_variable_which_will_force_a_delimiter_split, this_is_a_very_long_variable_which_will_force_a_delimiter_split,
element, element,
another, another,
@ -397,8 +396,21 @@ last_call()
- k: v - k: v
- for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension - for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
-} -}
-Python3 > Python2 > COBOL +NOT_YET_IMPLEMENTED_ExprSetComp
-Life is Life +NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+[i for i in []]
+[i for i in []]
+[i for i in []]
+[i for i in []]
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
Python3 > Python2 > COBOL
Life is Life
-call() -call()
-call(arg) -call(arg)
-call(kwarg="hey") -call(kwarg="hey")
@ -415,21 +427,6 @@ last_call()
-call(a, *gidgets[:2]) -call(a, *gidgets[:2])
-call(**self.screen_kwargs) -call(**self.screen_kwargs)
-call(b, **self.screen_kwargs) -call(b, **self.screen_kwargs)
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+NOT_YET_IMPLEMENTED_ExprSetComp
+[i for i in []]
+[i for i in []]
+[i for i in []]
+[i for i in []]
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+NOT_IMPLEMENTED_call() +NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@ -556,19 +553,10 @@ last_call()
-g = 1, *"ten" -g = 1, *"ten"
-what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set( -what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
- vars_to_remove - vars_to_remove
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) -)
+f = 1, NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = (
+ (coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
)
-what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set( -what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
- vars_to_remove - vars_to_remove
+what_is_up_with_those_new_coord_names = ( -)
+ (coord_names | NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ - NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
)
-result = ( -result = (
- session.query(models.Customer.id) - session.query(models.Customer.id)
- .filter( - .filter(
@ -576,7 +564,13 @@ last_call()
- ) - )
- .order_by(models.Customer.id.asc()) - .order_by(models.Customer.id.asc())
- .all() - .all()
-) +e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+f = 1, NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = (
+ (coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
)
-result = ( -result = (
- session.query(models.Customer.id) - session.query(models.Customer.id)
- .filter( - .filter(
@ -586,7 +580,10 @@ last_call()
- models.Customer.id.asc(), - models.Customer.id.asc(),
- ) - )
- .all() - .all()
-) +what_is_up_with_those_new_coord_names = (
+ (coord_names | NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ - NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
)
-Ø = set() -Ø = set()
-authors.łukasz.say_thanks() -authors.łukasz.say_thanks()
+result = NOT_IMPLEMENTED_call() +result = NOT_IMPLEMENTED_call()
@ -641,44 +638,29 @@ last_call()
... ...
for j in 1 + (2 + 3): for j in 1 + (2 + 3):
... ...
@@ -272,28 +254,16 @@ @@ -272,7 +254,7 @@
addr_proto, addr_proto,
addr_canonname, addr_canonname,
addr_sockaddr, addr_sockaddr,
-) in socket.getaddrinfo("google.com", "http"): -) in socket.getaddrinfo("google.com", "http"):
+) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): +) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
pass pass
-a = ( a = (
- aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
- in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz @@ -291,9 +273,9 @@
-) is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
-a = ( )
- aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
- not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
-)
-a = (
- aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
- is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
-)
-a = (
- aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
- is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
-)
+a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
if ( if (
- threading.current_thread() != threading.main_thread() - threading.current_thread() != threading.main_thread()
- and threading.current_thread() != threading.main_thread() - and threading.current_thread() != threading.main_thread()
- or signal.getsignal(signal.SIGINT) != signal.default_int_handler - or signal.getsignal(signal.SIGINT) != signal.default_int_handler
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + and NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
+ or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) != signal.default_int_handler
): ):
return True return True
if ( if (
@@ -327,13 +297,18 @@ @@ -327,13 +309,18 @@
): ):
return True return True
if ( if (
@ -700,7 +682,7 @@ last_call()
^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
): ):
return True return True
@@ -341,7 +316,8 @@ @@ -341,7 +328,8 @@
~aaaaaaaaaaaaaaaa.a ~aaaaaaaaaaaaaaaa.a
+ aaaaaaaaaaaaaaaa.b + aaaaaaaaaaaaaaaa.b
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
@ -710,7 +692,7 @@ last_call()
^ aaaaaaaaaaaaaaaa.i ^ aaaaaaaaaaaaaaaa.i
<< aaaaaaaaaaaaaaaa.k << aaaaaaaaaaaaaaaa.k
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
@@ -366,5 +342,5 @@ @@ -366,5 +354,5 @@
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) )
@ -756,7 +738,7 @@ not great
~int and not v1 ^ 123 + v2 | True ~int and not v1 ^ 123 + v2 | True
(~int) and (not ((v1 ^ (123 + v2)) | True)) (~int) and (not ((v1 ^ (123 + v2)) | True))
+really ** -confusing ** ~operator**-precedence +really ** -confusing ** ~operator**-precedence
flags & ~select.EPOLLIN and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right flags & ~select.EPOLLIN and waiters.write_task is not None
lambda x: True lambda x: True
lambda x: True lambda x: True
lambda x: True lambda x: True
@ -825,8 +807,8 @@ NOT_YET_IMPLEMENTED_ExprSetComp
{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right Python3 > Python2 > COBOL
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right Life is Life
NOT_IMPLEMENTED_call() NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@ -980,14 +962,26 @@ for (
addr_sockaddr, addr_sockaddr,
) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): ) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
pass pass
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right a = (
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right )
a = (
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
)
a = (
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
)
a = (
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
)
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) != signal.default_int_handler
): ):
return True return True
if ( if (

View file

@ -152,21 +152,22 @@ elif unformatted:
# Regression test for https://github.com/psf/black/issues/3184. # Regression test for https://github.com/psf/black/issues/3184.
@@ -52,29 +34,27 @@ @@ -53,28 +35,29 @@
async def call(param):
if param: if param:
# fmt: off # fmt: off
- if param[0:4] in ( if param[0:4] in (
- "ABCD", "EFGH" - "ABCD", "EFGH"
- ) : - ) :
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING",
+ ):
# fmt: on # fmt: on
- print ( "This won't be formatted" ) - print ( "This won't be formatted" )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
- elif param[0:4] in ("ZZZZ",): - elif param[0:4] in ("ZZZZ",):
- print ( "This won't be formatted either" ) - print ( "This won't be formatted either" )
+ elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + elif param[0:4] in ("NOT_YET_IMPLEMENTED_STRING",):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
- print("This will be formatted") - print("This will be formatted")
@ -189,7 +190,7 @@ elif unformatted:
# fmt: on # fmt: on
@@ -82,6 +62,6 @@ @@ -82,6 +65,6 @@
if x: if x:
return x return x
# fmt: off # fmt: off
@ -239,11 +240,14 @@ class A:
async def call(param): async def call(param):
if param: if param:
# fmt: off # fmt: off
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if param[0:4] in (
"NOT_YET_IMPLEMENTED_STRING",
"NOT_YET_IMPLEMENTED_STRING",
):
# fmt: on # fmt: on
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: elif param[0:4] in ("NOT_YET_IMPLEMENTED_STRING",):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)

View file

@ -411,7 +411,7 @@ d={'a':1,
- because . the . handling . inside . generate_ignored_nodes() - because . the . handling . inside . generate_ignored_nodes()
- now . considers . multiple . fmt . directives . within . one . prefix - now . considers . multiple . fmt . directives . within . one . prefix
+ this = NOT_IMPLEMENTED_call() + this = NOT_IMPLEMENTED_call()
+ and_ = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + and_ = indeed.it is not formatted
+ NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call()
+ now.considers.multiple.fmt.directives.within.one.prefix + now.considers.multiple.fmt.directives.within.one.prefix
# fmt: on # fmt: on
@ -663,7 +663,7 @@ def on_and_off_broken():
# fmt: on # fmt: on
# fmt: off # fmt: off
this = NOT_IMPLEMENTED_call() this = NOT_IMPLEMENTED_call()
and_ = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and_ = indeed.it is not formatted
NOT_IMPLEMENTED_call() NOT_IMPLEMENTED_call()
now.considers.multiple.fmt.directives.within.one.prefix now.considers.multiple.fmt.directives.within.one.prefix
# fmt: on # fmt: on

View file

@ -22,15 +22,14 @@ else:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,9 +1,9 @@ @@ -1,9 +1,10 @@
a, b, c = 3, 4, 5 a, b, c = 3, 4, 5
if ( if (
- a == 3 a == 3
- and b != 9 # fmt: skip - and b != 9 # fmt: skip
- and c is not None + and b
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + != 9 # fmt: skip
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # fmt: skip and c is not None
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
): ):
- print("I'm good!") - print("I'm good!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@ -44,9 +43,10 @@ else:
```py ```py
a, b, c = 3, 4, 5 a, b, c = 3, 4, 5
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right a == 3
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # fmt: skip and b
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right != 9 # fmt: skip
and c is not None
): ):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else: else:

View file

@ -107,7 +107,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
-if os.name == "posix": -if os.name == "posix":
- import termios - import termios
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if os.name == "NOT_YET_IMPLEMENTED_STRING":
+ NOT_YET_IMPLEMENTED_StmtImport + NOT_YET_IMPLEMENTED_StmtImport
def i_should_be_followed_by_only_one_newline(): def i_should_be_followed_by_only_one_newline():
@ -124,7 +124,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
- -
- def i_should_be_followed_by_only_one_newline(): - def i_should_be_followed_by_only_one_newline():
- pass - pass
+elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +elif os.name == "NOT_YET_IMPLEMENTED_STRING":
+ NOT_YET_IMPLEMENTED_StmtTry + NOT_YET_IMPLEMENTED_StmtTry
elif False: elif False:
@ -173,12 +173,12 @@ def h():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if os.name == "NOT_YET_IMPLEMENTED_STRING":
NOT_YET_IMPLEMENTED_StmtImport NOT_YET_IMPLEMENTED_StmtImport
def i_should_be_followed_by_only_one_newline(): def i_should_be_followed_by_only_one_newline():
pass pass
elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: elif os.name == "NOT_YET_IMPLEMENTED_STRING":
NOT_YET_IMPLEMENTED_StmtTry NOT_YET_IMPLEMENTED_StmtTry
elif False: elif False:

View file

@ -94,7 +94,7 @@ some_module.some_function(
} }
tup = ( tup = (
1, 1,
@@ -24,45 +24,23 @@ @@ -24,45 +24,37 @@
def f( def f(
a: int = 1, a: int = 1,
): ):
@ -112,9 +112,14 @@ some_module.some_function(
- "a": 1, - "a": 1,
- "b": 2, - "b": 2,
- }["a"] - }["a"]
- if ( + "NOT_YET_IMPLEMENTED_STRING": 1,
- a + "NOT_YET_IMPLEMENTED_STRING": 2,
- == { + }[
+ "NOT_YET_IMPLEMENTED_STRING"
+ ]
if (
a
== {
- "a": 1, - "a": 1,
- "b": 2, - "b": 2,
- "c": 3, - "c": 3,
@ -124,13 +129,18 @@ some_module.some_function(
- "g": 7, - "g": 7,
- "h": 8, - "h": 8,
- }["a"] - }["a"]
- ):
+ "NOT_YET_IMPLEMENTED_STRING": 1, + "NOT_YET_IMPLEMENTED_STRING": 1,
+ "NOT_YET_IMPLEMENTED_STRING": 2, + "NOT_YET_IMPLEMENTED_STRING": 2,
+ "NOT_YET_IMPLEMENTED_STRING": 3,
+ "NOT_YET_IMPLEMENTED_STRING": 4,
+ "NOT_YET_IMPLEMENTED_STRING": 5,
+ "NOT_YET_IMPLEMENTED_STRING": 6,
+ "NOT_YET_IMPLEMENTED_STRING": 7,
+ "NOT_YET_IMPLEMENTED_STRING": 8,
+ }[ + }[
+ "NOT_YET_IMPLEMENTED_STRING" + "NOT_YET_IMPLEMENTED_STRING"
+ ] + ]
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: ):
pass pass
@ -152,7 +162,7 @@ some_module.some_function(
} }
@@ -80,35 +58,16 @@ @@ -80,35 +72,16 @@
pass pass
@ -231,7 +241,21 @@ def f(
}[ }[
"NOT_YET_IMPLEMENTED_STRING" "NOT_YET_IMPLEMENTED_STRING"
] ]
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if (
a
== {
"NOT_YET_IMPLEMENTED_STRING": 1,
"NOT_YET_IMPLEMENTED_STRING": 2,
"NOT_YET_IMPLEMENTED_STRING": 3,
"NOT_YET_IMPLEMENTED_STRING": 4,
"NOT_YET_IMPLEMENTED_STRING": 5,
"NOT_YET_IMPLEMENTED_STRING": 6,
"NOT_YET_IMPLEMENTED_STRING": 7,
"NOT_YET_IMPLEMENTED_STRING": 8,
}[
"NOT_YET_IMPLEMENTED_STRING"
]
):
pass pass

View file

@ -99,13 +99,12 @@ return np.divide(
+i = NOT_IMPLEMENTED_call() ** 5 +i = NOT_IMPLEMENTED_call() ** 5
+j = NOT_IMPLEMENTED_call().name ** 5 +j = NOT_IMPLEMENTED_call().name ** 5
+k = [i for i in []] +k = [i for i in []]
+l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right +l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
m = [([2**63], [1, 2**63])] m = [([2**63], [1, 2**63])]
-n = count <= 10**5 n = count <= 10**5
-o = settings(max_examples=10**6) -o = settings(max_examples=10**6)
-p = {(k, k**2): v**2 for k, v in pairs} -p = {(k, k**2): v**2 for k, v in pairs}
-q = [10**i for i in range(6)] -q = [10**i for i in range(6)]
+n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} +p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+q = [i for i in []] +q = [i for i in []]
@ -131,13 +130,12 @@ return np.divide(
+i = NOT_IMPLEMENTED_call() ** 5.0 +i = NOT_IMPLEMENTED_call() ** 5.0
+j = NOT_IMPLEMENTED_call().name ** 5.0 +j = NOT_IMPLEMENTED_call().name ** 5.0
+k = [i for i in []] +k = [i for i in []]
+l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right +l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
m = [([2.0**63.0], [1.0, 2**63.0])] m = [([2.0**63.0], [1.0, 2**63.0])]
-n = count <= 10**5.0 n = count <= 10**5.0
-o = settings(max_examples=10**6.0) -o = settings(max_examples=10**6.0)
-p = {(k, k**2): v**2.0 for k, v in pairs} -p = {(k, k**2): v**2.0 for k, v in pairs}
-q = [10.5**i for i in range(6)] -q = [10.5**i for i in range(6)]
+n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} +p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+q = [i for i in []] +q = [i for i in []]
@ -187,9 +185,9 @@ h = 5 ** NOT_IMPLEMENTED_call()
i = NOT_IMPLEMENTED_call() ** 5 i = NOT_IMPLEMENTED_call() ** 5
j = NOT_IMPLEMENTED_call().name ** 5 j = NOT_IMPLEMENTED_call().name ** 5
k = [i for i in []] k = [i for i in []]
l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
m = [([2**63], [1, 2**63])] m = [([2**63], [1, 2**63])]
n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right n = count <= 10**5
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
q = [i for i in []] q = [i for i in []]
@ -206,9 +204,9 @@ h = 5.0 ** NOT_IMPLEMENTED_call()
i = NOT_IMPLEMENTED_call() ** 5.0 i = NOT_IMPLEMENTED_call() ** 5.0
j = NOT_IMPLEMENTED_call().name ** 5.0 j = NOT_IMPLEMENTED_call().name ** 5.0
k = [i for i in []] k = [i for i in []]
l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
m = [([2.0**63.0], [1.0, 2**63.0])] m = [([2.0**63.0], [1.0, 2**63.0])]
n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right n = count <= 10**5.0
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict} p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
q = [i for i in []] q = [i for i in []]

View file

@ -179,21 +179,21 @@ with open("/path/to/file.txt", mode="r") as read_file:
-if random.randint(0, 3) == 0: -if random.randint(0, 3) == 0:
- print("The new line above me is about to be removed!") - print("The new line above me is about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-if random.randint(0, 3) == 0: -if random.randint(0, 3) == 0:
- print("The new lines above me is about to be removed!") - print("The new lines above me is about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-if random.randint(0, 3) == 0: -if random.randint(0, 3) == 0:
- if random.uniform(0, 1) > 0.5: - if random.uniform(0, 1) > 0.5:
- print("Two lines above me are about to be removed!") - print("Two lines above me are about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: +if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: + if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) > 0.5:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@ -273,16 +273,16 @@ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) > 0.5:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)

View file

@ -95,10 +95,9 @@ x[
+slice[lambda x: True : lambda x: True] +slice[lambda x: True : lambda x: True]
+slice[lambda x: True :, None::] +slice[lambda x: True :, None::]
slice[1 or 2 : True and False] slice[1 or 2 : True and False]
-slice[not so_simple : 1 < val <= 10] slice[not so_simple : 1 < val <= 10]
-slice[(1 for i in range(42)) : x] -slice[(1 for i in range(42)) : x]
-slice[:: [i for i in range(42)]] -slice[:: [i for i in range(42)]]
+slice[not so_simple : NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right]
+slice[(i for i in []) : x] +slice[(i for i in []) : x]
+slice[ :: [i for i in []]] +slice[ :: [i for i in []]]
@ -161,7 +160,7 @@ slice[ : -1 :]
slice[lambda x: True : lambda x: True] slice[lambda x: True : lambda x: True]
slice[lambda x: True :, None::] slice[lambda x: True :, None::]
slice[1 or 2 : True and False] slice[1 or 2 : True and False]
slice[not so_simple : NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right] slice[not so_simple : 1 < val <= 10]
slice[(i for i in []) : x] slice[(i for i in []) : x]
slice[ :: [i for i in []]] slice[ :: [i for i in []]]

View file

@ -65,7 +65,7 @@ assert (
importA importA
0 0
@@ -24,35 +14,15 @@ @@ -24,35 +14,34 @@
class A: class A:
def foo(self): def foo(self):
@ -97,8 +97,27 @@ assert (
- othr.meta_data, - othr.meta_data,
- othr.schedule, - othr.schedule,
+ return ( + return (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + 1 == 2
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + and (
+ name,
+ description,
+ self.default,
+ self.selected,
+ self.auto_generated,
+ self.parameters,
+ self.meta_data,
+ self.schedule,
+ )
+ == (
+ name,
+ description,
+ othr.default,
+ othr.selected,
+ othr.auto_generated,
+ othr.parameters,
+ othr.meta_data,
+ othr.schedule,
+ )
) )
@ -134,8 +153,27 @@ class A:
def test(self, othr): def test(self, othr):
return ( return (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right 1 == 2
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and (
name,
description,
self.default,
self.selected,
self.auto_generated,
self.parameters,
self.meta_data,
self.schedule,
)
== (
name,
description,
othr.default,
othr.selected,
othr.auto_generated,
othr.parameters,
othr.meta_data,
othr.schedule,
)
) )

View file

@ -38,13 +38,14 @@ class A:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,34 +1,25 @@ @@ -1,34 +1,32 @@
-if e1234123412341234.winerror not in ( -if e1234123412341234.winerror not in (
- _winapi.ERROR_SEM_TIMEOUT, - _winapi.ERROR_SEM_TIMEOUT,
- _winapi.ERROR_PIPE_BUSY, - _winapi.ERROR_PIPE_BUSY,
-) or _check_timeout(t): -) or _check_timeout(t):
+if ( +if (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + e1234123412341234.winerror
+ not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
+ or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+): +):
pass pass
@ -82,7 +83,13 @@ class A:
- ) < self.connection.mysql_version < (10, 5, 2): - ) < self.connection.mysql_version < (10, 5, 2):
+ if ( + if (
+ self.connection.mysql_is_mariadb + self.connection.mysql_is_mariadb
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + and (
+ 10,
+ 4,
+ 3,
+ )
+ < self.connection.mysql_version
+ < (10, 5, 2)
+ ): + ):
pass pass
``` ```
@ -91,7 +98,8 @@ class A:
```py ```py
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right e1234123412341234.winerror
not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
): ):
pass pass
@ -112,7 +120,13 @@ class A:
def b(self): def b(self):
if ( if (
self.connection.mysql_is_mariadb self.connection.mysql_is_mariadb
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right and (
10,
4,
3,
)
< self.connection.mysql_version
< (10, 5, 2)
): ):
pass pass
``` ```

View file

@ -23,8 +23,8 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
- 8, - 8,
-) <= get_tk_patchlevel() < (8, 6): -) <= get_tk_patchlevel() < (8, 6):
+if ( +if (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + NOT_IMPLEMENTED_call() >= (8, 6, 0, "NOT_YET_IMPLEMENTED_STRING")
+ or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right + or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6)
+): +):
pass pass
``` ```
@ -33,8 +33,8 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
```py ```py
if ( if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right NOT_IMPLEMENTED_call() >= (8, 6, 0, "NOT_YET_IMPLEMENTED_STRING")
or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6)
): ):
pass pass
``` ```

View file

@ -252,7 +252,13 @@ aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprSetComp
# But only for expressions that have a statement parent. # But only for expressions that have a statement parent.
not (aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprSetComp) not (aaaaaaaaaaaaaa + NOT_YET_IMPLEMENTED_ExprSetComp)
[NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right] [
a
+ [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
]
in c,
]
# leading comment # leading comment

View file

@ -0,0 +1,189 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
---
## Input
```py
a == b
a != b
a < b
a <= b
a > b
a >= b
a is b
a is not b
a in b
a not in b
(a ==
# comment
b
)
(a == # comment
b
)
a < b > c == d
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ccccccccccccccccccccccccccccc == ddddddddddddddddddddd
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
ff,
] < [ccccccccccccccccccccccccccccc, dddd] < ddddddddddddddddddddddddddddddddddddddddddd
return 1 == 2 and (
name,
description,
self_default,
self_selected,
self_auto_generated,
self_parameters,
self_meta_data,
self_schedule,
) == (
name,
description,
othr_default,
othr_selected,
othr_auto_generated,
othr_parameters,
othr_meta_data,
othr_schedule,
)
(name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule)
((name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule))
[
(
a
+ [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
]
>= c
)
]
```
## Output
```py
a == b
a != b
a < b
a <= b
a > b
a >= b
a is b
a is not b
a in b
a not in b
(
a
# comment
== b
)
(
a # comment
== b
)
a < b > c == d
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
> ccccccccccccccccccccccccccccc
== ddddddddddddddddddddd
)
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
< [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ff]
< [ccccccccccccccccccccccccccccc, dddd]
< ddddddddddddddddddddddddddddddddddddddddddd
)
return (
1 == 2
and (
name,
description,
self_default,
self_selected,
self_auto_generated,
self_parameters,
self_meta_data,
self_schedule,
)
== (
name,
description,
othr_default,
othr_selected,
othr_auto_generated,
othr_parameters,
othr_meta_data,
othr_schedule,
)
)
(
name,
description,
self_default,
self_selected,
self_auto_generated,
self_parameters,
self_meta_data,
self_schedule,
) == (
name,
description,
other_default,
othr_selected,
othr_auto_generated,
othr_parameters,
othr_meta_data,
othr_schedule,
)
(
(
name,
description,
self_default,
self_selected,
self_auto_generated,
self_parameters,
self_meta_data,
self_schedule,
)
== (
name,
description,
other_default,
othr_selected,
othr_auto_generated,
othr_parameters,
othr_meta_data,
othr_schedule,
)
)
[
(
a
+ [
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
]
>= c
),
]
```

View file

@ -74,12 +74,12 @@ x = 3
## Output ## Output
```py ```py
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: # trailing if condition if x == y: # trailing if condition
pass # trailing `pass` comment pass # trailing `pass` comment
# Root `if` trailing comment # Root `if` trailing comment
# Leading elif comment # Leading elif comment
elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: # trailing elif condition elif x < y: # trailing elif condition
pass pass
# `elif` trailing comment # `elif` trailing comment
@ -89,11 +89,11 @@ else: # trailing else condition
# `else` trailing comment # `else` trailing comment
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if x == y:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if y == z:
... ...
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: if a == b:
... ...
else: # trailing comment else: # trailing comment
... ...

View file

@ -62,7 +62,7 @@ class Test:
c = 30 c = 30
while NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: while a == 10:
... ...
# trailing comment with one line before # trailing comment with one line before
@ -71,7 +71,7 @@ while NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
d = 40 d = 40
while NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right: while b == 20:
... ...
# no empty line before # no empty line before