Compare commits
9 Commits
v0.1.5
...
schemastor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d65addffa0 | ||
|
|
9d167a1f5c | ||
|
|
9e184a9067 | ||
|
|
9d1027c239 | ||
|
|
f499f0ca60 | ||
|
|
722687ad72 | ||
|
|
4760af3dcb | ||
|
|
4fdf97a95c | ||
|
|
0ea1076f85 |
@@ -58,3 +58,33 @@ def f_fix_indentation_check(foo):
|
||||
# Report these, but don't fix them
|
||||
if foo: raise RuntimeError("This is an example exception")
|
||||
if foo: x = 1; raise RuntimeError("This is an example exception")
|
||||
|
||||
|
||||
def f_triple_quoted_string():
|
||||
raise RuntimeError(f"""This is an {"example"} exception""")
|
||||
|
||||
|
||||
def f_multi_line_string():
|
||||
raise RuntimeError(
|
||||
"first"
|
||||
"second"
|
||||
)
|
||||
|
||||
|
||||
def f_multi_line_string2():
|
||||
raise RuntimeError(
|
||||
"This is an {example} exception".format(
|
||||
example="example"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def f_multi_line_string2():
|
||||
raise RuntimeError(
|
||||
(
|
||||
"This is an "
|
||||
"{example} exception"
|
||||
).format(
|
||||
example="example"
|
||||
)
|
||||
)
|
||||
|
||||
0
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/__init__.py
vendored
Normal file
0
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/__init__.py
vendored
Normal file
11
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/direct.py
vendored
Normal file
11
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/direct.py
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
|
||||
class MyBaseClass:
|
||||
pass
|
||||
|
||||
|
||||
class Foo(MyBaseClass):
|
||||
foo: Sequence
|
||||
9
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/import.py
vendored
Normal file
9
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/import.py
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from module.direct import MyBaseClass
|
||||
|
||||
|
||||
class Foo(MyBaseClass):
|
||||
foo: Sequence
|
||||
7
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/undefined.py
vendored
Normal file
7
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/module/undefined.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
|
||||
class Foo(MyBaseClass):
|
||||
foo: Sequence
|
||||
@@ -0,0 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence # TCH003
|
||||
|
||||
|
||||
class MyBaseClass:
|
||||
pass
|
||||
|
||||
|
||||
class Foo(MyBaseClass):
|
||||
foo: Sequence
|
||||
@@ -123,6 +123,15 @@ def yes_six(x: list):
|
||||
x.append(2)
|
||||
|
||||
|
||||
if True:
|
||||
# FURB113
|
||||
nums.append(1)
|
||||
# comment
|
||||
nums.append(2)
|
||||
# comment
|
||||
nums.append(3)
|
||||
|
||||
|
||||
# Non-errors.
|
||||
|
||||
nums.append(1)
|
||||
|
||||
@@ -1415,7 +1415,7 @@ impl<'a> Checker<'a> {
|
||||
// subsequent nodes are evaluated in the inner scope.
|
||||
//
|
||||
// For example, given:
|
||||
// ```py
|
||||
// ```python
|
||||
// class A:
|
||||
// T = range(10)
|
||||
//
|
||||
@@ -1423,7 +1423,7 @@ impl<'a> Checker<'a> {
|
||||
// ```
|
||||
//
|
||||
// Conceptually, this is compiled as:
|
||||
// ```py
|
||||
// ```python
|
||||
// class A:
|
||||
// T = range(10)
|
||||
//
|
||||
|
||||
@@ -189,7 +189,7 @@ impl<'a> Insertion<'a> {
|
||||
Tok::NonLogicalNewline => {}
|
||||
Tok::Indent => {
|
||||
// This is like:
|
||||
// ```py
|
||||
// ```python
|
||||
// if True:
|
||||
// pass
|
||||
// ```
|
||||
|
||||
@@ -209,7 +209,7 @@ impl<'a> Importer<'a> {
|
||||
// We also add a no-op edit to force conflicts with any other fixes that might try to
|
||||
// remove the import. Consider:
|
||||
//
|
||||
// ```py
|
||||
// ```python
|
||||
// import sys
|
||||
//
|
||||
// quit()
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
use ruff_python_ast::{self as ast, Arguments, Expr, Stmt};
|
||||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::whitespace;
|
||||
use ruff_python_codegen::{Generator, Stylist};
|
||||
use ruff_python_codegen::Stylist;
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Rule;
|
||||
@@ -196,7 +197,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr
|
||||
first,
|
||||
indentation,
|
||||
checker.stylist(),
|
||||
checker.generator(),
|
||||
checker.locator(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -216,7 +217,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr
|
||||
first,
|
||||
indentation,
|
||||
checker.stylist(),
|
||||
checker.generator(),
|
||||
checker.locator(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -241,7 +242,7 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr
|
||||
first,
|
||||
indentation,
|
||||
checker.stylist(),
|
||||
checker.generator(),
|
||||
checker.locator(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -269,28 +270,27 @@ pub(crate) fn string_in_exception(checker: &mut Checker, stmt: &Stmt, exc: &Expr
|
||||
fn generate_fix(
|
||||
stmt: &Stmt,
|
||||
exc_arg: &Expr,
|
||||
indentation: &str,
|
||||
stmt_indentation: &str,
|
||||
stylist: &Stylist,
|
||||
generator: Generator,
|
||||
locator: &Locator,
|
||||
) -> Fix {
|
||||
let assignment = Stmt::Assign(ast::StmtAssign {
|
||||
targets: vec![Expr::Name(ast::ExprName {
|
||||
id: "msg".into(),
|
||||
ctx: ExprContext::Store,
|
||||
range: TextRange::default(),
|
||||
})],
|
||||
value: Box::new(exc_arg.clone()),
|
||||
range: TextRange::default(),
|
||||
});
|
||||
|
||||
Fix::unsafe_edits(
|
||||
Edit::insertion(
|
||||
format!(
|
||||
"{}{}{}",
|
||||
generator.stmt(&assignment),
|
||||
stylist.line_ending().as_str(),
|
||||
indentation,
|
||||
),
|
||||
if locator.contains_line_break(exc_arg.range()) {
|
||||
format!(
|
||||
"msg = ({line_ending}{stmt_indentation}{indentation}{}{line_ending}{stmt_indentation}){line_ending}{stmt_indentation}",
|
||||
locator.slice(exc_arg.range()),
|
||||
line_ending = stylist.line_ending().as_str(),
|
||||
indentation = stylist.indentation().as_str(),
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"msg = {}{}{}",
|
||||
locator.slice(exc_arg.range()),
|
||||
stylist.line_ending().as_str(),
|
||||
stmt_indentation,
|
||||
)
|
||||
},
|
||||
stmt.start(),
|
||||
),
|
||||
[Edit::range_replacement(
|
||||
|
||||
@@ -177,4 +177,86 @@ EM.py:60:35: EM101 Exception must not use a string literal, assign to variable f
|
||||
|
|
||||
= help: Assign to variable; remove string literal
|
||||
|
||||
EM.py:64:24: EM102 [*] Exception must not use an f-string literal, assign to variable first
|
||||
|
|
||||
63 | def f_triple_quoted_string():
|
||||
64 | raise RuntimeError(f"""This is an {"example"} exception""")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM102
|
||||
|
|
||||
= help: Assign to variable; remove f-string literal
|
||||
|
||||
ℹ Unsafe fix
|
||||
61 61 |
|
||||
62 62 |
|
||||
63 63 | def f_triple_quoted_string():
|
||||
64 |- raise RuntimeError(f"""This is an {"example"} exception""")
|
||||
64 |+ msg = f"""This is an {"example"} exception"""
|
||||
65 |+ raise RuntimeError(msg)
|
||||
65 66 |
|
||||
66 67 |
|
||||
67 68 | def f_multi_line_string():
|
||||
|
||||
EM.py:76:9: EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
|
||||
|
|
||||
74 | def f_multi_line_string2():
|
||||
75 | raise RuntimeError(
|
||||
76 | "This is an {example} exception".format(
|
||||
| _________^
|
||||
77 | | example="example"
|
||||
78 | | )
|
||||
| |_________^ EM103
|
||||
79 | )
|
||||
|
|
||||
= help: Assign to variable; remove `.format()` string
|
||||
|
||||
ℹ Unsafe fix
|
||||
72 72 |
|
||||
73 73 |
|
||||
74 74 | def f_multi_line_string2():
|
||||
75 |- raise RuntimeError(
|
||||
75 |+ msg = (
|
||||
76 76 | "This is an {example} exception".format(
|
||||
77 77 | example="example"
|
||||
78 78 | )
|
||||
79 79 | )
|
||||
80 |+ raise RuntimeError(
|
||||
81 |+ msg
|
||||
82 |+ )
|
||||
80 83 |
|
||||
81 84 |
|
||||
82 85 | def f_multi_line_string2():
|
||||
|
||||
EM.py:84:9: EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
|
||||
|
|
||||
82 | def f_multi_line_string2():
|
||||
83 | raise RuntimeError(
|
||||
84 | (
|
||||
| _________^
|
||||
85 | | "This is an "
|
||||
86 | | "{example} exception"
|
||||
87 | | ).format(
|
||||
88 | | example="example"
|
||||
89 | | )
|
||||
| |_________^ EM103
|
||||
90 | )
|
||||
|
|
||||
= help: Assign to variable; remove `.format()` string
|
||||
|
||||
ℹ Unsafe fix
|
||||
80 80 |
|
||||
81 81 |
|
||||
82 82 | def f_multi_line_string2():
|
||||
83 |- raise RuntimeError(
|
||||
83 |+ msg = (
|
||||
84 84 | (
|
||||
85 85 | "This is an "
|
||||
86 86 | "{example} exception"
|
||||
--------------------------------------------------------------------------------
|
||||
88 88 | example="example"
|
||||
89 89 | )
|
||||
90 90 | )
|
||||
91 |+ raise RuntimeError(
|
||||
92 |+ msg
|
||||
93 |+ )
|
||||
|
||||
|
||||
|
||||
@@ -215,4 +215,114 @@ EM.py:60:35: EM101 Exception must not use a string literal, assign to variable f
|
||||
|
|
||||
= help: Assign to variable; remove string literal
|
||||
|
||||
EM.py:64:24: EM102 [*] Exception must not use an f-string literal, assign to variable first
|
||||
|
|
||||
63 | def f_triple_quoted_string():
|
||||
64 | raise RuntimeError(f"""This is an {"example"} exception""")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM102
|
||||
|
|
||||
= help: Assign to variable; remove f-string literal
|
||||
|
||||
ℹ Unsafe fix
|
||||
61 61 |
|
||||
62 62 |
|
||||
63 63 | def f_triple_quoted_string():
|
||||
64 |- raise RuntimeError(f"""This is an {"example"} exception""")
|
||||
64 |+ msg = f"""This is an {"example"} exception"""
|
||||
65 |+ raise RuntimeError(msg)
|
||||
65 66 |
|
||||
66 67 |
|
||||
67 68 | def f_multi_line_string():
|
||||
|
||||
EM.py:69:9: EM101 [*] Exception must not use a string literal, assign to variable first
|
||||
|
|
||||
67 | def f_multi_line_string():
|
||||
68 | raise RuntimeError(
|
||||
69 | "first"
|
||||
| _________^
|
||||
70 | | "second"
|
||||
| |________________^ EM101
|
||||
71 | )
|
||||
|
|
||||
= help: Assign to variable; remove string literal
|
||||
|
||||
ℹ Unsafe fix
|
||||
65 65 |
|
||||
66 66 |
|
||||
67 67 | def f_multi_line_string():
|
||||
68 |- raise RuntimeError(
|
||||
68 |+ msg = (
|
||||
69 69 | "first"
|
||||
70 70 | "second"
|
||||
71 71 | )
|
||||
72 |+ raise RuntimeError(
|
||||
73 |+ msg
|
||||
74 |+ )
|
||||
72 75 |
|
||||
73 76 |
|
||||
74 77 | def f_multi_line_string2():
|
||||
|
||||
EM.py:76:9: EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
|
||||
|
|
||||
74 | def f_multi_line_string2():
|
||||
75 | raise RuntimeError(
|
||||
76 | "This is an {example} exception".format(
|
||||
| _________^
|
||||
77 | | example="example"
|
||||
78 | | )
|
||||
| |_________^ EM103
|
||||
79 | )
|
||||
|
|
||||
= help: Assign to variable; remove `.format()` string
|
||||
|
||||
ℹ Unsafe fix
|
||||
72 72 |
|
||||
73 73 |
|
||||
74 74 | def f_multi_line_string2():
|
||||
75 |- raise RuntimeError(
|
||||
75 |+ msg = (
|
||||
76 76 | "This is an {example} exception".format(
|
||||
77 77 | example="example"
|
||||
78 78 | )
|
||||
79 79 | )
|
||||
80 |+ raise RuntimeError(
|
||||
81 |+ msg
|
||||
82 |+ )
|
||||
80 83 |
|
||||
81 84 |
|
||||
82 85 | def f_multi_line_string2():
|
||||
|
||||
EM.py:84:9: EM103 [*] Exception must not use a `.format()` string directly, assign to variable first
|
||||
|
|
||||
82 | def f_multi_line_string2():
|
||||
83 | raise RuntimeError(
|
||||
84 | (
|
||||
| _________^
|
||||
85 | | "This is an "
|
||||
86 | | "{example} exception"
|
||||
87 | | ).format(
|
||||
88 | | example="example"
|
||||
89 | | )
|
||||
| |_________^ EM103
|
||||
90 | )
|
||||
|
|
||||
= help: Assign to variable; remove `.format()` string
|
||||
|
||||
ℹ Unsafe fix
|
||||
80 80 |
|
||||
81 81 |
|
||||
82 82 | def f_multi_line_string2():
|
||||
83 |- raise RuntimeError(
|
||||
83 |+ msg = (
|
||||
84 84 | (
|
||||
85 85 | "This is an "
|
||||
86 86 | "{example} exception"
|
||||
--------------------------------------------------------------------------------
|
||||
88 88 | example="example"
|
||||
89 89 | )
|
||||
90 90 | )
|
||||
91 |+ raise RuntimeError(
|
||||
92 |+ msg
|
||||
93 |+ )
|
||||
|
||||
|
||||
|
||||
@@ -144,6 +144,28 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("module/direct.py"))]
|
||||
#[test_case(Rule::TypingOnlyStandardLibraryImport, Path::new("module/import.py"))]
|
||||
#[test_case(
|
||||
Rule::TypingOnlyStandardLibraryImport,
|
||||
Path::new("module/undefined.py")
|
||||
)]
|
||||
fn base_class_same_file(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
Path::new("flake8_type_checking").join(path).as_path(),
|
||||
&settings::LinterSettings {
|
||||
flake8_type_checking: super::settings::Settings {
|
||||
runtime_evaluated_base_classes: vec!["module.direct.MyBaseClass".to_string()],
|
||||
..Default::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rule(rule_code)
|
||||
},
|
||||
)?;
|
||||
assert_messages!(snapshot, diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(
|
||||
r#"
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
|
||||
---
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
|
||||
---
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_type_checking/mod.rs
|
||||
---
|
||||
undefined.py:3:29: TCH003 [*] Move standard library import `collections.abc.Sequence` into a type-checking block
|
||||
|
|
||||
1 | from __future__ import annotations
|
||||
2 |
|
||||
3 | from collections.abc import Sequence
|
||||
| ^^^^^^^^ TCH003
|
||||
|
|
||||
= help: Move into type-checking block
|
||||
|
||||
ℹ Unsafe fix
|
||||
1 1 | from __future__ import annotations
|
||||
2 2 |
|
||||
3 |-from collections.abc import Sequence
|
||||
3 |+from typing import TYPE_CHECKING
|
||||
4 |+
|
||||
5 |+if TYPE_CHECKING:
|
||||
6 |+ from collections.abc import Sequence
|
||||
4 7 |
|
||||
5 8 |
|
||||
6 9 | class Foo(MyBaseClass):
|
||||
|
||||
|
||||
@@ -106,7 +106,16 @@ pub(crate) fn repeated_append(checker: &mut Checker, stmt: &Stmt) {
|
||||
|
||||
// We only suggest a fix when all appends in a group are clumped together. If they're
|
||||
// non-consecutive, fixing them is much more difficult.
|
||||
if group.is_consecutive {
|
||||
//
|
||||
// Avoid fixing if there are comments in between the appends:
|
||||
//
|
||||
// ```python
|
||||
// a.append(1)
|
||||
// # comment
|
||||
// a.append(2)
|
||||
// ```
|
||||
if group.is_consecutive && !checker.indexer().comment_ranges().intersects(group.range())
|
||||
{
|
||||
diagnostic.set_fix(Fix::unsafe_edit(Edit::replacement(
|
||||
replacement,
|
||||
group.start(),
|
||||
|
||||
@@ -330,6 +330,20 @@ FURB113.py:122:5: FURB113 [*] Use `x.extend((1, 2))` instead of repeatedly calli
|
||||
122 |+ x.extend((1, 2))
|
||||
124 123 |
|
||||
125 124 |
|
||||
126 125 | # Non-errors.
|
||||
126 125 | if True:
|
||||
|
||||
FURB113.py:128:5: FURB113 Use `nums.extend((1, 2, 3))` instead of repeatedly calling `nums.append()`
|
||||
|
|
||||
126 | if True:
|
||||
127 | # FURB113
|
||||
128 | nums.append(1)
|
||||
| _____^
|
||||
129 | | # comment
|
||||
130 | | nums.append(2)
|
||||
131 | | # comment
|
||||
132 | | nums.append(3)
|
||||
| |__________________^ FURB113
|
||||
|
|
||||
= help: Replace with `nums.extend((1, 2, 3))`
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ fn black_compatibility() {
|
||||
// today.
|
||||
let mut snapshot = String::new();
|
||||
write!(snapshot, "{}", Header::new("Input")).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("py", &content)).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("python", &content)).unwrap();
|
||||
|
||||
write!(snapshot, "{}", Header::new("Black Differences")).unwrap();
|
||||
|
||||
@@ -83,10 +83,10 @@ fn black_compatibility() {
|
||||
write!(snapshot, "{}", CodeFrame::new("diff", &diff)).unwrap();
|
||||
|
||||
write!(snapshot, "{}", Header::new("Ruff Output")).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("py", &formatted_code)).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("python", &formatted_code)).unwrap();
|
||||
|
||||
write!(snapshot, "{}", Header::new("Black Output")).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("py", &expected_output)).unwrap();
|
||||
write!(snapshot, "{}", CodeFrame::new("python", &expected_output)).unwrap();
|
||||
|
||||
insta::with_settings!({
|
||||
omit_expression => true,
|
||||
@@ -113,7 +113,7 @@ fn format() {
|
||||
|
||||
ensure_stability_when_formatting_twice(formatted_code, options.clone(), input_path);
|
||||
|
||||
let mut snapshot = format!("## Input\n{}", CodeFrame::new("py", &content));
|
||||
let mut snapshot = format!("## Input\n{}", CodeFrame::new("python", &content));
|
||||
|
||||
let options_path = input_path.with_extension("options.json");
|
||||
if let Ok(options_file) = fs::File::open(options_path) {
|
||||
@@ -135,7 +135,7 @@ fn format() {
|
||||
"### Output {}\n{}{}",
|
||||
i + 1,
|
||||
CodeFrame::new("", &DisplayPyOptions(&options)),
|
||||
CodeFrame::new("py", &formatted_code)
|
||||
CodeFrame::new("python", &formatted_code)
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
@@ -159,14 +159,19 @@ fn format() {
|
||||
);
|
||||
|
||||
if formatted == formatted_preview {
|
||||
writeln!(snapshot, "## Output\n{}", CodeFrame::new("py", &formatted)).unwrap();
|
||||
writeln!(
|
||||
snapshot,
|
||||
"## Output\n{}",
|
||||
CodeFrame::new("python", &formatted)
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
// Having both snapshots makes it hard to see the difference, so we're keeping only
|
||||
// diff.
|
||||
writeln!(
|
||||
snapshot,
|
||||
"## Output\n{}\n## Preview changes\n{}",
|
||||
CodeFrame::new("py", &formatted),
|
||||
CodeFrame::new("python", &formatted),
|
||||
CodeFrame::new(
|
||||
"diff",
|
||||
TextDiff::from_lines(formatted, formatted_preview)
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/condition
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
long_kwargs_single_line = my_function(
|
||||
foo="test, this is a sample value",
|
||||
bar=some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz,
|
||||
@@ -149,7 +149,7 @@ def something():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
long_kwargs_single_line = my_function(
|
||||
foo="test, this is a sample value",
|
||||
bar=some_long_value_name_foo_bar_baz
|
||||
@@ -238,7 +238,7 @@ def something():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
long_kwargs_single_line = my_function(
|
||||
foo="test, this is a sample value",
|
||||
bar=(
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def abc ():
|
||||
return ["hello", "world",
|
||||
"!"]
|
||||
@@ -33,7 +33,7 @@ print( "Incorrect formatting"
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def abc():
|
||||
return ["hello", "world", "!"]
|
||||
|
||||
@@ -43,7 +43,7 @@ print("Incorrect formatting")
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def abc ():
|
||||
return ["hello", "world",
|
||||
"!"]
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
@dataclass
|
||||
class DebugVisitor(Visitor[T]):
|
||||
tree_depth: int = 0
|
||||
@@ -79,7 +79,7 @@ class DebugVisitor(Visitor[T]):
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
@dataclass
|
||||
class DebugVisitor(Visitor[T]):
|
||||
tree_depth: int = 0
|
||||
@@ -116,7 +116,7 @@ class DebugVisitor(Visitor[T]):
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
@dataclass
|
||||
class DebugVisitor(Visitor[T]):
|
||||
tree_depth: int = 0
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# This file doesn't use the standard decomposition.
|
||||
# Decorator syntax test cases are separated by double # comments.
|
||||
# Those before the 'output' comment are valid under the old syntax.
|
||||
@@ -378,7 +378,7 @@ def f():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# This file doesn't use the standard decomposition.
|
||||
# Decorator syntax test cases are separated by double # comments.
|
||||
# Those before the 'output' comment are valid under the old syntax.
|
||||
@@ -589,7 +589,7 @@ def f():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
##
|
||||
|
||||
@decorator()()
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
class ALonelyClass:
|
||||
'''
|
||||
A multiline class docstring.
|
||||
@@ -208,7 +208,7 @@ def multiline_backslash_3():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class ALonelyClass:
|
||||
"""
|
||||
A multiline class docstring.
|
||||
@@ -336,7 +336,7 @@ def multiline_backslash_3():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class ALonelyClass:
|
||||
'''
|
||||
A multiline class docstring.
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def do_not_touch_this_prefix():
|
||||
R"""There was a bug where docstring prefixes would be normalized even with -S."""
|
||||
|
||||
@@ -37,7 +37,7 @@ def do_not_touch_this_prefix3():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def do_not_touch_this_prefix():
|
||||
R"""There was a bug where docstring prefixes would be normalized even with -S."""
|
||||
|
||||
@@ -52,7 +52,7 @@ def do_not_touch_this_prefix3():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def do_not_touch_this_prefix():
|
||||
R"""There was a bug where docstring prefixes would be normalized even with -S."""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# flags: --pyi
|
||||
from typing import Union
|
||||
|
||||
@@ -119,7 +119,7 @@ def eggs() -> Union[str, int]: ...
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# flags: --pyi
|
||||
from typing import Union
|
||||
|
||||
@@ -183,7 +183,7 @@ def eggs() -> Union[str, int]:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
from typing import Union
|
||||
|
||||
@bird
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
|
||||
x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
@@ -324,7 +324,7 @@ long_unmergable_string_with_pragma = (
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
|
||||
x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
@@ -617,7 +617,7 @@ long_unmergable_string_with_pragma = (
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
|
||||
x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
importA;()<<0**0#
|
||||
```
|
||||
|
||||
@@ -25,14 +25,14 @@ importA;()<<0**0#
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
importA
|
||||
() << 0**0 #
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
importA
|
||||
(
|
||||
()
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
''''''
|
||||
|
||||
'\''
|
||||
@@ -88,7 +88,7 @@ f"\"{a}\"{'hello' * b}\"{c}\""
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
""""""
|
||||
|
||||
"'"
|
||||
@@ -151,7 +151,7 @@ f"\"{a}\"{'hello' * b}\"{c}\""
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
""""""
|
||||
|
||||
"'"
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_310/pa
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
import match
|
||||
|
||||
match something:
|
||||
@@ -162,7 +162,7 @@ match bar1:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
import match
|
||||
|
||||
match something:
|
||||
@@ -295,7 +295,7 @@ match bar1:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
import match
|
||||
|
||||
match something:
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_310/pa
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
match something:
|
||||
case b(): print(1+1)
|
||||
case c(
|
||||
@@ -99,7 +99,7 @@ match match(
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
match something:
|
||||
case b():
|
||||
print(1 + 1)
|
||||
@@ -145,7 +145,7 @@ match match():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
match something:
|
||||
case b():
|
||||
print(1 + 1)
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_310/pe
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Unparenthesized walruses are now allowed in indices since Python 3.10.
|
||||
x[a:=0]
|
||||
x[a:=0, b:=1]
|
||||
@@ -42,7 +42,7 @@ f(x, (a := b + c for c in range(10)), y=z, **q)
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Unparenthesized walruses are now allowed in indices since Python 3.10.
|
||||
x[a := 0]
|
||||
x[a := 0, b := 1]
|
||||
@@ -62,7 +62,7 @@ f(x, (a := b + c for c in range(10)), y=z, **q)
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Unparenthesized walruses are now allowed in indices since Python 3.10.
|
||||
x[a:=0]
|
||||
x[a:=0, b:=1]
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_38/pep
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
if (foo := 0):
|
||||
pass
|
||||
|
||||
@@ -94,7 +94,7 @@ async def await_the_walrus():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
if foo := 0:
|
||||
pass
|
||||
|
||||
@@ -170,7 +170,7 @@ async def await_the_walrus():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
if foo := 0:
|
||||
pass
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/raw_docst
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# flags: --preview --skip-string-normalization
|
||||
class C:
|
||||
|
||||
@@ -50,7 +50,7 @@ class UpperCaseR:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# flags: --preview --skip-string-normalization
|
||||
class C:
|
||||
|
||||
@@ -72,7 +72,7 @@ class UpperCaseR:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
r"""Raw"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def bob(): \
|
||||
# pylint: disable=W9016
|
||||
pass
|
||||
@@ -36,7 +36,7 @@ def bobtwo(): \
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def bob():
|
||||
# pylint: disable=W9016
|
||||
pass
|
||||
@@ -49,7 +49,7 @@ def bobtwo():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def bob(): # pylint: disable=W9016
|
||||
pass
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent # NOT DRY
|
||||
)
|
||||
@@ -246,7 +246,7 @@ instruction()#comment with bad spacing
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
@@ -442,7 +442,7 @@ instruction() # comment with bad spacing
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
@@ -179,7 +179,7 @@ def bar():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
@@ -342,7 +342,7 @@ def bar():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
@@ -242,7 +242,7 @@ class C:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
@@ -427,7 +427,7 @@ class C:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
@@ -242,7 +242,7 @@ class C:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
@@ -427,7 +427,7 @@ class C:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
"""
|
||||
@@ -76,7 +76,7 @@ def single_quote_docstring_over_line_limit2():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
@@ -130,7 +130,7 @@ def single_quote_docstring_over_line_limit2():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
...
|
||||
'some_string'
|
||||
b'\\xa3'
|
||||
@@ -279,7 +279,7 @@ last_call()
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
...
|
||||
"some_string"
|
||||
b"\\xa3"
|
||||
@@ -655,7 +655,7 @@ last_call()
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
...
|
||||
"some_string"
|
||||
b"\\xa3"
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
@@ -271,7 +271,7 @@ d={'a':1,
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
@@ -506,7 +506,7 @@ d={'a':1,
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
@@ -53,7 +53,7 @@ def f(): pass
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
@@ -71,7 +71,7 @@ def f(): pass
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
setup(
|
||||
entry_points={
|
||||
@@ -122,7 +122,7 @@ elif unformatted:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
setup(
|
||||
entry_points={
|
||||
@@ -213,7 +213,7 @@ elif unformatted:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
setup(
|
||||
entry_points={
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3438
|
||||
|
||||
import ast
|
||||
@@ -43,7 +43,7 @@ import zoneinfo
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3438
|
||||
|
||||
import ast
|
||||
@@ -68,7 +68,7 @@ import zoneinfo
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Regression test for https://github.com/psf/black/issues/3438
|
||||
|
||||
import ast
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
@@ -34,7 +34,7 @@ else:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
@@ -48,7 +48,7 @@ else:
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
@@ -119,7 +119,7 @@ def __await__(): return (yield)
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
@@ -273,7 +273,7 @@ def __await__():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
@@ -85,7 +85,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
@@ -153,7 +153,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(): # type: ignore
|
||||
...
|
||||
|
||||
@@ -64,7 +64,7 @@ def h():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(): # type: ignore
|
||||
...
|
||||
|
||||
@@ -94,7 +94,7 @@ def h():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
def f(): # type: ignore
|
||||
...
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a regression test. Issue #3737
|
||||
|
||||
a = ( # type: ignore
|
||||
@@ -48,7 +48,7 @@ print( "111" ) # type: ignore
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a regression test. Issue #3737
|
||||
|
||||
a = ( # type: ignore
|
||||
@@ -70,7 +70,7 @@ print("111") # type: ignore
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a regression test. Issue #3737
|
||||
|
||||
a = ( # type: ignore
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
import asyncio
|
||||
|
||||
# Control example
|
||||
@@ -108,7 +108,7 @@ async def main():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
import asyncio
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ async def main():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
import asyncio
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
@@ -62,7 +62,7 @@ except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.ov
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
@@ -107,7 +107,7 @@ except (
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Only remove tuple brackets after `for`
|
||||
for (k, v) in d.items():
|
||||
print(k, v)
|
||||
@@ -46,7 +46,7 @@ for (((((k, v))))) in d.items():
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Only remove tuple brackets after `for`
|
||||
for k, v in d.items():
|
||||
print(k, v)
|
||||
@@ -76,7 +76,7 @@ for k, v in d.items():
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Only remove tuple brackets after `for`
|
||||
for k, v in d.items():
|
||||
print(k, v)
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2*a
|
||||
@@ -126,7 +126,7 @@ def foo() -> tuple[int, int, int,]:
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
@@ -259,7 +259,7 @@ def foo() -> (
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
importA;() << 0 ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 #
|
||||
|
||||
assert sort_by_dependency(
|
||||
@@ -66,7 +66,7 @@ assert (
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
importA
|
||||
(
|
||||
()
|
||||
@@ -129,7 +129,7 @@ assert a_function(
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
importA
|
||||
(
|
||||
()
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
zero(one,).two(three,).four(five,)
|
||||
|
||||
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||
@@ -72,7 +72,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
zero(
|
||||
one,
|
||||
).two(
|
||||
@@ -123,7 +123,7 @@ assert (
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
zero(
|
||||
one,
|
||||
).two(
|
||||
|
||||
@@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a standalone comment.
|
||||
sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3
|
||||
|
||||
@@ -32,7 +32,7 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a standalone comment.
|
||||
(
|
||||
sdfjklsdfsjldkflkjsf,
|
||||
@@ -49,7 +49,7 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
```python
|
||||
# This is a standalone comment.
|
||||
(
|
||||
sdfjklsdfsjldkflkjsf,
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/carriage_return/string.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
@@ -13,7 +13,7 @@ String \"
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
"This string will not include \
|
||||
backslashes or newline characters."
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
def single_line_backslashes1():
|
||||
""" content\ """
|
||||
return
|
||||
@@ -169,7 +169,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def single_line_backslashes1():
|
||||
"""content\ """
|
||||
return
|
||||
@@ -335,7 +335,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def single_line_backslashes1():
|
||||
"""content\ """
|
||||
return
|
||||
@@ -501,7 +501,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def single_line_backslashes1():
|
||||
"""content\ """
|
||||
return
|
||||
@@ -667,7 +667,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def single_line_backslashes1():
|
||||
"""content\ """
|
||||
return
|
||||
|
||||
@@ -3,14 +3,14 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/empty_multiple_trailing_newlines.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/empty_now_newline.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/empty_trailing_newline.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/empty_whitespace.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/annotated_assign.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
a: string
|
||||
|
||||
b: string = "test"
|
||||
@@ -20,7 +20,7 @@ b: list[
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
a: string
|
||||
|
||||
b: string = "test"
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/attribute.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
from argparse import Namespace
|
||||
|
||||
a = Namespace()
|
||||
@@ -161,7 +161,7 @@ result = (
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
from argparse import Namespace
|
||||
|
||||
a = Namespace()
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/await.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7420
|
||||
result = await self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
@@ -57,7 +57,7 @@ await (
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7420
|
||||
result = await self.request(
|
||||
f"/applications/{int(application_id)}/guilds/{int(scope)}/commands/{int(command_id)}/permissions"
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
(aaaaaaaa
|
||||
+ # trailing operator comment
|
||||
b # trailing right comment
|
||||
@@ -415,7 +415,7 @@ if True:
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
(
|
||||
aaaaaaaa
|
||||
+ # trailing operator comment
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_implicit_string.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
|
||||
raise ImproperlyConfigured(
|
||||
"The app module %r has multiple filesystem locations (%r); "
|
||||
@@ -198,7 +198,7 @@ class EC2REPATH:
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
raise ImproperlyConfigured(
|
||||
"The app module %r has multiple filesystem locations (%r); "
|
||||
"you must configure this app with an AppConfig subclass "
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/binary_pow_spacing.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# No spacing
|
||||
5 ** 5
|
||||
5.0 ** 5.0
|
||||
@@ -17,7 +17,7 @@ None ** None
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# No spacing
|
||||
5**5
|
||||
5.0**5.0
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/boolean_operation.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
if (
|
||||
self._proc
|
||||
# has the child process finished?
|
||||
@@ -194,7 +194,7 @@ if (self._proc
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
if (
|
||||
self._proc
|
||||
# has the child process finished?
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/bytes.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
b"' test"
|
||||
b'" test'
|
||||
|
||||
@@ -137,7 +137,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
b"' test"
|
||||
b'" test'
|
||||
|
||||
@@ -286,7 +286,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
b"' test"
|
||||
b'" test'
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/call.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ result = (object[complicate_caller])("argument").a["b"].test(argument)
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/compare.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
a == b
|
||||
a != b
|
||||
a < b
|
||||
@@ -187,7 +187,7 @@ c = (a *
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
a == b
|
||||
a != b
|
||||
a < b
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# before
|
||||
{ # open
|
||||
key# key
|
||||
@@ -141,7 +141,7 @@ query = {
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# before
|
||||
{ # open
|
||||
key: # key
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict_comp.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
{i: i for i in []}
|
||||
|
||||
{i: i for i in [1,]}
|
||||
@@ -186,7 +186,7 @@ query = {
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
{i: i for i in []}
|
||||
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/fstring.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
(
|
||||
f'{one}'
|
||||
f'{two}'
|
||||
@@ -71,7 +71,7 @@ z = f'''a{""}b''' f'''c{1}d"""e'''
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
(f"{one}" f"{two}")
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/generator_exp.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
(a for b in c)
|
||||
|
||||
# parens around generator expression not required
|
||||
@@ -78,7 +78,7 @@ tuple(
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
(a for b in c)
|
||||
|
||||
# parens around generator expression not required
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/if.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
a1 = 1 if True else 2
|
||||
|
||||
a2 = "this is a very long text that will make the group break to check that parentheses are added" if True else 2
|
||||
@@ -117,7 +117,7 @@ def something():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
a1 = 1 if True else 2
|
||||
|
||||
a2 = (
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/lambda.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Leading
|
||||
lambda x: x # Trailing
|
||||
# Trailing
|
||||
@@ -237,7 +237,7 @@ def a():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Leading
|
||||
lambda x: x # Trailing
|
||||
# Trailing
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Dangling comment placement in empty lists
|
||||
# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16
|
||||
a1 = [ # a
|
||||
@@ -67,7 +67,7 @@ c1 = [ # trailing open bracket
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Dangling comment placement in empty lists
|
||||
# Regression test for https://github.com/python/cpython/blob/03160630319ca26dcbbad65225da4248e54c45ec/Tools/c-analyzer/c_analyzer/datafiles.py#L14-L16
|
||||
a1 = [ # a
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list_comp.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
[i for i in []]
|
||||
|
||||
[i for i in [1,]]
|
||||
@@ -114,7 +114,7 @@ aaaaaaaaaaaaaaaaaaaaa = [
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
[i for i in []]
|
||||
|
||||
[
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/named_expr.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
y = 1
|
||||
|
||||
if (
|
||||
@@ -106,7 +106,7 @@ async def f():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
y = 1
|
||||
|
||||
if (
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/number.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
.1
|
||||
1.
|
||||
1E+1
|
||||
@@ -14,7 +14,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
0.1
|
||||
1.0
|
||||
1e1
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/optional_parentheses_comments.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
comment_string = "Long lines with inline comments should have their comments appended to the reformatted string's enclosing right parentheses." # This comment gets thrown to the top.
|
||||
|
||||
# 88 characters unparenthesized
|
||||
@@ -213,7 +213,7 @@ def test6():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
comment_string = "Long lines with inline comments should have their comments appended to the reformatted string's enclosing right parentheses." # This comment gets thrown to the top.
|
||||
|
||||
# 88 characters unparenthesized
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/set_comp.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
{i for i in []}
|
||||
|
||||
{i for i in [1,]}
|
||||
@@ -62,7 +62,7 @@ selected_choices = {
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
{i for i in []}
|
||||
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/slice.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Handle comments both when lower and upper exist and when they don't
|
||||
a1 = "a"[
|
||||
# a
|
||||
@@ -119,7 +119,7 @@ self.assertEqual(
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Handle comments both when lower and upper exist and when they don't
|
||||
a1 = "a"[
|
||||
# a
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/split_empty_brackets.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Expressions with empty parentheses.
|
||||
ct_match = (
|
||||
unicodedata.normalize("NFKC", s1).casefold()
|
||||
@@ -97,7 +97,7 @@ response = await sync_to_async(
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Expressions with empty parentheses.
|
||||
ct_match = (
|
||||
unicodedata.normalize("NFKC", s1).casefold()
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/starred.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
call(
|
||||
# Leading starred comment
|
||||
* # Trailing star comment
|
||||
@@ -40,7 +40,7 @@ call(
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
call(
|
||||
# Leading starred comment
|
||||
# Trailing star comment
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/string.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
@@ -152,7 +152,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
@@ -325,7 +325,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/subscript.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
||||
result = (
|
||||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||
@@ -12,7 +12,7 @@ result = (
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
||||
result = (
|
||||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# Non-wrapping parentheses checks
|
||||
a1 = 1, 2
|
||||
a2 = (1, 2)
|
||||
@@ -78,7 +78,7 @@ i1 = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# Non-wrapping parentheses checks
|
||||
a1 = 1, 2
|
||||
a2 = (1, 2)
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/unary.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
if not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb:
|
||||
pass
|
||||
|
||||
@@ -202,7 +202,7 @@ def foo():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
if (
|
||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/unsplittable.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
x_aa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
@@ -103,7 +103,7 @@ def f():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
x_aa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/yield.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
l = [1,2,3,4]
|
||||
|
||||
def foo():
|
||||
@@ -128,7 +128,7 @@ print((yield x))
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
l = [1, 2, 3, 4]
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/yield_from.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
l = [1,2,3,4]
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ def foo():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
l = [1, 2, 3, 4]
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/comments.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
pass
|
||||
|
||||
# fmt: off
|
||||
@@ -35,7 +35,7 @@ def test():
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
pass
|
||||
|
||||
# fmt: off
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/empty_file.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
# fmt: off
|
||||
|
||||
# this does not work because there are no statements
|
||||
@@ -12,7 +12,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
```python
|
||||
# fmt: off
|
||||
|
||||
# this does not work because there are no statements
|
||||
|
||||
@@ -3,7 +3,7 @@ source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/fmt_off_docstring.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
```python
|
||||
def test():
|
||||
# fmt: off
|
||||
""" This docstring does not
|
||||
@@ -36,7 +36,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def test():
|
||||
# fmt: off
|
||||
""" This docstring does not
|
||||
@@ -69,7 +69,7 @@ magic-trailing-comma = Respect
|
||||
preview = Disabled
|
||||
```
|
||||
|
||||
```py
|
||||
```python
|
||||
def test():
|
||||
# fmt: off
|
||||
""" This docstring does not
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user