Format call expressions (without call chaining) (#5341)

## Summary

This formats call expressions with magic trailing comma and parentheses
behaviour but without call chaining

## Test Plan

Lots of new test fixtures, including some that don't work yet
This commit is contained in:
konstin 2023-06-27 11:29:40 +02:00 committed by GitHub
parent 50a7769d69
commit 7f6cb9dfb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 1662 additions and 1853 deletions

12
Cargo.lock generated
View file

@ -2111,7 +2111,7 @@ dependencies = [
[[package]] [[package]]
name = "ruff_text_size" name = "ruff_text_size"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"schemars", "schemars",
"serde", "serde",
@ -2199,7 +2199,7 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-ast" name = "rustpython-ast"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"is-macro", "is-macro",
"num-bigint", "num-bigint",
@ -2210,7 +2210,7 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-format" name = "rustpython-format"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"bitflags 2.3.2", "bitflags 2.3.2",
"itertools", "itertools",
@ -2222,7 +2222,7 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-literal" name = "rustpython-literal"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"hexf-parse", "hexf-parse",
"is-macro", "is-macro",
@ -2234,7 +2234,7 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-parser" name = "rustpython-parser"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"is-macro", "is-macro",
@ -2257,7 +2257,7 @@ dependencies = [
[[package]] [[package]]
name = "rustpython-parser-core" name = "rustpython-parser-core"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=8078663b6c914c1cb86993e427764f7c422fc12c#8078663b6c914c1cb86993e427764f7c422fc12c" source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=c174bbf1f29527edd43d432326327f16f47ab9e0#c174bbf1f29527edd43d432326327f16f47ab9e0"
dependencies = [ dependencies = [
"is-macro", "is-macro",
"memchr", "memchr",

View file

@ -50,14 +50,14 @@ toml = { version = "0.7.2" }
# v0.0.1 # v0.0.1
libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "80e4c1399f95e5beb532fdd1e209ad2dbb470438" } libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "80e4c1399f95e5beb532fdd1e209ad2dbb470438" }
# Please tag the RustPython version everytime you update its revision here. # Please tag the RustPython version everytime you update its revision here and in fuzz/Cargo.toml
# Tagging the version ensures that older ruff versions continue to build from source even when we rebase our RustPython fork. # Tagging the version ensures that older ruff versions continue to build from source even when we rebase our RustPython fork.
# Current tag: v0.0.6 # Current tag: v0.0.7
ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" } ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0" }
rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["num-bigint"]} rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0" , default-features = false, features = ["num-bigint"]}
rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c", default-features = false, features = ["num-bigint"] } rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0", default-features = false, features = ["num-bigint"] }
rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c", default-features = false } rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0", default-features = false }
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["full-lexer", "num-bigint"] } rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0" , default-features = false, features = ["full-lexer", "num-bigint"] }
[profile.release] [profile.release]
lto = "fat" lto = "fat"

View file

@ -15,6 +15,7 @@ use ruff_python_ast::source_code::{Indexer, Locator, SourceFileBuilder, Stylist}
use crate::autofix::{fix_file, FixResult}; use crate::autofix::{fix_file, FixResult};
use crate::directives; use crate::directives;
#[cfg(not(fuzzing))]
use crate::jupyter::Notebook; use crate::jupyter::Notebook;
use crate::linter::{check_path, LinterResult}; use crate::linter::{check_path, LinterResult};
use crate::message::{Emitter, EmitterContext, Message, TextEmitter}; use crate::message::{Emitter, EmitterContext, Message, TextEmitter};

View file

@ -0,0 +1,83 @@
from unittest.mock import MagicMock
def f(*args, **kwargs):
pass
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd = 1
session = MagicMock()
models = MagicMock()
f()
f(1)
f(x=2)
f(1, x=2)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd
)
f(
this_is_a_very_long_keyword_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd=1
)
f(
1,
mixed_very_long_arguments=1,
)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd,
these_arguments_have_values_that_need_to_break_because_they_are_too_long1=(100000 - 100000000000),
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad" + "asdfasdfa",
these_arguments_have_values_that_need_to_break_because_they_are_too_long3=session,
)
f(
# dangling comment
)
f(
only=1, short=1, arguments=1
)
f(
hey_this_is_a_long_call, it_has_funny_attributes_that_breaks_into_three_lines=1
)
f(
hey_this_is_a_very_long_call=1, it_has_funny_attributes_asdf_asdf=1, too_long_for_the_line=1, really=True
)
# TODO(konstin): Call chains/fluent interface (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#call-chains)
result = (
session.query(models.Customer.id)
.filter(
models.Customer.account_id == 10000,
models.Customer.email == "user@example.org",
)
.order_by(models.Customer.id.asc())
.all()
)
# TODO(konstin): Black has this special case for comment placement where everything stays in one line
f(
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa"
)
f(
session,
b=1,
** # oddly placed end-of-line comment
dict()
)
f(
session,
b=1,
**
# oddly placed own line comment
dict()
)

View file

@ -989,7 +989,7 @@ fn handle_dict_unpacking_comment<'a>(
match comment.enclosing_node() { match comment.enclosing_node() {
// TODO: can maybe also add AnyNodeRef::Arguments here, but tricky to test due to // TODO: can maybe also add AnyNodeRef::Arguments here, but tricky to test due to
// https://github.com/astral-sh/ruff/issues/5176 // https://github.com/astral-sh/ruff/issues/5176
AnyNodeRef::ExprDict(_) => {} AnyNodeRef::ExprDict(_) | AnyNodeRef::Keyword(_) => {}
_ => { _ => {
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
} }
@ -1015,12 +1015,22 @@ fn handle_dict_unpacking_comment<'a>(
) )
.skip_trivia(); .skip_trivia();
// if the remaining tokens from the previous node are exactly `**`,
// re-assign the comment to the one that follows the stars
let mut count = 0;
// we start from the preceding node but we skip its token // we start from the preceding node but we skip its token
for token in tokens.by_ref() { for token in tokens.by_ref() {
// Skip closing parentheses that are not part of the node range // Skip closing parentheses that are not part of the node range
if token.kind == TokenKind::RParen { if token.kind == TokenKind::RParen {
continue; continue;
} }
// The Keyword case
if token.kind == TokenKind::Star {
count += 1;
break;
}
// The dict case
debug_assert!( debug_assert!(
matches!( matches!(
token, token,
@ -1034,9 +1044,6 @@ fn handle_dict_unpacking_comment<'a>(
break; break;
} }
// if the remaining tokens from the previous node is exactly `**`,
// re-assign the comment to the one that follows the stars
let mut count = 0;
for token in tokens { for token in tokens {
if token.kind != TokenKind::Star { if token.kind != TokenKind::Star {
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
@ -1050,19 +1057,19 @@ fn handle_dict_unpacking_comment<'a>(
CommentPlacement::Default(comment) CommentPlacement::Default(comment)
} }
// Own line comments coming after the node are always dangling comments /// Own line comments coming after the node are always dangling comments
// ```python /// ```python
// ( /// (
// a /// a
// # trailing a comment /// # trailing a comment
// . # dangling comment /// . # dangling comment
// # or this /// # or this
// b /// b
// ) /// )
// ``` /// ```
fn handle_attribute_comment<'a>( fn handle_attribute_comment<'a>(
comment: DecoratedComment<'a>, comment: DecoratedComment<'a>,
locator: &Locator, _locator: &Locator,
) -> CommentPlacement<'a> { ) -> CommentPlacement<'a> {
let Some(attribute) = comment.enclosing_node().expr_attribute() else { let Some(attribute) = comment.enclosing_node().expr_attribute() else {
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
@ -1073,14 +1080,13 @@ fn handle_attribute_comment<'a>(
return CommentPlacement::Default(comment); return CommentPlacement::Default(comment);
} }
let between_value_and_attr = TextRange::new(attribute.value.end(), attribute.attr.start()); if TextRange::new(attribute.value.end(), attribute.attr.start())
.contains(comment.slice().start())
let dot = SimpleTokenizer::new(locator.contents(), between_value_and_attr) {
.skip_trivia() // ```text
.next() // value . attr
.expect("Expected the `.` character after the value"); // ^^^^^^^ the range of dangling comments
// ```
if TextRange::new(dot.end(), attribute.attr.start()).contains(comment.slice().start()) {
if comment.line_position().is_end_of_line() { if comment.line_position().is_end_of_line() {
// Attach to node with b // Attach to node with b
// ```python // ```python

View file

@ -1,8 +1,10 @@
use crate::comments::Comments; use crate::builders::PyFormatterExtensions;
use crate::comments::{dangling_comments, Comments};
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::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{format_with, group, soft_block_indent, text};
use ruff_formatter::{write, Buffer, FormatResult}; use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::ExprCall; use rustpython_parser::ast::ExprCall;
@ -11,19 +13,75 @@ pub struct FormatExprCall;
impl FormatNodeRule<ExprCall> for FormatExprCall { impl FormatNodeRule<ExprCall> for FormatExprCall {
fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> { fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> {
if item.args.is_empty() && item.keywords.is_empty() { let ExprCall {
write!( range: _,
func,
args,
keywords,
} = item;
// We have a case with `f()` without any argument, which is a special case because we can
// have a comment with no node attachment inside:
// ```python
// f(
// # This function has a dangling comment
// )
// ```
if args.is_empty() && keywords.is_empty() {
let comments = f.context().comments().clone();
let comments = comments.dangling_comments(item);
return write!(
f, f,
[not_yet_implemented_custom_text("NOT_IMPLEMENTED_call()")] [
) func.format(),
} else { text("("),
write!( dangling_comments(comments),
f, text(")")
[not_yet_implemented_custom_text( ]
"NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)" );
)]
)
} }
let all_args = format_with(|f| {
f.join_comma_separated()
.entries(
// We have the parentheses from the call so the arguments never need any
args.iter()
.map(|arg| (arg, arg.format().with_options(Parenthesize::Never))),
)
.nodes(keywords.iter())
.finish()
});
write!(
f,
[
func.format(),
text("("),
// The outer group is for things like
// ```python
// get_collection(
// hey_this_is_a_very_long_call,
// it_has_funny_attributes_asdf_asdf,
// too_long_for_the_line,
// really=True,
// )
// ```
// The inner group is for things like:
// ```python
// get_collection(
// hey_this_is_a_very_long_call, it_has_funny_attributes_asdf_asdf, really=True
// )
// ```
// TODO(konstin): Doesn't work see wrongly formatted test
&group(&soft_block_indent(&group(&all_args))),
text(")")
]
)
}
fn fmt_dangling_comments(&self, _node: &ExprCall, _f: &mut PyFormatter) -> FormatResult<()> {
// Handled in `fmt_fields`
Ok(())
} }
} }

View file

@ -13,10 +13,11 @@ impl FormatNodeRule<Keyword> for FormatKeyword {
arg, arg,
value, value,
} = item; } = item;
if let Some(argument) = arg { if let Some(arg) = arg {
write!(f, [argument.format(), text("=")])?; write!(f, [arg.format(), text("="), value.format()])
} else {
// Comments after the stars are reassigned as trailing value comments
write!(f, [text("**"), value.format()])
} }
value.format().fmt(f)
} }
} }

View file

@ -34,14 +34,18 @@ y = 100(no)
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,22 +1,22 @@ @@ -1,19 +1,19 @@
-x = (123456789).bit_count() x = (123456789).bit_count()
-x = (123456).__abs__() x = (123456).__abs__()
-x = (0.1).is_integer() -x = (0.1).is_integer()
-x = (1.0).imag -x = (1.0).imag
-x = (1e1).imag -x = (1e1).imag
-x = (1e-1).real -x = (1e-1).real
-x = (123456789.123456789).hex() +x = (.1).is_integer()
+x = (1.).imag
+x = (1E+1).imag
+x = (1E-1).real
x = (123456789.123456789).hex()
-x = (123456789.123456789e123456789).real -x = (123456789.123456789e123456789).real
-x = (123456789e123456789).conjugate() -x = (123456789e123456789).conjugate()
-x = 123456789j.real -x = 123456789j.real
@ -49,58 +53,46 @@ y = 100(no)
-x = 0xB1ACC.conjugate() -x = 0xB1ACC.conjugate()
-x = 0b1011.conjugate() -x = 0b1011.conjugate()
-x = 0o777.real -x = 0o777.real
-x = (0.000000006).hex()
-x = -100.0000j
+x = NOT_IMPLEMENTED_call()
+x = NOT_IMPLEMENTED_call()
+x = NOT_IMPLEMENTED_call()
+x = (1.).imag
+x = (1E+1).imag
+x = (1E-1).real
+x = NOT_IMPLEMENTED_call()
+x = (123456789.123456789E123456789).real +x = (123456789.123456789E123456789).real
+x = NOT_IMPLEMENTED_call() +x = (123456789E123456789).conjugate()
+x = 123456789J.real +x = 123456789J.real
+x = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +x = 123456789.123456789J.__add__((0b1011).bit_length())
+x = NOT_IMPLEMENTED_call() +x = (0XB1ACC).conjugate()
+x = NOT_IMPLEMENTED_call() +x = (0B1011).conjugate()
+x = (0O777).real +x = (0O777).real
+x = NOT_IMPLEMENTED_call() x = (0.000000006).hex()
-x = -100.0000j
+x = -100.0000J +x = -100.0000J
if (10).real: if (10).real:
... ...
y = 100[no]
-y = 100(no)
+y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
```py ```py
x = NOT_IMPLEMENTED_call() x = (123456789).bit_count()
x = NOT_IMPLEMENTED_call() x = (123456).__abs__()
x = NOT_IMPLEMENTED_call() x = (.1).is_integer()
x = (1.).imag x = (1.).imag
x = (1E+1).imag x = (1E+1).imag
x = (1E-1).real x = (1E-1).real
x = NOT_IMPLEMENTED_call() x = (123456789.123456789).hex()
x = (123456789.123456789E123456789).real x = (123456789.123456789E123456789).real
x = NOT_IMPLEMENTED_call() x = (123456789E123456789).conjugate()
x = 123456789J.real x = 123456789J.real
x = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) x = 123456789.123456789J.__add__((0b1011).bit_length())
x = NOT_IMPLEMENTED_call() x = (0XB1ACC).conjugate()
x = NOT_IMPLEMENTED_call() x = (0B1011).conjugate()
x = (0O777).real x = (0O777).real
x = NOT_IMPLEMENTED_call() x = (0.000000006).hex()
x = -100.0000J x = -100.0000J
if (10).real: if (10).real:
... ...
y = 100[no] y = 100[no]
y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) y = 100(no)
``` ```
## Black Output ## Black Output

View file

@ -1,39 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py
---
## Input
```py
\
print("hello, world")
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1 +1 @@
-print("hello, world")
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
```
## Ruff Output
```py
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
```
## Black Output
```py
print("hello, world")
```

View file

@ -123,12 +123,11 @@ if True:
-} -}
+c = {1, 2, 3} +c = {1, 2, 3}
x = (1,) x = (1,)
-y = (narf(),) y = (narf(),)
-nested = { -nested = {
- (1, 2, 3), - (1, 2, 3),
- (4, 5, 6), - (4, 5, 6),
-} -}
+y = (NOT_IMPLEMENTED_call(),)
+nested = {(1, 2, 3), (4, 5, 6)} +nested = {(1, 2, 3), (4, 5, 6)}
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)} nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
nested_long_lines = [ nested_long_lines = [
@ -145,40 +144,6 @@ if True:
# looping over a 1-tuple should also not get wrapped # looping over a 1-tuple should also not get wrapped
for x in (1,): for x in (1,):
@@ -70,7 +49,7 @@
]
division_result_tuple = (6 / 2,)
-print("foo %r", (foo.bar,))
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if True:
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
@@ -79,21 +58,6 @@
)
if True:
- ec2client.get_waiter("instance_stopped").wait(
- InstanceIds=[instance.id],
- WaiterConfig={
- "Delay": 5,
- },
- )
- ec2client.get_waiter("instance_stopped").wait(
- InstanceIds=[instance.id],
- WaiterConfig={
- "Delay": 5,
- },
- )
- ec2client.get_waiter("instance_stopped").wait(
- InstanceIds=[instance.id],
- WaiterConfig={
- "Delay": 5,
- },
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
@ -201,7 +166,7 @@ a = {1, 2, 3}
b = {1, 2, 3} b = {1, 2, 3}
c = {1, 2, 3} c = {1, 2, 3}
x = (1,) x = (1,)
y = (NOT_IMPLEMENTED_call(),) y = (narf(),)
nested = {(1, 2, 3), (4, 5, 6)} nested = {(1, 2, 3), (4, 5, 6)}
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)} nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
nested_long_lines = [ nested_long_lines = [
@ -235,7 +200,7 @@ for (x,) in (1,), (2,), (3,):
] ]
division_result_tuple = (6 / 2,) division_result_tuple = (6 / 2,)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("foo %r", (foo.bar,))
if True: if True:
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = ( IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
@ -244,9 +209,24 @@ if True:
) )
if True: if True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) ec2client.get_waiter("instance_stopped").wait(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) InstanceIds=[instance.id],
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) WaiterConfig={
"Delay": 5,
},
)
ec2client.get_waiter("instance_stopped").wait(
InstanceIds=[instance.id],
WaiterConfig={
"Delay": 5,
},
)
ec2client.get_waiter("instance_stopped").wait(
InstanceIds=[instance.id],
WaiterConfig={
"Delay": 5,
},
)
``` ```
## Black Output ## Black Output

View file

@ -130,42 +130,16 @@ async def wat():
# Some comment before a function. # Some comment before a function.
@@ -35,20 +32,24 @@ @@ -35,7 +32,7 @@
Possibly many lines. Possibly many lines.
""" """
# FIXME: Some comment about why this function is crap but still in production. # FIXME: Some comment about why this function is crap but still in production.
- import inner_imports - import inner_imports
+ NOT_YET_IMPLEMENTED_StmtImport + NOT_YET_IMPLEMENTED_StmtImport
- if inner_imports.are_evil(): if inner_imports.are_evil():
+ if NOT_IMPLEMENTED_call():
# Explains why we have this if. # Explains why we have this if.
# In great detail indeed. @@ -82,8 +79,7 @@
- x = X()
- return x.method1() # type: ignore
+ x = NOT_IMPLEMENTED_call()
+ return NOT_IMPLEMENTED_call() # type: ignore
# This return is also commented for some reason.
return default
# Explains why we use global state.
-GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
+GLOBAL_STATE = {
+ "a": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "b": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "c": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+}
# Another comment!
@@ -78,19 +79,18 @@
#' <h1>This is pweave!</h1>
-@fast(really=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
async def wat(): async def wat():
# This comment, for some reason \ # This comment, for some reason \
# contains a trailing backslash. # contains a trailing backslash.
@ -174,12 +148,8 @@ async def wat():
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments + NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
# Comment after ending a block. # Comment after ending a block.
if result: if result:
- print("A OK", file=sys.stdout) print("A OK", file=sys.stdout)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @@ -93,4 +89,4 @@
# Comment between things.
- print()
+ NOT_IMPLEMENTED_call()
# Some closing comments. # Some closing comments.
# Maybe Vim or Emacs directives for formatting. # Maybe Vim or Emacs directives for formatting.
@ -227,22 +197,18 @@ def function(default=None):
# FIXME: Some comment about why this function is crap but still in production. # FIXME: Some comment about why this function is crap but still in production.
NOT_YET_IMPLEMENTED_StmtImport NOT_YET_IMPLEMENTED_StmtImport
if NOT_IMPLEMENTED_call(): if inner_imports.are_evil():
# Explains why we have this if. # Explains why we have this if.
# In great detail indeed. # In great detail indeed.
x = NOT_IMPLEMENTED_call() x = X()
return NOT_IMPLEMENTED_call() # type: ignore return x.method1() # type: ignore
# This return is also commented for some reason. # This return is also commented for some reason.
return default return default
# Explains why we use global state. # Explains why we use global state.
GLOBAL_STATE = { GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
"a": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"b": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"c": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
}
# Another comment! # Another comment!
@ -272,16 +238,16 @@ class Foo:
#' <h1>This is pweave!</h1> #' <h1>This is pweave!</h1>
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @fast(really=True)
async def wat(): async def wat():
# This comment, for some reason \ # This comment, for some reason \
# contains a trailing backslash. # contains a trailing backslash.
NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
# Comment after ending a block. # Comment after ending a block.
if result: if result:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("A OK", file=sys.stdout)
# Comment between things. # Comment between things.
NOT_IMPLEMENTED_call() print()
# Some closing comments. # Some closing comments.

View file

@ -189,36 +189,16 @@ instruction()#comment with bad spacing
# Please keep __all__ alphabetized within each category. # Please keep __all__ alphabetized within each category.
@@ -37,31 +33,35 @@ @@ -45,7 +41,7 @@
# builtin types and objects
type,
object,
- object(),
- Exception(),
+ NOT_IMPLEMENTED_call(),
+ NOT_IMPLEMENTED_call(),
42,
100.0,
"spam",
# user-defined types and objects # user-defined types and objects
Cheese, Cheese,
- Cheese("Wensleydale"), Cheese("Wensleydale"),
- SubBytes(b"spam"), - SubBytes(b"spam"),
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), + SubBytes(b"NOT_YET_IMPLEMENTED_BYTE_STRING"),
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
] ]
if "PYTHON" in os.environ: if "PYTHON" in os.environ:
- add_compiler(compiler_from_env()) @@ -60,8 +56,12 @@
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else:
# for compiler in compilers.values():
# add_compiler(compiler)
- add_compiler(compilers[(7.0, 32)])
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# add_compiler(compilers[(7.1, 64)])
# Comment before function. # Comment before function.
def inline_comments_in_brackets_ruin_everything(): def inline_comments_in_brackets_ruin_everything():
if typedargslist: if typedargslist:
@ -232,7 +212,7 @@ instruction()#comment with bad spacing
children[0], children[0],
body, body,
children[-1], # type: ignore children[-1], # type: ignore
@@ -72,14 +72,18 @@ @@ -72,7 +72,11 @@
body, body,
parameters.children[-1], # )2 parameters.children[-1], # )2
] ]
@ -245,42 +225,10 @@ instruction()#comment with bad spacing
if ( if (
self._proc is not None self._proc is not None
# has the child process finished? # has the child process finished?
and self._returncode is None @@ -114,25 +118,9 @@
# the child process has finished, but the # yup
# transport hasn't been notified yet? arg3=True,
- and self._proc.poll() is None )
+ and NOT_IMPLEMENTED_call() is None
):
pass
# no newline before or after
@@ -91,48 +95,14 @@
]
# no newline after
- call(
- arg1,
- arg2,
- """
-short
-""",
- arg3=True,
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
############################################################################
- call2(
- # short
- arg1,
- # but
- arg2,
- # multiline
- """
-short
-""",
- # yup
- arg3=True,
- )
- lcomp = [ - lcomp = [
- element for element in collection if element is not None # yup # yup # right - element for element in collection if element is not None # yup # yup # right
- ] - ]
@ -300,26 +248,25 @@ instruction()#comment with bad spacing
- # right - # right
- if element is not None - if element is not None
- ] - ]
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ lcomp = [i for i in []] + lcomp = [i for i in []]
+ lcomp2 = [i for i in []] + lcomp2 = [i for i in []]
+ lcomp3 = [i for i in []] + lcomp3 = [i for i in []]
while True: while True:
if False: if False:
continue continue
@@ -141,10 +111,7 @@ @@ -143,7 +131,10 @@
# and round and round we go
# let's return # let's return
- return Node( return Node(
- syms.simple_stmt, syms.simple_stmt,
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n? - [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
- ) + [
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + Node(statement, result),
+ Leaf(token.NEWLINE, "\n"), # FIXME: \r\n?
+ ],
)
CONFIG_FILES = ( @@ -158,7 +149,11 @@
@@ -158,7 +125,11 @@
class Test: class Test:
def _init_host(self, parsed) -> None: def _init_host(self, parsed) -> None:
@ -327,20 +274,11 @@ instruction()#comment with bad spacing
+ if ( + if (
+ parsed.hostname + parsed.hostname
+ is None # type: ignore + is None # type: ignore
+ or not NOT_IMPLEMENTED_call() + or not parsed.hostname.strip()
+ ): + ):
pass pass
@@ -167,7 +138,7 @@
#######################
-instruction() # comment with bad spacing
+NOT_IMPLEMENTED_call() # comment with bad spacing
# END COMMENTS
# MORE END COMMENTS
``` ```
## Ruff Output ## Ruff Output
@ -381,23 +319,23 @@ not_shareables = [
# builtin types and objects # builtin types and objects
type, type,
object, object,
NOT_IMPLEMENTED_call(), object(),
NOT_IMPLEMENTED_call(), Exception(),
42, 42,
100.0, 100.0,
"spam", "spam",
# user-defined types and objects # user-defined types and objects
Cheese, Cheese,
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), Cheese("Wensleydale"),
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), SubBytes(b"NOT_YET_IMPLEMENTED_BYTE_STRING"),
] ]
if "PYTHON" in os.environ: if "PYTHON" in os.environ:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) add_compiler(compiler_from_env())
else: else:
# for compiler in compilers.values(): # for compiler in compilers.values():
# add_compiler(compiler) # add_compiler(compiler)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) add_compiler(compilers[(7.0, 32)])
# add_compiler(compilers[(7.1, 64)]) # add_compiler(compilers[(7.1, 64)])
@ -431,7 +369,7 @@ def inline_comments_in_brackets_ruin_everything():
and self._returncode is None 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_call() is None and self._proc.poll() is None
): ):
pass pass
# no newline before or after # no newline before or after
@ -443,11 +381,29 @@ def inline_comments_in_brackets_ruin_everything():
] ]
# no newline after # no newline after
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(
arg1,
arg2,
"""
short
""",
arg3=True,
)
############################################################################ ############################################################################
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call2(
# short
arg1,
# but
arg2,
# multiline
"""
short
""",
# yup
arg3=True,
)
lcomp = [i for i in []] lcomp = [i for i in []]
lcomp2 = [i for i in []] lcomp2 = [i for i in []]
lcomp3 = [i for i in []] lcomp3 = [i for i in []]
@ -459,7 +415,13 @@ def inline_comments_in_brackets_ruin_everything():
# and round and round we go # and round and round we go
# let's return # let's return
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) return Node(
syms.simple_stmt,
[
Node(statement, result),
Leaf(token.NEWLINE, "\n"), # FIXME: \r\n?
],
)
CONFIG_FILES = ( CONFIG_FILES = (
@ -476,7 +438,7 @@ class Test:
if ( if (
parsed.hostname parsed.hostname
is None # type: ignore is None # type: ignore
or not NOT_IMPLEMENTED_call() or not parsed.hostname.strip()
): ):
pass pass
@ -486,7 +448,7 @@ class Test:
####################### #######################
NOT_IMPLEMENTED_call() # comment with bad spacing instruction() # comment with bad spacing
# END COMMENTS # END COMMENTS
# MORE END COMMENTS # MORE END COMMENTS

View file

@ -60,7 +60,7 @@ def func():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -6,43 +6,16 @@ @@ -6,14 +6,7 @@
x = """ x = """
a really long string a really long string
""" """
@ -74,40 +74,17 @@ def func():
- ] - ]
+ lcomp3 = [i for i in []] + lcomp3 = [i for i in []]
# Capture each of the exceptions in the MultiError along with each of their causes and contexts # Capture each of the exceptions in the MultiError along with each of their causes and contexts
- if isinstance(exc_value, MultiError): if isinstance(exc_value, MultiError):
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
embedded = [] embedded = []
for exc in exc_value.exceptions: @@ -29,7 +22,7 @@
if exc not in _seen: # copy the set of _seen exceptions so that duplicates
- embedded.append( # shared between sub-exceptions are not omitted
- # This should be left alone (before) _seen=set(_seen),
- traceback.TracebackException.from_exception(
- exc,
- limit=limit,
- lookup_lines=lookup_lines,
- capture_locals=capture_locals,
- # copy the set of _seen exceptions so that duplicates
- # shared between sub-exceptions are not omitted
- _seen=set(_seen),
- ) - )
- # This should be left alone (after) + ),
- ) # This should be left alone (after)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
# everything is fine if the expression isn't nested
- traceback.TracebackException.from_exception(
- exc,
- limit=limit,
- lookup_lines=lookup_lines,
- capture_locals=capture_locals,
- # copy the set of _seen exceptions so that duplicates
- # shared between sub-exceptions are not omitted
- _seen=set(_seen),
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# %%
``` ```
## Ruff Output ## Ruff Output
@ -123,14 +100,34 @@ def func():
""" """
lcomp3 = [i for i in []] lcomp3 = [i for i in []]
# Capture each of the exceptions in the MultiError along with each of their causes and contexts # Capture each of the exceptions in the MultiError along with each of their causes and contexts
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): if isinstance(exc_value, MultiError):
embedded = [] embedded = []
for exc in exc_value.exceptions: for exc in exc_value.exceptions:
if exc not in _seen: if exc not in _seen:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) embedded.append(
# This should be left alone (before)
traceback.TracebackException.from_exception(
exc,
limit=limit,
lookup_lines=lookup_lines,
capture_locals=capture_locals,
# copy the set of _seen exceptions so that duplicates
# shared between sub-exceptions are not omitted
_seen=set(_seen),
),
# This should be left alone (after)
)
# everything is fine if the expression isn't nested # everything is fine if the expression isn't nested
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) traceback.TracebackException.from_exception(
exc,
limit=limit,
lookup_lines=lookup_lines,
capture_locals=capture_locals,
# copy the set of _seen exceptions so that duplicates
# shared between sub-exceptions are not omitted
_seen=set(_seen),
)
# %% # %%

View file

@ -106,7 +106,7 @@ def foo3(list_a, list_b):
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,94 +1,28 @@ @@ -1,9 +1,5 @@
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import ( -from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
- MyLovelyCompanyTeamProjectComponent, # NOT DRY - MyLovelyCompanyTeamProjectComponent, # NOT DRY
-) -)
@ -118,72 +118,27 @@ def foo3(list_a, list_b):
class C: class C:
- @pytest.mark.parametrize( @@ -58,37 +54,28 @@
- ("post_data", "message"),
- [
- # metadata_version errors.
- (
- {},
- "None is an invalid value for Metadata-Version. Error: This field is"
- " required. see"
- " https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {"metadata_version": "-1"},
- "'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
- " Version see"
- " https://packaging.python.org/specifications/core-metadata",
- ),
- # name errors.
- (
- {"metadata_version": "1.2"},
- "'' is an invalid value for Name. Error: This field is required. see"
- " https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {"metadata_version": "1.2", "name": "foo-"},
- "'foo-' is an invalid value for Name. Error: Must start and end with a"
- " letter or numeral and contain only ascii numeric and '.', '_' and"
- " '-'. see https://packaging.python.org/specifications/core-metadata",
- ),
- # version errors.
- (
- {"metadata_version": "1.2", "name": "example"},
- "'' is an invalid value for Version. Error: This field is required. see"
- " https://packaging.python.org/specifications/core-metadata",
- ),
- (
- {"metadata_version": "1.2", "name": "example", "version": "dog"},
- "'dog' is an invalid value for Version. Error: Must start and end with"
- " a letter or numeral and contain only ascii numeric and '.', '_' and"
- " '-'. see https://packaging.python.org/specifications/core-metadata",
- ),
- ],
- )
+ @NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def test_fails_invalid_post_data(
self, pyramid_config, db_request, post_data, message
):
- pyramid_config.testing_securitypolicy(userid=1)
- db_request.POST = MultiDict(post_data)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ db_request.POST = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def foo(list_a, list_b): def foo(list_a, list_b):
- results = ( results = (
- User.query.filter(User.foo == "bar") - User.query.filter(User.foo == "bar")
- .filter( # Because foo. - .filter( # Because foo.
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) + User.query.filter(User.foo == "bar").filter( # Because foo.
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
- ) - )
- .filter(User.xyz.is_(None)) - .filter(User.xyz.is_(None))
- # Another comment about the filtering on is_quux goes here. + ).filter(User.xyz.is_(None)).
# Another comment about the filtering on is_quux goes here.
- .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))) - .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True)))
- .order_by(User.created_at.desc()) - .order_by(User.created_at.desc())
- .with_for_update(key_share=True) - .with_for_update(key_share=True)
- .all() - .all()
- ) - )
+ results = NOT_IMPLEMENTED_call() + filter
+ )(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
+ User.created_at.desc()
+ ).with_for_update(key_share=True).all()
return results return results
@ -196,7 +151,9 @@ def foo3(list_a, list_b):
- ) - )
- .filter(User.xyz.is_(None)) - .filter(User.xyz.is_(None))
- ) - )
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + return User.query.filter(User.foo == "bar").filter(
+ db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
+ ).filter(User.xyz.is_(None))
def foo3(list_a, list_b): def foo3(list_a, list_b):
@ -204,10 +161,11 @@ def foo3(list_a, list_b):
# Standalone comment but weirdly placed. # Standalone comment but weirdly placed.
- User.query.filter(User.foo == "bar") - User.query.filter(User.foo == "bar")
- .filter( - .filter(
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) + User.query.filter(User.foo == "bar").filter(
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
- ) - )
- .filter(User.xyz.is_(None)) - .filter(User.xyz.is_(None))
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + ).filter(User.xyz.is_(None))
) )
``` ```
@ -219,28 +177,81 @@ NOT_YET_IMPLEMENTED_StmtImportFrom
class C: class C:
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @pytest.mark.parametrize(
("post_data", "message"),
[
# metadata_version errors.
(
{},
"None is an invalid value for Metadata-Version. Error: This field is"
" required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "-1"},
"'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
" Version see"
" https://packaging.python.org/specifications/core-metadata",
),
# name errors.
(
{"metadata_version": "1.2"},
"'' is an invalid value for Name. Error: This field is required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "1.2", "name": "foo-"},
"'foo-' is an invalid value for Name. Error: Must start and end with a"
" letter or numeral and contain only ascii numeric and '.', '_' and"
" '-'. see https://packaging.python.org/specifications/core-metadata",
),
# version errors.
(
{"metadata_version": "1.2", "name": "example"},
"'' is an invalid value for Version. Error: This field is required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "1.2", "name": "example", "version": "dog"},
"'dog' is an invalid value for Version. Error: Must start and end with"
" a letter or numeral and contain only ascii numeric and '.', '_' and"
" '-'. see https://packaging.python.org/specifications/core-metadata",
),
],
)
def test_fails_invalid_post_data( def test_fails_invalid_post_data(
self, pyramid_config, db_request, post_data, message self, pyramid_config, db_request, post_data, message
): ):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) pyramid_config.testing_securitypolicy(userid=1)
db_request.POST = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) db_request.POST = MultiDict(post_data)
def foo(list_a, list_b): def foo(list_a, list_b):
results = NOT_IMPLEMENTED_call() results = (
User.query.filter(User.foo == "bar").filter( # Because foo.
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(User.xyz.is_(None)).
# Another comment about the filtering on is_quux goes here.
filter
)(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
User.created_at.desc()
).with_for_update(key_share=True).all()
return results return results
def foo2(list_a, list_b): def foo2(list_a, list_b):
# Standalone comment reasonably placed. # Standalone comment reasonably placed.
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) return User.query.filter(User.foo == "bar").filter(
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(User.xyz.is_(None))
def foo3(list_a, list_b): def foo3(list_a, list_b):
return ( return (
# Standalone comment but weirdly placed. # Standalone comment but weirdly placed.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) User.query.filter(User.foo == "bar").filter(
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(User.xyz.is_(None))
) )
``` ```

View file

@ -85,38 +85,14 @@ if __name__ == "__main__":
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,6 +1,6 @@ @@ -20,14 +20,9 @@
while True: with open(some_temp_file) as f:
if something.changed: data = f.read()
- do.stuff() # trailing comment
+ NOT_IMPLEMENTED_call() # trailing comment
# Comment belongs to the `if` block.
# This one belongs to the `while` block.
@@ -8,26 +8,21 @@
# This one is properly standalone now.
-for i in range(100):
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
# first we do this
if i % 33 == 0:
break
# then we do this
- print(i)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# and finally we loop around
-with open(some_temp_file) as f:
- data = f.read()
-
-try: -try:
- with open(some_other_file) as w: - with open(some_other_file) as w:
- w.write(data) - w.write(data)
+with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as f: -
+ data = NOT_IMPLEMENTED_call()
-except OSError: -except OSError:
- print("problems") - print("problems")
+NOT_YET_IMPLEMENTED_StmtTry +NOT_YET_IMPLEMENTED_StmtTry
@ -126,30 +102,6 @@ if __name__ == "__main__":
# leading function comment # leading function comment
@@ -42,7 +37,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# leading 3
@deco3
def decorated1():
@@ -52,7 +47,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# leading function comment
def decorated1():
...
@@ -70,4 +65,4 @@
if __name__ == "__main__":
- main()
+ NOT_IMPLEMENTED_call()
``` ```
## Ruff Output ## Ruff Output
@ -157,7 +109,7 @@ if __name__ == "__main__":
```py ```py
while True: while True:
if something.changed: if something.changed:
NOT_IMPLEMENTED_call() # trailing comment do.stuff() # trailing comment
# Comment belongs to the `if` block. # Comment belongs to the `if` block.
# This one belongs to the `while` block. # This one belongs to the `while` block.
@ -165,17 +117,17 @@ while True:
# This one is properly standalone now. # This one is properly standalone now.
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(100):
# first we do this # first we do this
if i % 33 == 0: if i % 33 == 0:
break break
# then we do this # then we do this
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(i)
# and finally we loop around # and finally we loop around
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as f: with open(some_temp_file) as f:
data = NOT_IMPLEMENTED_call() data = f.read()
NOT_YET_IMPLEMENTED_StmtTry NOT_YET_IMPLEMENTED_StmtTry
@ -194,7 +146,7 @@ def wat():
# leading 1 # leading 1
@deco1 @deco1
# leading 2 # leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @deco2(with_args=True)
# leading 3 # leading 3
@deco3 @deco3
def decorated1(): def decorated1():
@ -204,7 +156,7 @@ def decorated1():
# leading 1 # leading 1
@deco1 @deco1
# leading 2 # leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @deco2(with_args=True)
# leading function comment # leading function comment
def decorated1(): def decorated1():
... ...
@ -222,7 +174,7 @@ def g():
if __name__ == "__main__": if __name__ == "__main__":
NOT_IMPLEMENTED_call() main()
``` ```
## Black Output ## Black Output

View file

@ -136,44 +136,30 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
def f( def f(
@@ -49,10 +49,11 @@ @@ -49,9 +49,7 @@
element = 0 # type: int element = 0 # type: int
another_element = 1 # type: float another_element = 1 # type: float
another_element_with_long_name = 2 # type: int another_element_with_long_name = 2 # type: int
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = ( - another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = (
- 3 - 3
- ) # type: int - ) # type: int
- an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
+ another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int + another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int
+ an_element_with_a_long_value = ( an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
+ NOT_IMPLEMENTED_call()
+ or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
+ ) # type: bool
tup = ( tup = (
another_element, @@ -100,19 +98,35 @@
@@ -86,33 +87,20 @@ )
def func(
a=some_list[0], # type: int
): # type: () -> int
- c = call(
- 0.0123,
- 0.0456,
- 0.0789,
- 0.0123,
- 0.0456,
- 0.0789,
- 0.0123,
- 0.0456,
- 0.0789,
- a[-1], # type: ignore
- )
+ c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
- c = call( c = call(
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore - "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
- ) + "aaaaaaaa",
+ c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + "aaaaaaaa",
+ "aaaaaaaa",
+ "aaaaaaaa",
+ "aaaaaaaa",
+ "aaaaaaaa",
+ "aaaaaaaa", # type: ignore
)
-result = ( # aaa -result = ( # aaa
@ -189,14 +175,21 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
+ + AAAAAAAAAAAAA + + AAAAAAAAAAAAA
+) # type: ignore +) # type: ignore
-call_to_some_function_asdf( call_to_some_function_asdf(
- foo, foo,
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore - [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
-) + [
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + AAAAAAAAAAAAAAAAAAAAAAA,
+ AAAAAAAAAAAAAAAAAAAAAAA,
+ AAAAAAAAAAAAAAAAAAAAAAA,
+ BBBBBBBBBBBB,
+ ], # type: ignore
)
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] -aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
+aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type] +aaaaaaaaaaaaa, bbbbbbbbb = map(
+ list, map(itertools.chain.from_iterable, zip(*NOT_YET_IMPLEMENTED_ExprStarred))
+) # type: ignore[arg-type]
``` ```
## Ruff Output ## Ruff Output
@ -254,10 +247,7 @@ def f(
another_element = 1 # type: float another_element = 1 # type: float
another_element_with_long_name = 2 # type: int another_element_with_long_name = 2 # type: int
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int
an_element_with_a_long_value = ( an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
NOT_IMPLEMENTED_call()
or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
) # type: bool
tup = ( tup = (
another_element, another_element,
@ -291,9 +281,28 @@ def f(
def func( def func(
a=some_list[0], # type: int a=some_list[0], # type: int
): # type: () -> int ): # type: () -> int
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) c = call(
0.0123,
0.0456,
0.0789,
0.0123,
0.0456,
0.0789,
0.0123,
0.0456,
0.0789,
a[-1], # type: ignore
)
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) c = call(
"aaaaaaaa",
"aaaaaaaa",
"aaaaaaaa",
"aaaaaaaa",
"aaaaaaaa",
"aaaaaaaa",
"aaaaaaaa", # type: ignore
)
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
@ -305,9 +314,19 @@ AAAAAAAAAAAAA = (
+ AAAAAAAAAAAAA + AAAAAAAAAAAAA
) # type: ignore ) # type: ignore
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call_to_some_function_asdf(
foo,
[
AAAAAAAAAAAAAAAAAAAAAAA,
AAAAAAAAAAAAAAAAAAAAAAA,
AAAAAAAAAAAAAAAAAAAAAAA,
BBBBBBBBBBBB,
], # type: ignore
)
aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type] aaaaaaaaaaaaa, bbbbbbbbb = map(
list, map(itertools.chain.from_iterable, zip(*NOT_YET_IMPLEMENTED_ExprStarred))
) # type: ignore[arg-type]
``` ```
## Black Output ## Black Output

View file

@ -151,33 +151,6 @@ def bar():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -59,7 +59,7 @@
@deco1
# leading 2
# leading 2 extra
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# leading 3
@deco3
# leading 4
@@ -73,7 +73,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# leading 3 that already has an empty line
@deco3
@@ -88,7 +88,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# leading 3
@deco3
@@ -106,7 +106,6 @@ @@ -106,7 +106,6 @@
# Another leading comment # Another leading comment
def another_inline(): def another_inline():
@ -260,7 +233,7 @@ some = statement
@deco1 @deco1
# leading 2 # leading 2
# leading 2 extra # leading 2 extra
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @deco2(with_args=True)
# leading 3 # leading 3
@deco3 @deco3
# leading 4 # leading 4
@ -274,7 +247,7 @@ some = statement
# leading 1 # leading 1
@deco1 @deco1
# leading 2 # leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @deco2(with_args=True)
# leading 3 that already has an empty line # leading 3 that already has an empty line
@deco3 @deco3
@ -289,7 +262,7 @@ some = statement
# leading 1 # leading 1
@deco1 @deco1
# leading 2 # leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @deco2(with_args=True)
# leading 3 # leading 3
@deco3 @deco3

View file

@ -31,7 +31,7 @@ def function(a:int=42):
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,22 +1,17 @@ @@ -1,9 +1,4 @@
-from .config import ( -from .config import (
- ConfigTypeAttributes, - ConfigTypeAttributes,
- Int, - Int,
@ -42,11 +42,7 @@ def function(a:int=42):
result = 1 # A simple comment result = 1 # A simple comment
result = (1,) # Another one result = (1,) # Another one
@@ -14,9 +9,9 @@
result = 1 #  type: ignore
result = 1 # This comment is talking about type: ignore
-square = Square(4) #  type: Optional[Square]
+square = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) #  type: Optional[Square]
def function(a: int = 42): def function(a: int = 42):
@ -71,7 +67,7 @@ result = (1,) # Another one
result = 1 #  type: ignore result = 1 #  type: ignore
result = 1 # This comment is talking about type: ignore result = 1 # This comment is talking about type: ignore
square = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) #  type: Optional[Square] square = Square(4) #  type: Optional[Square]
def function(a: int = 42): def function(a: int = 42):

View file

@ -193,69 +193,41 @@ class C:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,23 +1,10 @@ @@ -28,8 +28,8 @@
class C:
def test(self) -> None:
- with patch("black.out", print):
- self.assertEqual(
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
- )
- self.assertEqual(
- unstyle(str(report)),
- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
- )
- self.assertEqual(
- unstyle(str(report)),
- "2 files reformatted, 1 file left unchanged, 1 file failed to"
- " reformat.",
- )
- self.assertEqual(
- unstyle(str(report)),
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat.",
- )
+ with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in (a,):
if (
# Rule 1
@@ -27,133 +14,46 @@
):
while ( while (
# Just a comment # Just a comment
- call() call()
- # Another + ):
+ NOT_IMPLEMENTED_call() # Another
): - ):
- print(i) print(i)
- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
- push_manager=context.request.resource_manager, push_manager=context.request.resource_manager,
- max_items_to_push=num_items, @@ -37,7 +37,7 @@
- batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
- ).push( ).push(
- # Only send the first n items. # Only send the first n items.
- items=items[:num_items] - items=items[:num_items]
- ) + items=items[:num_items],
+ # Another )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return ( return (
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
% (test.name, test.filename, lineno, lname, err) @@ -47,113 +47,46 @@
)
def omitting_trailers(self) -> None: def omitting_trailers(self) -> None:
- get_collection( get_collection(
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
- )[OneLevelIndex] - )[OneLevelIndex]
- get_collection( + )[
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + OneLevelIndex
+ ]
get_collection(
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] - )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex] + )[
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][ + OneLevelIndex
+ ][
+ TwoLevelIndex
+ ][
+ ThreeLevelIndex + ThreeLevelIndex
+ ][ + ][
+ FourLevelIndex + FourLevelIndex
@ -263,10 +235,11 @@ class C:
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
22 22
] ]
- assignment = ( assignment = (
- some.rather.elaborate.rule() and another.rule.ending_with.index[123] - some.rather.elaborate.rule() and another.rule.ending_with.index[123]
- ) + some.rather.elaborate.rule()
+ assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123] + and another.rule.ending_with.index[123]
)
def easy_asserts(self) -> None: def easy_asserts(self) -> None:
- assert { - assert {
@ -376,7 +349,7 @@ class C:
%3d 0 LOAD_FAST 1 (x) %3d 0 LOAD_FAST 1 (x)
2 LOAD_CONST 1 (1) 2 LOAD_CONST 1 (1)
4 COMPARE_OP 2 (==) 4 COMPARE_OP 2 (==)
@@ -161,21 +61,8 @@ @@ -161,21 +94,8 @@
8 STORE_ATTR 0 (x) 8 STORE_ATTR 0 (x)
10 LOAD_CONST 0 (None) 10 LOAD_CONST 0 (None)
12 RETURN_VALUE 12 RETURN_VALUE
@ -408,11 +381,24 @@ class C:
```py ```py
class C: class C:
def test(self) -> None: def test(self) -> None:
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): with patch("black.out", print):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) self.assertEqual(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 1 file left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
for i in (a,): for i in (a,):
if ( if (
# Rule 1 # Rule 1
@ -422,19 +408,36 @@ class C:
): ):
while ( while (
# Just a comment # Just a comment
NOT_IMPLEMENTED_call() call()
): ):
# Another # Another
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(i)
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
push_manager=context.request.resource_manager,
max_items_to_push=num_items,
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
).push(
# Only send the first n items.
items=items[:num_items],
)
return ( return (
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
% (test.name, test.filename, lineno, lname, err) % (test.name, test.filename, lineno, lname, err)
) )
def omitting_trailers(self) -> None: def omitting_trailers(self) -> None:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex] get_collection(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][ hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
)[
OneLevelIndex
]
get_collection(
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
)[
OneLevelIndex
][
TwoLevelIndex
][
ThreeLevelIndex ThreeLevelIndex
][ ][
FourLevelIndex FourLevelIndex
@ -442,7 +445,10 @@ class C:
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
22 22
] ]
assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123] assignment = (
some.rather.elaborate.rule()
and another.rule.ending_with.index[123]
)
def easy_asserts(self) -> None: def easy_asserts(self) -> None:
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert

View file

@ -193,69 +193,41 @@ class C:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,23 +1,10 @@ @@ -28,8 +28,8 @@
class C:
def test(self) -> None:
- with patch("black.out", print):
- self.assertEqual(
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
- )
- self.assertEqual(
- unstyle(str(report)),
- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
- )
- self.assertEqual(
- unstyle(str(report)),
- "2 files reformatted, 1 file left unchanged, 1 file failed to"
- " reformat.",
- )
- self.assertEqual(
- unstyle(str(report)),
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
- " reformat.",
- )
+ with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in (a,):
if (
# Rule 1
@@ -27,133 +14,46 @@
):
while ( while (
# Just a comment # Just a comment
- call() call()
- # Another + ):
+ NOT_IMPLEMENTED_call() # Another
): - ):
- print(i) print(i)
- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
- push_manager=context.request.resource_manager, push_manager=context.request.resource_manager,
- max_items_to_push=num_items, @@ -37,7 +37,7 @@
- batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
- ).push( ).push(
- # Only send the first n items. # Only send the first n items.
- items=items[:num_items] - items=items[:num_items]
- ) + items=items[:num_items],
+ # Another )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return ( return (
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
% (test.name, test.filename, lineno, lname, err) @@ -47,113 +47,46 @@
)
def omitting_trailers(self) -> None: def omitting_trailers(self) -> None:
- get_collection( get_collection(
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
- )[OneLevelIndex] - )[OneLevelIndex]
- get_collection( + )[
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True + OneLevelIndex
+ ]
get_collection(
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex] - )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex] + )[
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][ + OneLevelIndex
+ ][
+ TwoLevelIndex
+ ][
+ ThreeLevelIndex + ThreeLevelIndex
+ ][ + ][
+ FourLevelIndex + FourLevelIndex
@ -263,10 +235,11 @@ class C:
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
22 22
] ]
- assignment = ( assignment = (
- some.rather.elaborate.rule() and another.rule.ending_with.index[123] - some.rather.elaborate.rule() and another.rule.ending_with.index[123]
- ) + some.rather.elaborate.rule()
+ assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123] + and another.rule.ending_with.index[123]
)
def easy_asserts(self) -> None: def easy_asserts(self) -> None:
- assert { - assert {
@ -376,7 +349,7 @@ class C:
%3d 0 LOAD_FAST 1 (x) %3d 0 LOAD_FAST 1 (x)
2 LOAD_CONST 1 (1) 2 LOAD_CONST 1 (1)
4 COMPARE_OP 2 (==) 4 COMPARE_OP 2 (==)
@@ -161,21 +61,8 @@ @@ -161,21 +94,8 @@
8 STORE_ATTR 0 (x) 8 STORE_ATTR 0 (x)
10 LOAD_CONST 0 (None) 10 LOAD_CONST 0 (None)
12 RETURN_VALUE 12 RETURN_VALUE
@ -408,11 +381,24 @@ class C:
```py ```py
class C: class C:
def test(self) -> None: def test(self) -> None:
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): with patch("black.out", print):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) self.assertEqual(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 1 file left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
for i in (a,): for i in (a,):
if ( if (
# Rule 1 # Rule 1
@ -422,19 +408,36 @@ class C:
): ):
while ( while (
# Just a comment # Just a comment
NOT_IMPLEMENTED_call() call()
): ):
# Another # Another
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(i)
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
push_manager=context.request.resource_manager,
max_items_to_push=num_items,
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
).push(
# Only send the first n items.
items=items[:num_items],
)
return ( return (
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s' 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
% (test.name, test.filename, lineno, lname, err) % (test.name, test.filename, lineno, lname, err)
) )
def omitting_trailers(self) -> None: def omitting_trailers(self) -> None:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex] get_collection(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][ hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
)[
OneLevelIndex
]
get_collection(
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
)[
OneLevelIndex
][
TwoLevelIndex
][
ThreeLevelIndex ThreeLevelIndex
][ ][
FourLevelIndex FourLevelIndex
@ -442,7 +445,10 @@ class C:
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][ d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
22 22
] ]
assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123] assignment = (
some.rather.elaborate.rule()
and another.rule.ending_with.index[123]
)
def easy_asserts(self) -> None: def easy_asserts(self) -> None:
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert

View file

@ -104,7 +104,7 @@ def g():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -16,32 +16,40 @@ @@ -16,7 +16,7 @@
if t == token.COMMENT: # another trailing comment if t == token.COMMENT: # another trailing comment
return DOUBLESPACE return DOUBLESPACE
@ -113,9 +113,7 @@ def g():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
- prevp = preceding_leaf(p) @@ -25,23 +25,31 @@
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
if prevp.type == token.EQUAL: if prevp.type == token.EQUAL:
@ -169,7 +167,7 @@ def g():
def g(): def g():
NO = "" NO = ""
SPACE = " " SPACE = " "
@@ -67,11 +74,11 @@ @@ -67,7 +74,7 @@
return DOUBLESPACE return DOUBLESPACE
# Another comment because more comments # Another comment because more comments
@ -178,11 +176,6 @@ def g():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
- prevp = preceding_leaf(p)
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if not prevp or prevp.type in OPENING_BRACKETS:
# Start of the line or a bracketed expression.
@@ -79,11 +86,15 @@ @@ -79,11 +86,15 @@
return NO return NO
@ -233,7 +226,7 @@ def f():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) prevp = preceding_leaf(p)
if not prevp or prevp.type in OPENING_BRACKETS: if not prevp or prevp.type in OPENING_BRACKETS:
return NO return NO
@ -291,7 +284,7 @@ def g():
prev = leaf.prev_sibling prev = leaf.prev_sibling
if not prev: if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) prevp = preceding_leaf(p)
if not prevp or prevp.type in OPENING_BRACKETS: 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.

View file

@ -337,7 +337,7 @@ last_call()
() ()
(1,) (1,)
(1, 2) (1, 2)
@@ -68,60 +75,51 @@ @@ -68,40 +75,37 @@
2, 2,
3, 3,
] ]
@ -395,39 +395,19 @@ last_call()
+{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 Python3 > Python2 > COBOL
Life is Life Life is Life
-call() call()
-call(arg) @@ -116,8 +120,8 @@
-call(kwarg="hey") kwarg="hey",
-call(arg, kwarg="hey") **kwargs,
-call(arg, another, kwarg="hey", **kwargs) ) # note: no trailing comma pre-3.6
-call(
- this_is_a_very_long_variable_which_will_force_a_delimiter_split,
- arg,
- another,
- kwarg="hey",
- **kwargs,
-) # note: no trailing comma pre-3.6
-call(*gidgets[:2]) -call(*gidgets[:2])
-call(a, *gidgets[:2]) -call(a, *gidgets[:2])
-call(**self.screen_kwargs) +call(*NOT_YET_IMPLEMENTED_ExprStarred)
-call(b, **self.screen_kwargs) +call(a, *NOT_YET_IMPLEMENTED_ExprStarred)
+NOT_IMPLEMENTED_call() call(**self.screen_kwargs)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(b, **self.screen_kwargs)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # note: no trailing comma pre-3.6
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
lukasz.langa.pl lukasz.langa.pl
-call.me(maybe) @@ -130,34 +134,28 @@
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
(1).real
(1.0).real
....__class__
@@ -130,34 +128,28 @@
tuple[str, ...] tuple[str, ...]
tuple[str, int, float, dict[str, int]] tuple[str, int, float, dict[str, int]]
tuple[ tuple[
@ -475,7 +455,7 @@ last_call()
numpy[0, :] numpy[0, :]
numpy[:, i] numpy[:, i]
numpy[0, :2] numpy[0, :2]
@@ -171,25 +163,32 @@ @@ -171,20 +169,27 @@
numpy[1 : c + 1, c] numpy[1 : c + 1, c]
numpy[-(c + 1) :, d] numpy[-(c + 1) :, d]
numpy[:, l[-2]] numpy[:, l[-2]]
@ -511,34 +491,19 @@ last_call()
{ {
"id": "1", "id": "1",
"type": "type", "type": "type",
- "started_at": now(), @@ -199,32 +204,22 @@
- "ended_at": now() + timedelta(days=10),
+ "started_at": NOT_IMPLEMENTED_call(),
+ "ended_at": NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"priority": 1,
"import_session_id": 1,
**kwargs,
@@ -198,35 +197,21 @@
b = (1,)
c = 1 c = 1
d = (1,) + a + (2,) d = (1,) + a + (2,)
-e = (1,).count(1) e = (1,).count(1)
-f = 1, *range(10) -f = 1, *range(10)
-g = 1, *"ten" -g = 1, *"ten"
-what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
- vars_to_remove
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+f = 1, *NOT_YET_IMPLEMENTED_ExprStarred +f = 1, *NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, *NOT_YET_IMPLEMENTED_ExprStarred +g = 1, *NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = ( what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
+ (coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) vars_to_remove
+ + 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)
@ -558,16 +523,18 @@ last_call()
- ) - )
- .all() - .all()
-) -)
-Ø = set() +result = session.query(models.Customer.id).filter(
-authors.łukasz.say_thanks() + models.Customer.account_id == account_id, models.Customer.email == email_address
+result = NOT_IMPLEMENTED_call() +).order_by(models.Customer.id.asc()).all()
+result = NOT_IMPLEMENTED_call() +result = session.query(models.Customer.id).filter(
+Ø = NOT_IMPLEMENTED_call() + models.Customer.account_id == account_id, models.Customer.email == email_address
+NOT_IMPLEMENTED_call() +).order_by(
+ models.Customer.id.asc(),
+).all()
Ø = set()
authors.łukasz.say_thanks()
mapping = { mapping = {
A: 0.25 * (10.0 / 12), @@ -236,29 +231,27 @@
B: 0.1 * (10.0 / 12),
@@ -236,31 +221,29 @@
def gen(): def gen():
@ -582,8 +549,7 @@ last_call()
async def f(): async def f():
- await some.complicated[0].call(with_args=(True or (1 is not 1))) await some.complicated[0].call(with_args=(True or (1 is not 1)))
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-print(*[] or [1]) -print(*[] or [1])
@ -594,9 +560,9 @@ last_call()
- force=False - force=False
-), "Short message" -), "Short message"
-assert parens is TooMany -assert parens is TooMany
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +print(*NOT_YET_IMPLEMENTED_ExprStarred)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +print(**NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +print(*NOT_YET_IMPLEMENTED_ExprStarred)
+NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtAssert +NOT_YET_IMPLEMENTED_StmtAssert
@ -607,34 +573,9 @@ last_call()
-for z in (i for i in (1, 2, 3)): -for z in (i for i in (1, 2, 3)):
+for z in (i for i in []): +for z in (i for i in []):
... ...
-for i in call(): for i in call():
+for i in NOT_IMPLEMENTED_call():
... ...
for j in 1 + (2 + 3): @@ -327,13 +320,18 @@
...
@@ -272,7 +255,7 @@
addr_proto,
addr_canonname,
addr_sockaddr,
-) in socket.getaddrinfo("google.com", "http"):
+) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
pass
a = (
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
@@ -291,9 +274,9 @@
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
)
if (
- threading.current_thread() != threading.main_thread()
- and threading.current_thread() != threading.main_thread()
- or signal.getsignal(signal.SIGINT) != signal.default_int_handler
+ NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
+ and NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call()
+ or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) != signal.default_int_handler
):
return True
if (
@@ -327,13 +310,18 @@
): ):
return True return True
if ( if (
@ -656,7 +597,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 +329,8 @@ @@ -341,7 +339,8 @@
~aaaaaaaaaaaaaaaa.a ~aaaaaaaaaaaaaaaa.a
+ aaaaaaaaaaaaaaaa.b + aaaaaaaaaaaaaaaa.b
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
@ -666,13 +607,6 @@ last_call()
^ aaaaaaaaaaaaaaaa.i ^ aaaaaaaaaaaaaaaa.i
<< aaaaaaaaaaaaaaaa.k << aaaaaaaaaaaaaaaa.k
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
@@ -366,5 +355,5 @@
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
-last_call()
+NOT_IMPLEMENTED_call()
# standalone comment at ENDMARKER
``` ```
## Ruff Output ## Ruff Output
@ -788,18 +722,24 @@ NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false
{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 Python3 > Python2 > COBOL
Life is Life Life is Life
NOT_IMPLEMENTED_call() call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(kwarg="hey")
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(arg, kwarg="hey")
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(arg, another, kwarg="hey", **kwargs)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # note: no trailing comma pre-3.6 call(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) this_is_a_very_long_variable_which_will_force_a_delimiter_split,
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) arg,
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) another,
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) kwarg="hey",
**kwargs,
) # note: no trailing comma pre-3.6
call(*NOT_YET_IMPLEMENTED_ExprStarred)
call(a, *NOT_YET_IMPLEMENTED_ExprStarred)
call(**self.screen_kwargs)
call(b, **self.screen_kwargs)
lukasz.langa.pl lukasz.langa.pl
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call.me(maybe)
(1).real (1).real
(1.0).real (1.0).real
....__class__ ....__class__
@ -867,8 +807,8 @@ SomeName
{ {
"id": "1", "id": "1",
"type": "type", "type": "type",
"started_at": NOT_IMPLEMENTED_call(), "started_at": now(),
"ended_at": NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), "ended_at": now() + timedelta(days=10),
"priority": 1, "priority": 1,
"import_session_id": 1, "import_session_id": 1,
**kwargs, **kwargs,
@ -877,21 +817,25 @@ a = (1,)
b = (1,) b = (1,)
c = 1 c = 1
d = (1,) + a + (2,) d = (1,) + a + (2,)
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) e = (1,).count(1)
f = 1, *NOT_YET_IMPLEMENTED_ExprStarred f = 1, *NOT_YET_IMPLEMENTED_ExprStarred
g = 1, *NOT_YET_IMPLEMENTED_ExprStarred g = 1, *NOT_YET_IMPLEMENTED_ExprStarred
what_is_up_with_those_new_coord_names = ( what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
(coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) vars_to_remove
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
) )
what_is_up_with_those_new_coord_names = ( what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
(coord_names | NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) vars_to_remove
- NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
) )
result = NOT_IMPLEMENTED_call() result = session.query(models.Customer.id).filter(
result = NOT_IMPLEMENTED_call() models.Customer.account_id == account_id, models.Customer.email == email_address
Ø = NOT_IMPLEMENTED_call() ).order_by(models.Customer.id.asc()).all()
NOT_IMPLEMENTED_call() result = session.query(models.Customer.id).filter(
models.Customer.account_id == account_id, models.Customer.email == email_address
).order_by(
models.Customer.id.asc(),
).all()
Ø = set()
authors.łukasz.say_thanks()
mapping = { mapping = {
A: 0.25 * (10.0 / 12), A: 0.25 * (10.0 / 12),
B: 0.1 * (10.0 / 12), B: 0.1 * (10.0 / 12),
@ -908,12 +852,12 @@ def gen():
async def f(): async def f():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await some.complicated[0].call(with_args=(True or (1 is not 1)))
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(*NOT_YET_IMPLEMENTED_ExprStarred)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(**NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(*NOT_YET_IMPLEMENTED_ExprStarred)
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
@ -923,7 +867,7 @@ for y in ():
... ...
for z in (i for i in []): for z in (i for i in []):
... ...
for i in NOT_IMPLEMENTED_call(): for i in call():
... ...
for j in 1 + (2 + 3): for j in 1 + (2 + 3):
... ...
@ -935,7 +879,7 @@ for (
addr_proto, addr_proto,
addr_canonname, addr_canonname,
addr_sockaddr, addr_sockaddr,
) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): ) in socket.getaddrinfo("google.com", "http"):
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
@ -954,9 +898,9 @@ a = (
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
) )
if ( if (
NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call() threading.current_thread() != threading.main_thread()
and NOT_IMPLEMENTED_call() != NOT_IMPLEMENTED_call() and threading.current_thread() != threading.main_thread()
or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) != signal.default_int_handler or signal.getsignal(signal.SIGINT) != signal.default_int_handler
): ):
return True return True
if ( if (
@ -1035,7 +979,7 @@ bbbb >> bbbb * bbbb
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) )
NOT_IMPLEMENTED_call() last_call()
# standalone comment at ENDMARKER # standalone comment at ENDMARKER
``` ```

View file

@ -202,11 +202,11 @@ d={'a':1,
#!/usr/bin/env python3 #!/usr/bin/env python3
-import asyncio -import asyncio
-import sys -import sys
-
-from third_party import X, Y, Z
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
-from third_party import X, Y, Z
-
-from library import some_connection, some_decorator -from library import some_connection, some_decorator
+NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom
@ -240,10 +240,10 @@ d={'a':1,
+ NOT_YET_IMPLEMENTED_StmtRaise + NOT_YET_IMPLEMENTED_StmtRaise
+ if False: + if False:
+ ... + ...
+ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + for i in range(10):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + print(i)
+ continue + continue
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + exec("new-style exec", {}, {})
+ return None + return None
+ +
+ +
@ -254,7 +254,7 @@ d={'a':1,
- await asyncio.sleep(1) - await asyncio.sleep(1)
+ "Single-line docstring. Multiline is harder to reformat." + "Single-line docstring. Multiline is harder to reformat."
+ NOT_YET_IMPLEMENTED_StmtAsyncWith + NOT_YET_IMPLEMENTED_StmtAsyncWith
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + await asyncio.sleep(1)
+ +
+ +
@asyncio.coroutine @asyncio.coroutine
@ -264,7 +264,7 @@ d={'a':1,
-) -)
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str: -def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
- return text[number:-1] - return text[number:-1]
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +@some_decorator(with_args=True, many_args=[1, 2, 3])
+def function_signature_stress_test( +def function_signature_stress_test(
+ number: int, + number: int,
+ no_annotation=None, + no_annotation=None,
@ -291,12 +291,12 @@ d={'a':1,
+ h="", + h="",
+ i=r"", + i=r"",
+): +):
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + offset = attr.ib(default=attr.Factory(lambda x: True))
+ NOT_YET_IMPLEMENTED_StmtAssert + NOT_YET_IMPLEMENTED_StmtAssert
def spaces_types( def spaces_types(
@@ -51,68 +72,66 @@ @@ -51,7 +72,7 @@
d: dict = {}, d: dict = {},
e: bool = True, e: bool = True,
f: int = -1, f: int = -1,
@ -305,13 +305,7 @@ d={'a':1,
h: str = "", h: str = "",
i: str = r"", i: str = r"",
): ):
... @@ -64,55 +85,55 @@
-def spaces2(result=_core.Value(None)):
+def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
...
something = { something = {
# fmt: off # fmt: off
@ -381,11 +375,13 @@ d={'a':1,
- models.Customer.email == email_address)\ - models.Customer.email == email_address)\
- .order_by(models.Customer.id.asc())\ - .order_by(models.Customer.id.asc())\
- .all() - .all()
+ result = NOT_IMPLEMENTED_call() + result = session.query(models.Customer.id).filter(
+ models.Customer.account_id == account_id, models.Customer.email == email_address
+ ).order_by(models.Customer.id.asc()).all()
# fmt: on # fmt: on
@@ -133,10 +152,10 @@ @@ -133,10 +154,10 @@
"""Another known limitation.""" """Another known limitation."""
# fmt: on # fmt: on
# fmt: off # fmt: off
@ -393,92 +389,41 @@ d={'a':1,
- and_=indeed . it is not formatted - and_=indeed . it is not formatted
- 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 = should.not_be.formatted()
+ and_ = indeed.it is not formatted + and_ = indeed.it is not formatted
+ NOT_IMPLEMENTED_call() + because.the.handling.inside.generate_ignored_nodes()
+ now.considers.multiple.fmt.directives.within.one.prefix + now.considers.multiple.fmt.directives.within.one.prefix
# fmt: on # fmt: on
# fmt: off # fmt: off
# ...but comments still get reformatted even though they should not be # ...but comments still get reformatted even though they should not be
@@ -145,43 +164,11 @@ @@ -151,12 +172,10 @@
ast_args.kw_defaults,
def long_lines(): parameters,
if True: implicit_default=True,
- typedargslist.extend(
- gen_annotated_params(
- ast_args.kwonlyargs,
- ast_args.kw_defaults,
- parameters,
- implicit_default=True,
- ) - )
- ) + ),
- # fmt: off )
# fmt: off
- a = ( - a = (
- unnecessary_bracket() - unnecessary_bracket()
- ) - )
- # fmt: on + a = unnecessary_bracket()
- _type_comment_re = re.compile( # fmt: on
- r""" _type_comment_re = re.compile(
- ^ r"""
- [\t ]* @@ -179,7 +198,8 @@
- \#[ ]type:[ ]* $
- (?P<type> """,
- [^#\t\n]+?
- )
- (?<!ignore) # note: this will force the non-greedy + in <type> to match
- # a trailing space which is why we need the silliness below
- (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
- (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
- (?<!ignore[ ]{9})(?<!ignore[ ]{10})
- [\t ]*
- (?P<nl>
- (?:\#[^\n]*)?
- \n?
- )
- $
- """,
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# fmt: off # fmt: off
- re.MULTILINE|re.VERBOSE - re.MULTILINE|re.VERBOSE
+ a = NOT_IMPLEMENTED_call() + re.MULTILINE
+ | re.VERBOSE,
# fmt: on # fmt: on
- ) )
+ _type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@@ -217,8 +237,7 @@
def single_literal_yapf_disable(): xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
@@ -189,36 +176,9 @@ )
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
-cfg.rule(
- "Default",
- "address",
- xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
- xxxxxx="xx_xxxxx",
- xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- xxxxxxxxx_xxxx=True,
- xxxxxxxx_xxxxxxxxxx=False,
- xxxxxx_xxxxxx=2,
- xxxxxx_xxxxx_xxxxxxxx=70,
- xxxxxx_xxxxxx_xxxxx=True,
- # fmt: off
- xxxxxxx_xxxxxxxxxxxx={
- "xxxxxxxx": {
- "xxxxxx": False,
- "xxxxxxx": False,
- "xxxx_xxxxxx": "xxxxx",
- },
- "xxxxxxxx-xxxxx": {
- "xxxxxx": False,
- "xxxxxxx": True,
- "xxxx_xxxxxx": "xxxxxx",
- },
- },
- # fmt: on
- xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# fmt: off # fmt: off
-yield 'hello' -yield 'hello'
+NOT_YET_IMPLEMENTED_ExprYield +NOT_YET_IMPLEMENTED_ExprYield
@ -518,21 +463,21 @@ def func_no_args():
NOT_YET_IMPLEMENTED_StmtRaise NOT_YET_IMPLEMENTED_StmtRaise
if False: if False:
... ...
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(10):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(i)
continue continue
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) exec("new-style exec", {}, {})
return None return None
async def coroutine(arg, exec=False): async def coroutine(arg, exec=False):
"Single-line docstring. Multiline is harder to reformat." "Single-line docstring. Multiline is harder to reformat."
NOT_YET_IMPLEMENTED_StmtAsyncWith NOT_YET_IMPLEMENTED_StmtAsyncWith
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
@asyncio.coroutine @asyncio.coroutine
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @some_decorator(with_args=True, many_args=[1, 2, 3])
def function_signature_stress_test( def function_signature_stress_test(
number: int, number: int,
no_annotation=None, no_annotation=None,
@ -556,7 +501,7 @@ def spaces(
h="", h="",
i=r"", i=r"",
): ):
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) offset = attr.ib(default=attr.Factory(lambda x: True))
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
@ -574,7 +519,7 @@ def spaces_types(
... ...
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)): def spaces2(result=_core.Value(None)):
... ...
@ -626,7 +571,9 @@ def yield_expr():
def example(session): def example(session):
# fmt: off # fmt: off
result = NOT_IMPLEMENTED_call() result = session.query(models.Customer.id).filter(
models.Customer.account_id == account_id, models.Customer.email == email_address
).order_by(models.Customer.id.asc()).all()
# fmt: on # fmt: on
@ -647,9 +594,9 @@ def on_and_off_broken():
"""Another known limitation.""" """Another known limitation."""
# fmt: on # fmt: on
# fmt: off # fmt: off
this = NOT_IMPLEMENTED_call() this = should.not_be.formatted()
and_ = indeed.it is not formatted and_ = indeed.it is not formatted
NOT_IMPLEMENTED_call() because.the.handling.inside.generate_ignored_nodes()
now.considers.multiple.fmt.directives.within.one.prefix now.considers.multiple.fmt.directives.within.one.prefix
# fmt: on # fmt: on
# fmt: off # fmt: off
@ -659,11 +606,42 @@ def on_and_off_broken():
def long_lines(): def long_lines():
if True: if True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) typedargslist.extend(
gen_annotated_params(
ast_args.kwonlyargs,
ast_args.kw_defaults,
parameters,
implicit_default=True,
),
)
# fmt: off # fmt: off
a = NOT_IMPLEMENTED_call() a = unnecessary_bracket()
# fmt: on # fmt: on
_type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) _type_comment_re = re.compile(
r"""
^
[\t ]*
\#[ ]type:[ ]*
(?P<type>
[^#\t\n]+?
)
(?<!ignore) # note: this will force the non-greedy + in <type> to match
# a trailing space which is why we need the silliness below
(?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
(?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
(?<!ignore[ ]{9})(?<!ignore[ ]{10})
[\t ]*
(?P<nl>
(?:\#[^\n]*)?
\n?
)
$
""",
# fmt: off
re.MULTILINE
| re.VERBOSE,
# fmt: on
)
def single_literal_yapf_disable(): def single_literal_yapf_disable():
@ -671,7 +649,33 @@ def single_literal_yapf_disable():
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) cfg.rule(
"Default",
"address",
xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
xxxxxx="xx_xxxxx",
xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
xxxxxxxxx_xxxx=True,
xxxxxxxx_xxxxxxxxxx=False,
xxxxxx_xxxxxx=2,
xxxxxx_xxxxx_xxxxxxxx=70,
xxxxxx_xxxxxx_xxxxx=True,
# fmt: off
xxxxxxx_xxxxxxxxxxxx={
"xxxxxxxx": {
"xxxxxx": False,
"xxxxxxx": False,
"xxxx_xxxxxx": "xxxxx",
},
"xxxxxxxx-xxxxx": {
"xxxxxx": False,
"xxxxxxx": True,
"xxxx_xxxxxx": "xxxxxx",
},
},
# fmt: on
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
)
# fmt: off # fmt: off
NOT_YET_IMPLEMENTED_ExprYield NOT_YET_IMPLEMENTED_ExprYield
# No formatting to the end of the file # No formatting to the end of the file

View file

@ -52,7 +52,7 @@ def test_calculate_fades():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,40 +1,38 @@ @@ -1,40 +1,44 @@
-import pytest -import pytest
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
@ -68,11 +68,15 @@ def test_calculate_fades():
-@pytest.mark.parametrize('test', [ -@pytest.mark.parametrize('test', [
- -
- # Test don't manage the volume - # Test don't manage the volume
- [ +@pytest.mark.parametrize(
+ "test",
[
- ('stuff', 'in') - ('stuff', 'in')
- ], + # Test don't manage the volume
+ [("stuff", "in")],
],
-]) -])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +)
def test_fader(test): def test_fader(test):
pass pass
@ -120,7 +124,13 @@ TmEx = 2
# Test data: # Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @pytest.mark.parametrize(
"test",
[
# Test don't manage the volume
[("stuff", "in")],
],
)
def test_fader(test): def test_fader(test):
pass pass

View file

@ -25,27 +25,30 @@ def f(): pass
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,20 +1,10 @@ @@ -1,8 +1,12 @@
# fmt: off # fmt: off
-@test([ -@test([
- 1, 2, - 1, 2,
- 3, 4, - 3, 4,
-]) -])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +@test(
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ ],
+)
# fmt: on # fmt: on
def f(): def f():
pass pass
@@ -14,7 +18,7 @@
2,
-@test( 3,
- [ 4,
- 1,
- 2,
- 3,
- 4,
- ] - ]
-) + ],
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
def f(): def f():
pass pass
``` ```
@ -54,13 +57,27 @@ def f(): pass
```py ```py
# fmt: off # fmt: off
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @test(
[
1,
2,
3,
4,
],
)
# fmt: on # fmt: on
def f(): def f():
pass pass
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @test(
[
1,
2,
3,
4,
],
)
def f(): def f():
pass pass
``` ```

View file

@ -96,44 +96,27 @@ elif unformatted:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,33 +1,15 @@ @@ -5,8 +5,8 @@
# Regression test for https://github.com/psf/black/issues/3129. "console_scripts": [
-setup( "foo-bar"
- entry_points={ "=foo.bar.:main",
- # fmt: off
- "console_scripts": [
- "foo-bar"
- "=foo.bar.:main",
- # fmt: on - # fmt: on
- ] # Includes an formatted indentation. - ] # Includes an formatted indentation.
- }, + # fmt: on
-) + ], # Includes an formatted indentation.
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) },
)
# Regression test for https://github.com/psf/black/issues/2015.
-run(
- # fmt: off
- [
- "ls",
- "-la",
- ]
- # fmt: on
- + path,
- check=True,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@@ -27,7 +27,7 @@
# Regression test for https://github.com/psf/black/issues/3026. # Regression test for https://github.com/psf/black/issues/3026.
def test_func(): def test_func():
# yapf: disable # yapf: disable
- if unformatted( args ): - if unformatted( args ):
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + if unformatted(args):
return True return True
# yapf: enable # yapf: enable
elif b: elif b:
@@ -39,12 +21,12 @@ @@ -39,10 +39,10 @@
# Regression test for https://github.com/psf/black/issues/2567. # Regression test for https://github.com/psf/black/issues/2567.
if True: if True:
# fmt: off # fmt: off
@ -141,17 +124,14 @@ elif unformatted:
- # fmt: on - # fmt: on
- print ( "This won't be formatted" ) - print ( "This won't be formatted" )
- print ( "This won't be formatted either" ) - print ( "This won't be formatted either" )
+ for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + for _ in range(1):
+ # fmt: on + # fmt: on
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + print("This won't be formatted")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + print("This won't be formatted either")
else: else:
- print("This will be formatted") print("This will be formatted")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@@ -52,14 +52,12 @@
# Regression test for https://github.com/psf/black/issues/3184.
@@ -52,29 +34,27 @@
async def call(param): async def call(param):
if param: if param:
# fmt: off # fmt: off
@ -161,17 +141,15 @@ elif unformatted:
+ if param[0:4] in ("ABCD", "EFGH"): + if param[0:4] in ("ABCD", "EFGH"):
# fmt: on # fmt: on
- print ( "This won't be formatted" ) - print ( "This won't be formatted" )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + print("This won't be formatted")
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" )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + print("This won't be formatted either")
- print("This will be formatted") print("This will be formatted")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@@ -68,13 +66,13 @@
# Regression test for https://github.com/psf/black/issues/2985.
class Named(t.Protocol): class Named(t.Protocol):
# fmt: off # fmt: off
@property @property
@ -187,32 +165,49 @@ elif unformatted:
# fmt: on # fmt: on
@@ -82,6 +62,6 @@ @@ -82,6 +80,6 @@
if x: if x:
return x return x
# fmt: off # fmt: off
-elif unformatted: -elif unformatted:
+elif unformatted: +elif unformatted:
# fmt: on # fmt: on
- will_be_formatted() will_be_formatted()
+ NOT_IMPLEMENTED_call()
``` ```
## Ruff Output ## Ruff Output
```py ```py
# Regression test for https://github.com/psf/black/issues/3129. # Regression test for https://github.com/psf/black/issues/3129.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) setup(
entry_points={
# fmt: off
"console_scripts": [
"foo-bar"
"=foo.bar.:main",
# fmt: on
], # Includes an formatted indentation.
},
)
# Regression test for https://github.com/psf/black/issues/2015. # Regression test for https://github.com/psf/black/issues/2015.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) run(
# fmt: off
[
"ls",
"-la",
]
# fmt: on
+ path,
check=True,
)
# Regression test for https://github.com/psf/black/issues/3026. # Regression test for https://github.com/psf/black/issues/3026.
def test_func(): def test_func():
# yapf: disable # yapf: disable
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): if unformatted(args):
return True return True
# yapf: enable # yapf: enable
elif b: elif b:
@ -224,12 +219,12 @@ def test_func():
# Regression test for https://github.com/psf/black/issues/2567. # Regression test for https://github.com/psf/black/issues/2567.
if True: if True:
# fmt: off # fmt: off
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for _ in range(1):
# fmt: on # fmt: on
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This won't be formatted")
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This won't be formatted either")
else: else:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This will be formatted")
# Regression test for https://github.com/psf/black/issues/3184. # Regression test for https://github.com/psf/black/issues/3184.
@ -239,12 +234,12 @@ class A:
# fmt: off # fmt: off
if param[0:4] in ("ABCD", "EFGH"): if param[0:4] in ("ABCD", "EFGH"):
# fmt: on # fmt: on
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This won't be formatted")
elif param[0:4] in ("ZZZZ",): elif param[0:4] in ("ZZZZ",):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This won't be formatted either")
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("This will be formatted")
# Regression test for https://github.com/psf/black/issues/2985. # Regression test for https://github.com/psf/black/issues/2985.
@ -267,7 +262,7 @@ if x:
# fmt: off # fmt: off
elif unformatted: elif unformatted:
# fmt: on # fmt: on
NOT_IMPLEMENTED_call() will_be_formatted()
``` ```
## Black Output ## Black Output

View file

@ -21,7 +21,7 @@ else:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,9 +1,10 @@ @@ -1,7 +1,8 @@
a, b, c = 3, 4, 5 a, b, c = 3, 4, 5
if ( if (
a == 3 a == 3
@ -30,11 +30,7 @@ else:
+ != 9 # fmt: skip + != 9 # fmt: skip
and c is not None and c is not None
): ):
- print("I'm good!") print("I'm good!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else:
- print("I'm bad")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
@ -47,9 +43,9 @@ if (
!= 9 # fmt: skip != 9 # fmt: skip
and c is not None and c is not None
): ):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I'm good!")
else: else:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I'm bad")
``` ```
## Black Output ## Black Output

View file

@ -1,49 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py
---
## Input
```py
class A:
def f(self):
for line in range(10):
if True:
pass # fmt: skip
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,5 +1,5 @@
class A:
def f(self):
- for line in range(10):
+ for line in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if True:
pass # fmt: skip
```
## Ruff Output
```py
class A:
def f(self):
for line in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if True:
pass # fmt: skip
```
## Black Output
```py
class A:
def f(self):
for line in range(10):
if True:
pass # fmt: skip
```

View file

@ -77,65 +77,54 @@ async def test_async_with():
@@ -1,62 +1,55 @@ @@ -1,62 +1,55 @@
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
-def some_func( unformatted, args ): # fmt: skip -def some_func( unformatted, args ): # fmt: skip
- print("I am some_func")
+def some_func(unformatted, args): # fmt: skip +def some_func(unformatted, args): # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_func")
return 0 return 0
# Make sure this comment is not removed. # Make sure this comment is not removed.
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
-async def some_async_func( unformatted, args): # fmt: skip -async def some_async_func( unformatted, args): # fmt: skip
- print("I am some_async_func")
- await asyncio.sleep(1)
+async def some_async_func(unformatted, args): # fmt: skip +async def some_async_func(unformatted, args): # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_async_func")
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
-class SomeClass( Unformatted, SuperClasses ): # fmt: skip -class SomeClass( Unformatted, SuperClasses ): # fmt: skip
- def some_method( self, unformatted, args ): # fmt: skip - def some_method( self, unformatted, args ): # fmt: skip
- print("I am some_method")
+class SomeClass(Unformatted, SuperClasses): # fmt: skip +class SomeClass(Unformatted, SuperClasses): # fmt: skip
+ def some_method(self, unformatted, args): # fmt: skip + def some_method(self, unformatted, args): # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_method")
return 0 return 0
- async def some_async_method( self, unformatted, args ): # fmt: skip - async def some_async_method( self, unformatted, args ): # fmt: skip
- print("I am some_async_method")
- await asyncio.sleep(1)
+ async def some_async_method(self, unformatted, args): # fmt: skip + async def some_async_method(self, unformatted, args): # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_async_method")
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
-if unformatted_call( args ): # fmt: skip -if unformatted_call( args ): # fmt: skip
- print("First branch") +if unformatted_call(args): # fmt: skip
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip print("First branch")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Make sure this is not removed. # Make sure this is not removed.
-elif another_unformatted_call( args ): # fmt: skip -elif another_unformatted_call( args ): # fmt: skip
- print("Second branch") +elif another_unformatted_call(args): # fmt: skip
print("Second branch")
-else : # fmt: skip -else : # fmt: skip
- print("Last branch")
+elif NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+else: # fmt: skip +else: # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Last branch")
-while some_condition( unformatted, args ): # fmt: skip -while some_condition( unformatted, args ): # fmt: skip
- print("Do something") +while some_condition(unformatted, args): # fmt: skip
+while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip print("Do something")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-for i in some_iter( unformatted, args ): # fmt: skip -for i in some_iter( unformatted, args ): # fmt: skip
- print("Do something") +for i in some_iter(unformatted, args): # fmt: skip
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip print("Do something")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
async def test_async_for(): async def test_async_for():
@ -154,9 +143,8 @@ async def test_async_with():
-with give_me_context( unformatted, args ): # fmt: skip -with give_me_context( unformatted, args ): # fmt: skip
- print("Do something") +with give_me_context(unformatted, args): # fmt: skip
+with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip print("Do something")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
async def test_async_with(): async def test_async_with():
@ -170,44 +158,44 @@ async def test_async_with():
```py ```py
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
def some_func(unformatted, args): # fmt: skip def some_func(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_func")
return 0 return 0
# Make sure this comment is not removed. # Make sure this comment is not removed.
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
async def some_async_func(unformatted, args): # fmt: skip async def some_async_func(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_async_func")
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
class SomeClass(Unformatted, SuperClasses): # fmt: skip class SomeClass(Unformatted, SuperClasses): # fmt: skip
def some_method(self, unformatted, args): # fmt: skip def some_method(self, unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_method")
return 0 return 0
async def some_async_method(self, unformatted, args): # fmt: skip async def some_async_method(self, unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("I am some_async_method")
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
# Make sure a leading comment is not removed. # Make sure a leading comment is not removed.
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip if unformatted_call(args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("First branch")
# Make sure this is not removed. # Make sure this is not removed.
elif NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip elif another_unformatted_call(args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Second branch")
else: # fmt: skip else: # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Last branch")
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip while some_condition(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Do something")
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip for i in some_iter(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Do something")
async def test_async_for(): async def test_async_for():
@ -217,8 +205,8 @@ async def test_async_for():
NOT_YET_IMPLEMENTED_StmtTry NOT_YET_IMPLEMENTED_StmtTry
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip with give_me_context(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Do something")
async def test_async_with(): async def test_async_with():

View file

@ -107,7 +107,7 @@ def __await__(): return (yield)
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,12 +1,11 @@ @@ -1,20 +1,19 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
-import asyncio -import asyncio
-import sys -import sys
@ -118,14 +118,14 @@ def __await__(): return (yield)
+NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom
-from library import some_connection, some_decorator -from library import some_connection, some_decorator
-
-f"trigger 3.6 mode"
+NOT_YET_IMPLEMENTED_StmtImportFrom +NOT_YET_IMPLEMENTED_StmtImportFrom
+NOT_YET_IMPLEMENTED_ExprJoinedStr +NOT_YET_IMPLEMENTED_ExprJoinedStr
-f"trigger 3.6 mode"
-
def func_no_args(): def func_no_args():
@@ -14,25 +13,24 @@ a
b b
c c
if True: if True:
@ -133,31 +133,17 @@ def __await__(): return (yield)
+ NOT_YET_IMPLEMENTED_StmtRaise + NOT_YET_IMPLEMENTED_StmtRaise
if False: if False:
... ...
- for i in range(10): for i in range(10):
- print(i) @@ -26,8 +25,7 @@
+ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
continue
- exec("new-style exec", {}, {})
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return None
async def coroutine(arg, exec=False): async def coroutine(arg, exec=False):
"Single-line docstring. Multiline is harder to reformat." "Single-line docstring. Multiline is harder to reformat."
- async with some_connection() as conn: - async with some_connection() as conn:
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2) - await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
- await asyncio.sleep(1)
+ NOT_YET_IMPLEMENTED_StmtAsyncWith + NOT_YET_IMPLEMENTED_StmtAsyncWith
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
@asyncio.coroutine
-@some_decorator(with_args=True, many_args=[1, 2, 3])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def function_signature_stress_test(
number: int,
no_annotation=None,
@@ -41,12 +39,22 @@ @@ -41,12 +39,22 @@
debug: bool = False, debug: bool = False,
**kwargs, **kwargs,
@ -180,12 +166,12 @@ def __await__(): return (yield)
+ h="", + h="",
+ i=r"", + i=r"",
+): +):
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + offset = attr.ib(default=attr.Factory(lambda x: True))
+ NOT_YET_IMPLEMENTED_StmtAssert + NOT_YET_IMPLEMENTED_StmtAssert
def spaces_types( def spaces_types(
@@ -56,70 +64,26 @@ @@ -56,7 +64,7 @@
d: dict = {}, d: dict = {},
e: bool = True, e: bool = True,
f: int = -1, f: int = -1,
@ -194,12 +180,11 @@ def __await__(): return (yield)
h: str = "", h: str = "",
i: str = r"", i: str = r"",
): ):
... @@ -64,19 +72,16 @@
-def spaces2(result=_core.Value(None)): def spaces2(result=_core.Value(None)):
- assert fut is self._read_fut, (fut, self._read_fut) - assert fut is self._read_fut, (fut, self._read_fut)
+def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
+ NOT_YET_IMPLEMENTED_StmtAssert + NOT_YET_IMPLEMENTED_StmtAssert
@ -213,57 +198,44 @@ def __await__(): return (yield)
- .order_by(models.Customer.id.asc()) - .order_by(models.Customer.id.asc())
- .all() - .all()
- ) - )
+ result = NOT_IMPLEMENTED_call() + result = session.query(models.Customer.id).filter(
+ models.Customer.account_id
+ == account_id,
+ models.Customer.email
+ == email_address,
+ ).order_by(models.Customer.id.asc()).all()
def long_lines(): def long_lines():
if True: @@ -87,7 +92,7 @@
- typedargslist.extend( ast_args.kw_defaults,
- gen_annotated_params( parameters,
- ast_args.kwonlyargs, implicit_default=True,
- ast_args.kw_defaults,
- parameters,
- implicit_default=True,
- ) - )
- ) + ),
- typedargslist.extend( )
- gen_annotated_params( typedargslist.extend(
- ast_args.kwonlyargs, gen_annotated_params(
- ast_args.kw_defaults, @@ -96,7 +101,7 @@
- parameters, parameters,
- implicit_default=True, implicit_default=True,
- # trailing standalone comment # trailing standalone comment
- ) - )
- ) + ),
- _type_comment_re = re.compile( )
- r""" _type_comment_re = re.compile(
- ^ r"""
- [\t ]* @@ -118,7 +123,8 @@
- \#[ ]type:[ ]* )
- (?P<type> $
- [^#\t\n]+? """,
- )
- (?<!ignore) # note: this will force the non-greedy + in <type> to match
- # a trailing space which is why we need the silliness below
- (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
- (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
- (?<!ignore[ ]{9})(?<!ignore[ ]{10})
- [\t ]*
- (?P<nl>
- (?:\#[^\n]*)?
- \n?
- )
- $
- """,
- re.MULTILINE | re.VERBOSE, - re.MULTILINE | re.VERBOSE,
- ) + re.MULTILINE
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + | re.VERBOSE,
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
+ _type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def trailing_comma(): @@ -135,14 +141,8 @@
@@ -135,14 +99,8 @@
a, a,
**kwargs, **kwargs,
) -> A: ) -> A:
@ -303,21 +275,21 @@ def func_no_args():
NOT_YET_IMPLEMENTED_StmtRaise NOT_YET_IMPLEMENTED_StmtRaise
if False: if False:
... ...
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(10):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(i)
continue continue
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) exec("new-style exec", {}, {})
return None return None
async def coroutine(arg, exec=False): async def coroutine(arg, exec=False):
"Single-line docstring. Multiline is harder to reformat." "Single-line docstring. Multiline is harder to reformat."
NOT_YET_IMPLEMENTED_StmtAsyncWith NOT_YET_IMPLEMENTED_StmtAsyncWith
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
@asyncio.coroutine @asyncio.coroutine
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @some_decorator(with_args=True, many_args=[1, 2, 3])
def function_signature_stress_test( def function_signature_stress_test(
number: int, number: int,
no_annotation=None, no_annotation=None,
@ -340,7 +312,7 @@ def spaces(
h="", h="",
i=r"", i=r"",
): ):
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) offset = attr.ib(default=attr.Factory(lambda x: True))
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
@ -358,19 +330,61 @@ def spaces_types(
... ...
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)): def spaces2(result=_core.Value(None)):
NOT_YET_IMPLEMENTED_StmtAssert NOT_YET_IMPLEMENTED_StmtAssert
def example(session): def example(session):
result = NOT_IMPLEMENTED_call() result = session.query(models.Customer.id).filter(
models.Customer.account_id
== account_id,
models.Customer.email
== email_address,
).order_by(models.Customer.id.asc()).all()
def long_lines(): def long_lines():
if True: if True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) typedargslist.extend(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) gen_annotated_params(
_type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) ast_args.kwonlyargs,
ast_args.kw_defaults,
parameters,
implicit_default=True,
),
)
typedargslist.extend(
gen_annotated_params(
ast_args.kwonlyargs,
ast_args.kw_defaults,
parameters,
implicit_default=True,
# trailing standalone comment
),
)
_type_comment_re = re.compile(
r"""
^
[\t ]*
\#[ ]type:[ ]*
(?P<type>
[^#\t\n]+?
)
(?<!ignore) # note: this will force the non-greedy + in <type> to match
# a trailing space which is why we need the silliness below
(?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
(?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
(?<!ignore[ ]{9})(?<!ignore[ ]{10})
[\t ]*
(?P<nl>
(?:\#[^\n]*)?
\n?
)
$
""",
re.MULTILINE
| re.VERBOSE,
)
def trailing_comma(): def trailing_comma():

View file

@ -65,42 +65,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -2,17 +2,11 @@ @@ -32,34 +32,20 @@
a,
**kwargs,
) -> A:
- with cache_dir():
+ with NOT_IMPLEMENTED_call():
if something:
- result = CliRunner().invoke(
- black.main, [str(src1), str(src2), "--diff", "--check"]
- )
- limited.append(-limited.pop()) # negate top
- return A(
- very_long_argument_name1=very_long_value_for_the_argument,
- very_long_argument_name2=-very.long.value.for_the_argument,
- **kwargs,
- )
+ result = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def g():
@@ -21,45 +15,31 @@
def inner():
pass
- print("Inner defs should breathe a little.")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def h():
def inner():
pass
- print("Inner defs should breathe a little.")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if os.name == "posix": if os.name == "posix":
@ -116,28 +81,26 @@ 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
- + NOT_YET_IMPLEMENTED_StmtTry
- except ImportError: - except ImportError:
- -
- def i_should_be_followed_by_only_one_newline(): - def i_should_be_followed_by_only_one_newline():
- pass - pass
+ NOT_YET_IMPLEMENTED_StmtTry -
elif False: elif False:
- -
class IHopeYouAreHavingALovelyDay: class IHopeYouAreHavingALovelyDay:
def __call__(self): def __call__(self):
- print("i_should_be_followed_by_only_one_newline") print("i_should_be_followed_by_only_one_newline")
- -
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
else: else:
- -
def foo(): def foo():
pass pass
- -
-with hmm_but_this_should_get_two_preceding_newlines(): with hmm_but_this_should_get_two_preceding_newlines():
+with NOT_IMPLEMENTED_call():
pass pass
``` ```
@ -148,11 +111,17 @@ def f(
a, a,
**kwargs, **kwargs,
) -> A: ) -> A:
with NOT_IMPLEMENTED_call(): with cache_dir():
if something: if something:
result = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) result = CliRunner().invoke(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top black.main, [str(src1), str(src2), "--diff", "--check"]
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
limited.append(-limited.pop()) # negate top
return A(
very_long_argument_name1=very_long_value_for_the_argument,
very_long_argument_name2=-very.long.value.for_the_argument,
**kwargs,
)
def g(): def g():
@ -161,14 +130,14 @@ def g():
def inner(): def inner():
pass pass
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Inner defs should breathe a little.")
def h(): def h():
def inner(): def inner():
pass pass
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Inner defs should breathe a little.")
if os.name == "posix": if os.name == "posix":
@ -182,12 +151,12 @@ elif os.name == "nt":
elif False: elif False:
class IHopeYouAreHavingALovelyDay: class IHopeYouAreHavingALovelyDay:
def __call__(self): def __call__(self):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("i_should_be_followed_by_only_one_newline")
else: else:
def foo(): def foo():
pass pass
with NOT_IMPLEMENTED_call(): with hmm_but_this_should_get_two_preceding_newlines():
pass pass
``` ```

View file

@ -73,20 +73,16 @@ some_module.some_function(
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -24,18 +24,14 @@ @@ -27,7 +27,7 @@
def f( call(
a: int = 1, arg={
): "explode": "this",
- call(
- arg={
- "explode": "this",
- } - }
- ) + },
- call2( )
- arg=[1, 2, 3], call2(
- ) arg=[1, 2, 3],
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) @@ -35,7 +35,9 @@
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
x = { x = {
"a": 1, "a": 1,
"b": 2, "b": 2,
@ -97,7 +93,7 @@ some_module.some_function(
if ( if (
a a
== { == {
@@ -47,22 +43,24 @@ @@ -47,22 +49,24 @@
"f": 6, "f": 6,
"g": 7, "g": 7,
"h": 8, "h": 8,
@ -129,7 +125,7 @@ some_module.some_function(
} }
@@ -80,35 +78,16 @@ @@ -80,18 +84,14 @@
pass pass
@ -137,8 +133,9 @@ some_module.some_function(
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( - also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
- this_shouldn_t_get_a_trailing_comma_too - this_shouldn_t_get_a_trailing_comma_too
- ) - )
-): +def func() -> also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + this_shouldn_t_get_a_trailing_comma_too
):
pass pass
@ -146,29 +143,11 @@ some_module.some_function(
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black( - also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
- this_shouldn_t_get_a_trailing_comma_too - this_shouldn_t_get_a_trailing_comma_too
- ) - )
-): +def func() -> also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + this_shouldn_t_get_a_trailing_comma_too
):
pass pass
# Make sure inner one-element tuple won't explode
-some_module.some_function(
- argument1, (one_element_tuple,), argument4, argument5, argument6
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Inner trailing comma causes outer to explode
-some_module.some_function(
- argument1,
- (
- one,
- two,
- ),
- argument4,
- argument5,
- argument6,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
@ -200,8 +179,14 @@ def f2(
def f( def f(
a: int = 1, a: int = 1,
): ):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) call(
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) arg={
"explode": "this",
},
)
call2(
arg=[1, 2, 3],
)
x = { x = {
"a": 1, "a": 1,
"b": 2, "b": 2,
@ -254,19 +239,34 @@ def some_method_with_a_really_long_name(
pass pass
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): def func() -> also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
this_shouldn_t_get_a_trailing_comma_too
):
pass pass
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): def func() -> also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
this_shouldn_t_get_a_trailing_comma_too
):
pass pass
# Make sure inner one-element tuple won't explode # Make sure inner one-element tuple won't explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) some_module.some_function(
argument1, (one_element_tuple,), argument4, argument5, argument6
)
# Inner trailing comma causes outer to explode # Inner trailing comma causes outer to explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) some_module.some_function(
argument1,
(
one,
two,
),
argument4,
argument5,
argument6,
)
``` ```
## Black Output ## Black Output

View file

@ -75,84 +75,67 @@ return np.divide(
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -12,52 +12,45 @@ @@ -15,38 +15,38 @@
b = 5 ** f()
a = 5**~4
-b = 5 ** f()
+b = 5 ** NOT_IMPLEMENTED_call()
c = -(5**2) c = -(5**2)
d = 5 ** f["hi"] d = 5 ** f["hi"]
-e = lazy(lambda **kwargs: 5) -e = lazy(lambda **kwargs: 5)
-f = f() ** 5 +e = lazy(lambda x: True)
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) f = f() ** 5
+f = NOT_IMPLEMENTED_call() ** 5
g = a.b**c.d g = a.b**c.d
-h = 5 ** funcs.f() h = 5 ** funcs.f()
-i = funcs.f() ** 5 i = funcs.f() ** 5
-j = super().name ** 5 j = super().name ** 5
-k = [(2**idx, value) for idx, value in pairs] -k = [(2**idx, value) for idx, value in pairs]
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
+h = 5 ** NOT_IMPLEMENTED_call()
+i = NOT_IMPLEMENTED_call() ** 5
+j = NOT_IMPLEMENTED_call().name ** 5
+k = [i for i in []] +k = [i for i in []]
+l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
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)]
+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 []]
r = x**y r = x**y
a = 5.0**~4.0 a = 5.0**~4.0
-b = 5.0 ** f() b = 5.0 ** f()
+b = 5.0 ** NOT_IMPLEMENTED_call()
c = -(5.0**2.0) c = -(5.0**2.0)
d = 5.0 ** f["hi"] d = 5.0 ** f["hi"]
-e = lazy(lambda **kwargs: 5) -e = lazy(lambda **kwargs: 5)
-f = f() ** 5.0 +e = lazy(lambda x: True)
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) f = f() ** 5.0
+f = NOT_IMPLEMENTED_call() ** 5.0
g = a.b**c.d g = a.b**c.d
-h = 5.0 ** funcs.f() h = 5.0 ** funcs.f()
-i = funcs.f() ** 5.0 i = funcs.f() ** 5.0
-j = super().name ** 5.0 j = super().name ** 5.0
-k = [(2.0**idx, value) for idx, value in pairs] -k = [(2.0**idx, value) for idx, value in pairs]
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
+h = 5.0 ** NOT_IMPLEMENTED_call()
+i = NOT_IMPLEMENTED_call() ** 5.0
+j = NOT_IMPLEMENTED_call().name ** 5.0
+k = [i for i in []] +k = [i for i in []]
+l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
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)]
+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 []]
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) # WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
-if hasattr(view, "sum_of_weights"): @@ -55,9 +55,11 @@
- return np.divide( # type: ignore[no-any-return] view.variance, # type: ignore[union-attr]
- view.variance, # type: ignore[union-attr] view.sum_of_weights, # type: ignore[union-attr]
- view.sum_of_weights, # type: ignore[union-attr] out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr]
- out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr]
- where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr] - where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr]
- ) + where=view.sum_of_weights**2
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + > view.sum_of_weights_squared, # type: ignore[union-attr]
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) )
-return np.divide( return np.divide(
- where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore - where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore
-) + where=view.sum_of_weights_of_weight_long**2
+return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + > view.sum_of_weights_squared, # type: ignore
)
``` ```
## Ruff Output ## Ruff Output
@ -172,48 +155,57 @@ def function_dont_replace_spaces():
a = 5**~4 a = 5**~4
b = 5 ** NOT_IMPLEMENTED_call() b = 5 ** f()
c = -(5**2) c = -(5**2)
d = 5 ** f["hi"] d = 5 ** f["hi"]
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) e = lazy(lambda x: True)
f = NOT_IMPLEMENTED_call() ** 5 f = f() ** 5
g = a.b**c.d g = a.b**c.d
h = 5 ** NOT_IMPLEMENTED_call() h = 5 ** funcs.f()
i = NOT_IMPLEMENTED_call() ** 5 i = funcs.f() ** 5
j = NOT_IMPLEMENTED_call().name ** 5 j = super().name ** 5
k = [i for i in []] k = [i for i in []]
l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
m = [([2**63], [1, 2**63])] m = [([2**63], [1, 2**63])]
n = count <= 10**5 n = count <= 10**5
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) o = settings(max_examples=10**6)
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 []]
r = x**y r = x**y
a = 5.0**~4.0 a = 5.0**~4.0
b = 5.0 ** NOT_IMPLEMENTED_call() b = 5.0 ** f()
c = -(5.0**2.0) c = -(5.0**2.0)
d = 5.0 ** f["hi"] d = 5.0 ** f["hi"]
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) e = lazy(lambda x: True)
f = NOT_IMPLEMENTED_call() ** 5.0 f = f() ** 5.0
g = a.b**c.d g = a.b**c.d
h = 5.0 ** NOT_IMPLEMENTED_call() h = 5.0 ** funcs.f()
i = NOT_IMPLEMENTED_call() ** 5.0 i = funcs.f() ** 5.0
j = NOT_IMPLEMENTED_call().name ** 5.0 j = super().name ** 5.0
k = [i for i in []] k = [i for i in []]
l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
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 = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) o = settings(max_examples=10**6.0)
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 []]
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873) # WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): if hasattr(view, "sum_of_weights"):
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) return np.divide( # type: ignore[no-any-return]
view.variance, # type: ignore[union-attr]
view.sum_of_weights, # type: ignore[union-attr]
out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr]
where=view.sum_of_weights**2
> view.sum_of_weights_squared, # type: ignore[union-attr]
)
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) return np.divide(
where=view.sum_of_weights_of_weight_long**2
> view.sum_of_weights_squared, # type: ignore
)
``` ```
## Black Output ## Black Output

View file

@ -1,94 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py
---
## Input
```py
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source.
# Left hand side fits in a single line but will still be exploded by the
# magic trailing comma.
first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
arg1,
arg2,
)
# Make when when the left side of assignment plus the opening paren "... = (" is
# exactly line length limit + 1, it won't be split like that.
xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -9,13 +9,10 @@
m2,
),
third_value,
-) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
- arg1,
- arg2,
-)
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Make when when the left side of assignment plus the opening paren "... = (" is
# exactly line length limit + 1, it won't be split like that.
xxxxxxxxx_yyy_zzzzzzzz[
- xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
] = 1
```
## Ruff Output
```py
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source.
# Left hand side fits in a single line but will still be exploded by the
# magic trailing comma.
(
first_value,
(
m1,
m2,
),
third_value,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Make when when the left side of assignment plus the opening paren "... = (" is
# exactly line length limit + 1, it won't be split like that.
xxxxxxxxx_yyy_zzzzzzzz[
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg), NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
] = 1
```
## Black Output
```py
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source.
# Left hand side fits in a single line but will still be exploded by the
# magic trailing comma.
(
first_value,
(
m1,
m2,
),
third_value,
) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
arg1,
arg2,
)
# Make when when the left side of assignment plus the opening paren "... = (" is
# exactly line length limit + 1, it won't be split like that.
xxxxxxxxx_yyy_zzzzzzzz[
xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)
] = 1
```

View file

@ -93,31 +93,28 @@ async def main():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,66 +1,57 @@ @@ -1,4 +1,4 @@
-import asyncio -import asyncio
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
# Control example # Control example
async def main(): @@ -8,59 +8,70 @@
- await asyncio.sleep(1)
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Remove brackets for short coroutine/task # Remove brackets for short coroutine/task
async def main(): async def main():
- await asyncio.sleep(1) - await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) + await (asyncio.sleep(1))
async def main(): async def main():
- await asyncio.sleep(1) - await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) + await (asyncio.sleep(1))
async def main(): async def main():
- await asyncio.sleep(1) - await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) + await (asyncio.sleep(1))
# Check comments # Check comments
@ -125,7 +122,7 @@ async def main():
- await asyncio.sleep(1) # Hello - await asyncio.sleep(1) # Hello
+ ( + (
+ await # Hello + await # Hello
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + asyncio.sleep(1)
+ ) + )
@ -133,14 +130,14 @@ async def main():
- await asyncio.sleep(1) # Hello - await asyncio.sleep(1) # Hello
+ ( + (
+ await ( + await (
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello + asyncio.sleep(1) # Hello
+ ) + )
+ ) + )
async def main(): async def main():
- await asyncio.sleep(1) # Hello - await asyncio.sleep(1) # Hello
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello + await (asyncio.sleep(1)) # Hello
# Long lines # Long lines
@ -153,8 +150,17 @@ async def main():
- asyncio.sleep(1), - asyncio.sleep(1),
- asyncio.sleep(1), - asyncio.sleep(1),
- asyncio.sleep(1), - asyncio.sleep(1),
- ) + (
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + await asyncio.gather(
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ )
)
# Same as above but with magic trailing comma in function # Same as above but with magic trailing comma in function
@ -167,27 +173,27 @@ async def main():
- asyncio.sleep(1), - asyncio.sleep(1),
- asyncio.sleep(1), - asyncio.sleep(1),
- asyncio.sleep(1), - asyncio.sleep(1),
- ) + (
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + await asyncio.gather(
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ asyncio.sleep(1),
+ )
)
# Cr@zY Br@ck3Tz # Cr@zY Br@ck3Tz
async def main(): async def main():
- await black(1) - await black(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) + await (black(1))
# Keep brackets around non power operations and nested awaits # Keep brackets around non power operations and nested awaits
@@ -69,7 +60,7 @@ @@ -78,16 +89,16 @@
async def main():
- await (await asyncio.sleep(1))
+ await (await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
# It's awaits all the way down...
@@ -78,16 +69,16 @@
async def main(): async def main():
@ -197,12 +203,12 @@ async def main():
async def main(): async def main():
- await (await asyncio.sleep(1)) - await (await asyncio.sleep(1))
+ await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))) + await (await (asyncio.sleep(1)))
async def main(): async def main():
- await (await (await (await (await asyncio.sleep(1))))) - await (await (await (await (await asyncio.sleep(1)))))
+ await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))))) + await (await (await (await (await (asyncio.sleep(1))))))
async def main(): async def main():
@ -218,55 +224,75 @@ NOT_YET_IMPLEMENTED_StmtImport
# Control example # Control example
async def main(): async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) await asyncio.sleep(1)
# Remove brackets for short coroutine/task # Remove brackets for short coroutine/task
async def main(): async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) await (asyncio.sleep(1))
async def main(): async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) await (asyncio.sleep(1))
async def main(): async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) await (asyncio.sleep(1))
# Check comments # Check comments
async def main(): async def main():
( (
await # Hello await # Hello
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) asyncio.sleep(1)
) )
async def main(): async def main():
( (
await ( await (
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello asyncio.sleep(1) # Hello
) )
) )
async def main(): async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello await (asyncio.sleep(1)) # Hello
# Long lines # Long lines
async def main(): async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) (
await asyncio.gather(
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
)
)
# Same as above but with magic trailing comma in function # Same as above but with magic trailing comma in function
async def main(): async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) (
await asyncio.gather(
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
asyncio.sleep(1),
)
)
# Cr@zY Br@ck3Tz # Cr@zY Br@ck3Tz
async def main(): async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) await (black(1))
# Keep brackets around non power operations and nested awaits # Keep brackets around non power operations and nested awaits
@ -275,7 +301,7 @@ async def main():
async def main(): async def main():
await (await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) await (await asyncio.sleep(1))
# It's awaits all the way down... # It's awaits all the way down...
@ -288,11 +314,11 @@ async def main():
async def main(): async def main():
await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))) await (await (asyncio.sleep(1)))
async def main(): async def main():
await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))))) await (await (await (await (await (asyncio.sleep(1))))))
async def main(): async def main():

View file

@ -31,71 +31,56 @@ for (((((k, v))))) in d.items():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,27 +1,22 @@ @@ -5,7 +5,7 @@
# Only remove tuple brackets after `for`
-for k, v in d.items():
- print(k, v)
+for k, v in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Don't touch tuple brackets after `in` # Don't touch tuple brackets after `in`
for module in (core, _unicodefun): for module in (core, _unicodefun):
- if hasattr(module, "_verify_python3_env"): if hasattr(module, "_verify_python3_env"):
- module._verify_python3_env = lambda: None - module._verify_python3_env = lambda: None
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ module._verify_python3_env = lambda x: True + module._verify_python3_env = lambda x: True
# Brackets remain for long for loop lines # Brackets remain for long for loop lines
for ( for (
why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, @@ -17,9 +17,7 @@
i_dont_know_but_we_should_still_check_the_behaviour_if_they_do, for (
-) in d.items(): k,
- print(k, v) v,
+) in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-for (
- k,
- v,
-) in ( -) in (
- dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items() - dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items()
-): -):
- print(k, v) +) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
+for k, v in NOT_IMPLEMENTED_call(): print(k, v)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Test deeply nested brackets # Test deeply nested brackets
-for k, v in d.items():
- print(k, v)
+for k, v in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
```py ```py
# Only remove tuple brackets after `for` # Only remove tuple brackets after `for`
for k, v in NOT_IMPLEMENTED_call(): for k, v in d.items():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(k, v)
# Don't touch tuple brackets after `in` # Don't touch tuple brackets after `in`
for module in (core, _unicodefun): for module in (core, _unicodefun):
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): if hasattr(module, "_verify_python3_env"):
module._verify_python3_env = lambda x: True module._verify_python3_env = lambda x: True
# Brackets remain for long for loop lines # Brackets remain for long for loop lines
for ( for (
why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long,
i_dont_know_but_we_should_still_check_the_behaviour_if_they_do, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do,
) in NOT_IMPLEMENTED_call(): ) in d.items():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(k, v)
for k, v in NOT_IMPLEMENTED_call(): for (
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) k,
v,
) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
print(k, v)
# Test deeply nested brackets # Test deeply nested brackets
for k, v in NOT_IMPLEMENTED_call(): for k, v in d.items():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(k, v)
``` ```
## Black Output ## Black Output

View file

@ -120,116 +120,32 @@ with open("/path/to/file.txt", mode="r") as read_file:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,78 +1,78 @@ @@ -1,4 +1,4 @@
-import random -import random
+NOT_YET_IMPLEMENTED_StmtImport +NOT_YET_IMPLEMENTED_StmtImport
def foo1(): def foo1():
- print("The newline above me should be deleted!") @@ -27,16 +27,16 @@
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def foo2(): for i in range(5):
- print("All the newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def foo3():
- print("No newline above me!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
- print("There is a newline above me, and that's OK!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def foo4():
# There is a comment here
- print("The newline above me should not be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
class Foo:
def bar(self):
- print("The newline above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-for i in range(5):
- print(f"{i}) The line above me should be removed!") - print(f"{i}) The line above me should be removed!")
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-for i in range(5): for i in range(5):
- print(f"{i}) The lines above me should be removed!") - print(f"{i}) The lines above me should be removed!")
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-for i in range(5): for i in range(5):
- for j in range(7): for j in range(7):
- print(f"{i}) The lines above me should be removed!") - print(f"{i}) The lines above me should be removed!")
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
+ for j in 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 line above me is about to be removed!")
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-if random.randint(0, 3) == 0:
- print("The new lines above me is about to be removed!")
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-if random.randint(0, 3) == 0:
- if random.uniform(0, 1) > 0.5:
- print("Two lines above me are about to be removed!")
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) > 0.5:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
while True:
- print("The newline above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
while True:
- print("The newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
while True:
while False:
- print("The newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-with open("/path/to/file.txt", mode="w") as file:
- file.write("The new line above me is about to be removed!")
+with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as file:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-with open("/path/to/file.txt", mode="w") as file:
- file.write("The new lines above me is about to be removed!")
+with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as file:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-with open("/path/to/file.txt", mode="r") as read_file:
- with open("/path/to/output_file.txt", mode="w") as write_file:
- write_file.writelines(read_file.readlines())
+with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as read_file:
+ with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as write_file:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
``` ```
## Ruff Output ## Ruff Output
@ -239,80 +155,80 @@ NOT_YET_IMPLEMENTED_StmtImport
def foo1(): def foo1():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newline above me should be deleted!")
def foo2(): def foo2():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("All the newlines above me should be deleted!")
def foo3(): def foo3():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("No newline above me!")
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("There is a newline above me, and that's OK!")
def foo4(): def foo4():
# There is a comment here # There is a comment here
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newline above me should not be deleted!")
class Foo: class Foo:
def bar(self): def bar(self):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newline above me should be deleted!")
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(5):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(5):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for i in range(5):
for j in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for j in range(7):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print(NOT_YET_IMPLEMENTED_ExprJoinedStr)
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0: if random.randint(0, 3) == 0:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The new line above me is about to be removed!")
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0: if random.randint(0, 3) == 0:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The new lines above me is about to be removed!")
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0: if random.randint(0, 3) == 0:
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) > 0.5: if random.uniform(0, 1) > 0.5:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Two lines above me are about to be removed!")
while True: while True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newline above me should be deleted!")
while True: while True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newlines above me should be deleted!")
while True: while True:
while False: while False:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("The newlines above me should be deleted!")
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as file: with open("/path/to/file.txt", mode="w") as file:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) file.write("The new line above me is about to be removed!")
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as file: with open("/path/to/file.txt", mode="w") as file:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) file.write("The new lines above me is about to be removed!")
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as read_file: with open("/path/to/file.txt", mode="r") as read_file:
with NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) as write_file: with open("/path/to/output_file.txt", mode="w") as write_file:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) write_file.writelines(read_file.readlines())
``` ```
## Black Output ## Black Output

View file

@ -67,15 +67,7 @@ def example8():
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,20 +1,12 @@ @@ -8,13 +8,7 @@
x = 1
x = 1.2
-data = (
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
-).encode()
+data = NOT_IMPLEMENTED_call()
async def show_status(): async def show_status():
while True: while True:
@ -90,7 +82,7 @@ def example8():
def example(): def example():
@@ -30,15 +22,11 @@ @@ -30,15 +24,11 @@
def example2(): def example2():
@ -108,7 +100,7 @@ def example8():
def example4(): def example4():
@@ -50,35 +38,11 @@ @@ -50,35 +40,11 @@
def example6(): def example6():
@ -154,7 +146,9 @@ def example8():
x = 1 x = 1
x = 1.2 x = 1.2
data = NOT_IMPLEMENTED_call() data = (
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
).encode()
async def show_status(): async def show_status():

View file

@ -59,7 +59,7 @@ func(
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,25 +1,39 @@ @@ -1,25 +1,58 @@
# We should not remove the trailing comma in a single-element subscript. # We should not remove the trailing comma in a single-element subscript.
-a: tuple[int,] -a: tuple[int,]
-b = tuple[int,] -b = tuple[int,]
@ -95,10 +95,20 @@ func(
# Trailing commas in multiple chained non-nested parens. # Trailing commas in multiple chained non-nested parens.
-zero(one).two(three).four(five) -zero(one).two(three).four(five)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +zero(
+ one,
+).two(
+ three,
+).four(
+ five,
+)
-func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5) -func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +func1(arg1).func2(
+ arg2,
+).func3(arg3).func4(
+ arg4,
+).func5(arg5)
-(a, b, c, d) = func1(arg1) and func2(arg2) -(a, b, c, d) = func1(arg1) and func2(arg2)
+( +(
@ -106,10 +116,19 @@ func(
+ b, + b,
+ c, + c,
+ d, + d,
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +) = func1(arg1) and func2(arg2)
-func(argument1, (one, two), argument4, argument5, argument6) -func(argument1, (one, two), argument4, argument5, argument6)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +func(
+ argument1,
+ (
+ one,
+ two,
+ ),
+ argument4,
+ argument5,
+ argument6,
+)
``` ```
## Ruff Output ## Ruff Output
@ -142,18 +161,37 @@ set_of_types = {tuple[(int,)]}
small_tuple = (1,) small_tuple = (1,)
# Trailing commas in multiple chained non-nested parens. # Trailing commas in multiple chained non-nested parens.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) zero(
one,
).two(
three,
).four(
five,
)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) func1(arg1).func2(
arg2,
).func3(arg3).func4(
arg4,
).func5(arg5)
( (
a, a,
b, b,
c, c,
d, d,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) ) = func1(arg1) and func2(arg2)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) func(
argument1,
(
one,
two,
),
argument4,
argument5,
argument6,
)
``` ```
## Black Output ## Black Output

View file

@ -75,7 +75,7 @@ x[
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -4,30 +4,35 @@ @@ -4,30 +4,30 @@
slice[d::d] slice[d::d]
slice[0] slice[0]
slice[-1] slice[-1]
@ -111,16 +111,11 @@ x[
ham[lower:upper], ham[lower:upper:], ham[lower::step] ham[lower:upper], ham[lower:upper:], ham[lower::step]
# ham[lower+offset : upper+offset] # ham[lower+offset : upper+offset]
-ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)] -ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
+( +ham[ : upper_fn(x) : step_fn(x)], ham[ :: step_fn(x)]
+ ham[
+ : NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) : NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ ],
+ ham[ :: NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)],
+)
ham[lower + offset : upper + offset] ham[lower + offset : upper + offset]
slice[::, ::] slice[::, ::]
@@ -50,10 +55,14 @@ @@ -50,10 +50,14 @@
slice[ slice[
# A # A
1 1
@ -172,12 +167,7 @@ async def f():
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:] ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step] ham[lower:upper], ham[lower:upper:], ham[lower::step]
# ham[lower+offset : upper+offset] # ham[lower+offset : upper+offset]
( ham[ : upper_fn(x) : step_fn(x)], ham[ :: step_fn(x)]
ham[
: NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) : NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
],
ham[ :: NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)],
)
ham[lower + offset : upper + offset] ham[lower + offset : upper + offset]
slice[::, ::] slice[::, ::]

View file

@ -64,16 +64,14 @@ assert (
importA importA
0 0
@@ -24,35 +14,34 @@ @@ -25,34 +15,33 @@
class A: class A:
def foo(self): def foo(self):
- for _ in range(10): for _ in range(10):
- aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( - aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(
- xxxxxxxxxxxx - xxxxxxxxxxxx
- ) # pylint: disable=no-member - ) # pylint: disable=no-member
+ for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): + aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(xxxxxxxxxxxx) # pylint: disable=no-member
+ aaaaaaaaaaaaaaaaaaa = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def test(self, othr): def test(self, othr):
@ -146,8 +144,8 @@ importA
class A: class A:
def foo(self): def foo(self):
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): for _ in range(10):
aaaaaaaaaaaaaaaaaaa = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(xxxxxxxxxxxx) # pylint: disable=no-member
def test(self, othr): def test(self, othr):

View file

@ -37,7 +37,7 @@ class A:
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,34 +1,32 @@ @@ -1,18 +1,16 @@
-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,
@ -45,7 +45,7 @@ class A:
+if ( +if (
+ e1234123412341234.winerror + e1234123412341234.winerror
+ not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY) + not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
+ or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + or _check_timeout(t)
+): +):
pass pass
@ -58,20 +58,14 @@ class A:
- ) - )
- + 1 - + 1
- ) - )
+ new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1 + new_id = max(
+ Vegetable.objects.order_by("-id")[0].id,
+ Mineral.objects.order_by("-id")[0].id,
+ ) + 1
class X: class X:
def get_help_text(self): @@ -26,9 +24,14 @@
- return ngettext(
- "Your password must contain at least %(min_length)d character.",
- "Your password must contain at least %(min_length)d characters.",
- self.min_length,
- ) % {"min_length": self.min_length}
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
+ "min_length": self.min_length,
+ }
class A: class A:
def b(self): def b(self):
@ -99,20 +93,25 @@ class A:
if ( if (
e1234123412341234.winerror e1234123412341234.winerror
not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY) not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) or _check_timeout(t)
): ):
pass pass
if x: if x:
if y: if y:
new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1 new_id = max(
Vegetable.objects.order_by("-id")[0].id,
Mineral.objects.order_by("-id")[0].id,
) + 1
class X: class X:
def get_help_text(self): def get_help_text(self):
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % { return ngettext(
"min_length": self.min_length, "Your password must contain at least %(min_length)d character.",
} "Your password must contain at least %(min_length)d characters.",
self.min_length,
) % {"min_length": self.min_length}
class A: class A:

View file

@ -22,8 +22,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_call() >= (8, 6, 0, "final") + e123456.get_tk_patchlevel() >= (8, 6, 0, "final")
+ or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6) + or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)
+): +):
pass pass
``` ```
@ -32,8 +32,8 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
```py ```py
if ( if (
NOT_IMPLEMENTED_call() >= (8, 6, 0, "final") e123456.get_tk_patchlevel() >= (8, 6, 0, "final")
or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6) or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)
): ):
pass pass
``` ```

View file

@ -1,63 +0,0 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py
---
## Input
```py
if True:
if True:
if True:
return _(
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
) % {"reported_username": reported_username, "report_reason": report_reason}
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,8 +1,7 @@
if True:
if True:
if True:
- return _(
- "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
- + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
- "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
- ) % {"reported_username": reported_username, "report_reason": report_reason}
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
+ "reported_username": reported_username,
+ "report_reason": report_reason,
+ }
```
## Ruff Output
```py
if True:
if True:
if True:
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
"reported_username": reported_username,
"report_reason": report_reason,
}
```
## Black Output
```py
if True:
if True:
if True:
return _(
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
) % {"reported_username": reported_username, "report_reason": report_reason}
```

View file

@ -45,47 +45,29 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
```diff ```diff
--- Black --- Black
+++ Ruff +++ Ruff
@@ -1,50 +1,26 @@ @@ -20,9 +20,7 @@
-zero(
- one,
-).two(
- three,
-).four(
- five,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-func1(arg1).func2(
- arg2,
-).func3(arg3).func4(
- arg4,
-).func5(arg5)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
# Inner one-element tuple shouldn't explode
-func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
(
a,
b, b,
c, c,
d, d,
-) = func1( -) = func1(
- arg1 - arg1
-) and func2(arg2) -) and func2(arg2)
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +) = func1(arg1) and func2(arg2)
# Example from https://github.com/psf/black/issues/3229 # Example from https://github.com/psf/black/issues/3229
def refresh_token(self, device_family, refresh_token, api_key): @@ -32,19 +30,18 @@
- return self.orchestration.refresh_token( "refreshToken": refresh_token,
- data={ },
- "refreshToken": refresh_token, api_key=api_key,
- },
- api_key=api_key,
- )["extensions"]["sdk"]["token"] - )["extensions"]["sdk"]["token"]
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)["extensions"]["sdk"]["token"] + )[
+ "extensions"
+ ][
+ "sdk"
+ ][
+ "token"
+ ]
# Edge case where a bug in a working-in-progress version of # Edge case where a bug in a working-in-progress version of
@ -108,24 +90,45 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
## Ruff Output ## Ruff Output
```py ```py
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) zero(
one,
).two(
three,
).four(
five,
)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) func1(arg1).func2(
arg2,
).func3(arg3).func4(
arg4,
).func5(arg5)
# Inner one-element tuple shouldn't explode # Inner one-element tuple shouldn't explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
( (
a, a,
b, b,
c, c,
d, d,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) ) = func1(arg1) and func2(arg2)
# Example from https://github.com/psf/black/issues/3229 # Example from https://github.com/psf/black/issues/3229
def refresh_token(self, device_family, refresh_token, api_key): def refresh_token(self, device_family, refresh_token, api_key):
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)["extensions"]["sdk"]["token"] return self.orchestration.refresh_token(
data={
"refreshToken": refresh_token,
},
api_key=api_key,
)[
"extensions"
][
"sdk"
][
"token"
]
# Edge case where a bug in a working-in-progress version of # Edge case where a bug in a working-in-progress version of

View file

@ -28,10 +28,9 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
# This is as well. # This is as well.
-(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") -(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
+(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) +(this_will_be_wrapped_in_parens,) = struct.unpack(b"NOT_YET_IMPLEMENTED_BYTE_STRING")
-(a,) = call() (a,) = call()
+(a,) = NOT_IMPLEMENTED_call()
``` ```
## Ruff Output ## Ruff Output
@ -46,9 +45,9 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
) = 1, 2, 3 ) = 1, 2, 3
# This is as well. # This is as well.
(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) (this_will_be_wrapped_in_parens,) = struct.unpack(b"NOT_YET_IMPLEMENTED_BYTE_STRING")
(a,) = NOT_IMPLEMENTED_call() (a,) = call()
``` ```
## Black Output ## Black Output

View file

@ -113,31 +113,30 @@ x53 = (
```py ```py
NOT_YET_IMPLEMENTED_StmtImportFrom NOT_YET_IMPLEMENTED_StmtImportFrom
a = NOT_IMPLEMENTED_call() a = Namespace()
( (
a a.
# comment # comment
.b # trailing comment b # trailing comment
) )
( (
a a.
# comment # comment
.b # trailing dot comment # trailing identifier comment b # trailing dot comment # trailing identifier comment
) )
( (
a a.
# comment # comment
.b # trailing identifier comment b # trailing identifier comment
) )
( (
a a.
# comment # comment
.
# in between # in between
b # trailing dot comment # trailing identifier comment b # trailing dot comment # trailing identifier comment
) )
@ -150,9 +149,8 @@ a.aaaaaaaaaaaaaaaaaaaaa.lllllllllllllllllllllllllllloooooooooong.chaaaaaaaaaaaaa
# chain if and only if we need them, that is if there are own line comments inside # chain if and only if we need them, that is if there are own line comments inside
# the chain. # the chain.
x1 = ( x1 = (
a.b a.b.
# comment 1 # comment 1
.
# comment 3 # comment 3
c.d # comment 2 c.d # comment 2
) )
@ -163,15 +161,15 @@ x21 = (
a.b # trailing name end-of-line a.b # trailing name end-of-line
) )
x22 = ( x22 = (
a a.
# outermost leading own line # outermost leading own line
.b # outermost trailing end-of-line b # outermost trailing end-of-line
) )
x31 = ( x31 = (
a a.
# own line between nodes 1 # own line between nodes 1
.b b
) )
x321 = a.b # end-of-line dot comment x321 = a.b # end-of-line dot comment
x322 = a.b.c # end-of-line dot comment 2 x322 = a.b.c # end-of-line dot comment 2
@ -181,9 +179,9 @@ x331 = (
b b
) )
x332 = ( x332 = (
"" "".
# own line between nodes # own line between nodes
.find find
) )
x8 = (a + a).b x8 = (a + a).b

View file

@ -217,7 +217,9 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}:
# Black breaks the right side first for the following expressions: # Black breaks the right side first for the following expressions:
aaaaaaaaaaaaaa + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) aaaaaaaaaaaaaa + caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal(
argument1, argument2, argument3
)
aaaaaaaaaaaaaa + [ aaaaaaaaaaaaaa + [
bbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbb,
ccccccccccccccccccccc, ccccccccccccccccccccc,
@ -438,10 +440,10 @@ if (
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py # Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py
for ( for user_id in set(
user_id target_user_ids
) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) - {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}: ) - {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) updates.append(UserPresenceState.default(user_id))
``` ```

View file

@ -78,17 +78,17 @@ if (
and self._returncode and self._returncode
# 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_call() and self._proc.poll()
): ):
pass pass
if ( if (
self._proc self._proc
and self._returncode and self._returncode
and NOT_IMPLEMENTED_call() and self._proc.poll()
and self._proc and self._proc
and self._returncode and self._returncode
and NOT_IMPLEMENTED_call() and self._proc.poll()
): ):
... ...

View file

@ -159,17 +159,17 @@ def a():
e00 = "e"[:] e00 = "e"[:]
e01 = "e"[:1] e01 = "e"[:1]
e02 = "e"[ : NOT_IMPLEMENTED_call()] e02 = "e"[ : a()]
e10 = "e"[1:] e10 = "e"[1:]
e11 = "e"[1:1] e11 = "e"[1:1]
e12 = "e"[1 : NOT_IMPLEMENTED_call()] e12 = "e"[1 : a()]
e20 = "e"[NOT_IMPLEMENTED_call() :] e20 = "e"[a() :]
e21 = "e"[NOT_IMPLEMENTED_call() : 1] e21 = "e"[a() : 1]
e22 = "e"[NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()] e22 = "e"[a() : a()]
e200 = "e"[NOT_IMPLEMENTED_call() : :] e200 = "e"[a() : :]
e201 = "e"[NOT_IMPLEMENTED_call() :: 1] e201 = "e"[a() :: 1]
e202 = "e"[NOT_IMPLEMENTED_call() :: NOT_IMPLEMENTED_call()] e202 = "e"[a() :: a()]
e210 = "e"[NOT_IMPLEMENTED_call() : 1 :] e210 = "e"[a() : 1 :]
``` ```

View file

@ -0,0 +1,175 @@
---
source: crates/ruff_python_formatter/tests/fixtures.rs
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/call.py
---
## Input
```py
from unittest.mock import MagicMock
def f(*args, **kwargs):
pass
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd = 1
session = MagicMock()
models = MagicMock()
f()
f(1)
f(x=2)
f(1, x=2)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd
)
f(
this_is_a_very_long_keyword_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd=1
)
f(
1,
mixed_very_long_arguments=1,
)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd,
these_arguments_have_values_that_need_to_break_because_they_are_too_long1=(100000 - 100000000000),
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad" + "asdfasdfa",
these_arguments_have_values_that_need_to_break_because_they_are_too_long3=session,
)
f(
# dangling comment
)
f(
only=1, short=1, arguments=1
)
f(
hey_this_is_a_long_call, it_has_funny_attributes_that_breaks_into_three_lines=1
)
f(
hey_this_is_a_very_long_call=1, it_has_funny_attributes_asdf_asdf=1, too_long_for_the_line=1, really=True
)
# TODO(konstin): Call chains/fluent interface (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#call-chains)
result = (
session.query(models.Customer.id)
.filter(
models.Customer.account_id == 10000,
models.Customer.email == "user@example.org",
)
.order_by(models.Customer.id.asc())
.all()
)
# TODO(konstin): Black has this special case for comment placement where everything stays in one line
f(
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa"
)
f(
session,
b=1,
** # oddly placed end-of-line comment
dict()
)
f(
session,
b=1,
**
# oddly placed own line comment
dict()
)
```
## Output
```py
NOT_YET_IMPLEMENTED_StmtImportFrom
def f(*args, **kwargs):
pass
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd = 1
session = MagicMock()
models = MagicMock()
f()
f(1)
f(x=2)
f(1, x=2)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd,
)
f(
this_is_a_very_long_keyword_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd=1,
)
f(
1,
mixed_very_long_arguments=1,
)
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd,
these_arguments_have_values_that_need_to_break_because_they_are_too_long1=(
100000
- 100000000000
),
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad"
+ "asdfasdfa",
these_arguments_have_values_that_need_to_break_because_they_are_too_long3=session,
)
f()
# dangling comment
f(only=1, short=1, arguments=1)
f(hey_this_is_a_long_call, it_has_funny_attributes_that_breaks_into_three_lines=1)
f(
hey_this_is_a_very_long_call=1,
it_has_funny_attributes_asdf_asdf=1,
too_long_for_the_line=1,
really=True,
)
# TODO(konstin): Call chains/fluent interface (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#call-chains)
result = session.query(models.Customer.id).filter(
models.Customer.account_id
== 10000,
models.Customer.email
== "user@example.org",
).order_by(models.Customer.id.asc()).all()
# TODO(konstin): Black has this special case for comment placement where everything stays in one line
f("aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa")
f(
session,
b=1,
**dict(), # oddly placed end-of-line comment
)
f(
session,
b=1,
**dict(),
# oddly placed own line comment
)
```

View file

@ -59,16 +59,16 @@ while (
else: else:
... ...
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and anotherCondition or aThirdCondition: # comment while some_condition(unformatted, args) and anotherCondition or aThirdCondition: # comment
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Do something")
while ( while (
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # trailing some condition some_condition(unformatted, args) # trailing some condition
and anotherCondition and anotherCondition
or aThirdCondition # trailing third condition or aThirdCondition # trailing third condition
): # comment ): # comment
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) print("Do something")
``` ```

View file

@ -24,8 +24,8 @@ ruff_python_ast = { path = "../crates/ruff_python_ast" }
ruff_python_formatter = { path = "../crates/ruff_python_formatter" } ruff_python_formatter = { path = "../crates/ruff_python_formatter" }
similar = { version = "2.2.1" } similar = { version = "2.2.1" }
# Current tag: v0.0.6 # Current tag: v0.0.7
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "8078663b6c914c1cb86993e427764f7c422fc12c" , default-features = false, features = ["full-lexer", "num-bigint"] } rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "c174bbf1f29527edd43d432326327f16f47ab9e0" , default-features = false, features = ["full-lexer", "num-bigint"] }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]