mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 09:31:09 +00:00
Use insta::glob
instead of fixture
macro (#5364)
This commit is contained in:
parent
dce6a046b0
commit
8879927b9a
82 changed files with 285 additions and 765 deletions
|
@ -263,18 +263,12 @@ impl TryFrom<char> for QuoteStyle {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{format_module, format_node};
|
||||
use anyhow::Result;
|
||||
use insta::assert_snapshot;
|
||||
use ruff_python_ast::source_code::CommentRangesBuilder;
|
||||
use ruff_testing_macros::fixture;
|
||||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
use similar::TextDiff;
|
||||
use std::fmt::{Formatter, Write};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{format_module, format_node};
|
||||
|
||||
/// Very basic test intentionally kept very similar to the CLI
|
||||
#[test]
|
||||
|
@ -295,138 +289,6 @@ if True:
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[fixture(pattern = "resources/test/fixtures/black/**/*.py")]
|
||||
#[test]
|
||||
fn black_test(input_path: &Path) -> Result<()> {
|
||||
let content = fs::read_to_string(input_path)?;
|
||||
|
||||
let printed = format_module(&content)?;
|
||||
|
||||
let expected_path = input_path.with_extension("py.expect");
|
||||
let expected_output = fs::read_to_string(&expected_path)
|
||||
.unwrap_or_else(|_| panic!("Expected Black output file '{expected_path:?}' to exist"));
|
||||
|
||||
let formatted_code = printed.as_code();
|
||||
|
||||
ensure_stability_when_formatting_twice(formatted_code);
|
||||
|
||||
if formatted_code == expected_output {
|
||||
// Black and Ruff formatting matches. Delete any existing snapshot files because the Black output
|
||||
// already perfectly captures the expected output.
|
||||
// The following code mimics insta's logic generating the snapshot name for a test.
|
||||
let workspace_path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let snapshot_name = insta::_function_name!()
|
||||
.strip_prefix(&format!("{}::", module_path!()))
|
||||
.unwrap();
|
||||
let module_path = module_path!().replace("::", "__");
|
||||
|
||||
let snapshot_path = Path::new(&workspace_path)
|
||||
.join("src/snapshots")
|
||||
.join(format!(
|
||||
"{module_path}__{}.snap",
|
||||
snapshot_name.replace(&['/', '\\'][..], "__")
|
||||
));
|
||||
|
||||
if snapshot_path.exists() && snapshot_path.is_file() {
|
||||
// SAFETY: This is a convenience feature. That's why we don't want to abort
|
||||
// when deleting a no longer needed snapshot fails.
|
||||
fs::remove_file(&snapshot_path).ok();
|
||||
}
|
||||
|
||||
let new_snapshot_path = snapshot_path.with_extension("snap.new");
|
||||
if new_snapshot_path.exists() && new_snapshot_path.is_file() {
|
||||
// SAFETY: This is a convenience feature. That's why we don't want to abort
|
||||
// when deleting a no longer needed snapshot fails.
|
||||
fs::remove_file(&new_snapshot_path).ok();
|
||||
}
|
||||
} else {
|
||||
// Black and Ruff have different formatting. Write out a snapshot that covers the differences
|
||||
// today.
|
||||
let mut snapshot = String::new();
|
||||
write!(snapshot, "{}", Header::new("Input"))?;
|
||||
write!(snapshot, "{}", CodeFrame::new("py", &content))?;
|
||||
|
||||
write!(snapshot, "{}", Header::new("Black Differences"))?;
|
||||
|
||||
let diff = TextDiff::from_lines(expected_output.as_str(), formatted_code)
|
||||
.unified_diff()
|
||||
.header("Black", "Ruff")
|
||||
.to_string();
|
||||
|
||||
write!(snapshot, "{}", CodeFrame::new("diff", &diff))?;
|
||||
|
||||
write!(snapshot, "{}", Header::new("Ruff Output"))?;
|
||||
write!(snapshot, "{}", CodeFrame::new("py", formatted_code))?;
|
||||
|
||||
write!(snapshot, "{}", Header::new("Black Output"))?;
|
||||
write!(snapshot, "{}", CodeFrame::new("py", &expected_output))?;
|
||||
|
||||
insta::with_settings!({ omit_expression => false, input_file => input_path }, {
|
||||
insta::assert_snapshot!(snapshot);
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[fixture(pattern = "resources/test/fixtures/ruff/**/*.py")]
|
||||
#[test]
|
||||
fn ruff_test(input_path: &Path) -> Result<()> {
|
||||
let content = fs::read_to_string(input_path)?;
|
||||
|
||||
let printed = format_module(&content)?;
|
||||
let formatted_code = printed.as_code();
|
||||
|
||||
ensure_stability_when_formatting_twice(formatted_code);
|
||||
|
||||
let snapshot = format!(
|
||||
r#"## Input
|
||||
{}
|
||||
|
||||
## Output
|
||||
{}"#,
|
||||
CodeFrame::new("py", &content),
|
||||
CodeFrame::new("py", formatted_code)
|
||||
);
|
||||
assert_snapshot!(snapshot);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Format another time and make sure that there are no changes anymore
|
||||
fn ensure_stability_when_formatting_twice(formatted_code: &str) {
|
||||
let reformatted = match format_module(formatted_code) {
|
||||
Ok(reformatted) => reformatted,
|
||||
Err(err) => {
|
||||
panic!(
|
||||
"Expected formatted code to be valid syntax: {err}:\
|
||||
\n---\n{formatted_code}---\n",
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if reformatted.as_code() != formatted_code {
|
||||
let diff = TextDiff::from_lines(formatted_code, reformatted.as_code())
|
||||
.unified_diff()
|
||||
.header("Formatted once", "Formatted twice")
|
||||
.to_string();
|
||||
panic!(
|
||||
r#"Reformatting the formatted code a second time resulted in formatting changes.
|
||||
---
|
||||
{diff}---
|
||||
|
||||
Formatted once:
|
||||
---
|
||||
{formatted_code}---
|
||||
|
||||
Formatted twice:
|
||||
---
|
||||
{}---"#,
|
||||
reformatted.as_code()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Use this test to debug the formatting of some snipped
|
||||
#[ignore]
|
||||
#[test]
|
||||
|
@ -549,41 +411,4 @@ if [
|
|||
|
||||
assert_snapshot!(output.print().expect("Printing to succeed").as_code());
|
||||
}
|
||||
|
||||
struct Header<'a> {
|
||||
title: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Header<'a> {
|
||||
fn new(title: &'a str) -> Self {
|
||||
Self { title }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Header<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "## {}", self.title)?;
|
||||
writeln!(f)
|
||||
}
|
||||
}
|
||||
|
||||
struct CodeFrame<'a> {
|
||||
language: &'a str,
|
||||
code: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> CodeFrame<'a> {
|
||||
fn new(language: &'a str, code: &'a str) -> Self {
|
||||
Self { language, code }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CodeFrame<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "```{}", self.language)?;
|
||||
write!(f, "{}", self.code)?;
|
||||
writeln!(f, "```")?;
|
||||
writeln!(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
x = 123456789 .bit_count()
|
||||
x = (123456).__abs__()
|
||||
x = .1.is_integer()
|
||||
x = 1. .imag
|
||||
x = 1E+1.imag
|
||||
x = 1E-1.real
|
||||
x = 123456789.123456789.hex()
|
||||
x = 123456789.123456789E123456789 .real
|
||||
x = 123456789E123456789 .conjugate()
|
||||
x = 123456789J.real
|
||||
x = 123456789.123456789J.__add__(0b1011.bit_length())
|
||||
x = 0XB1ACC.conjugate()
|
||||
x = 0B1011 .conjugate()
|
||||
x = 0O777 .real
|
||||
x = 0.000000006 .hex()
|
||||
x = -100.0000J
|
||||
|
||||
if 10 .real:
|
||||
...
|
||||
|
||||
y = 100[no]
|
||||
y = 100(no)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,22 +1,22 @@
|
||||
-x = (123456789).bit_count()
|
||||
-x = (123456).__abs__()
|
||||
-x = (0.1).is_integer()
|
||||
-x = (1.0).imag
|
||||
-x = (1e1).imag
|
||||
-x = (1e-1).real
|
||||
-x = (123456789.123456789).hex()
|
||||
-x = (123456789.123456789e123456789).real
|
||||
-x = (123456789e123456789).conjugate()
|
||||
-x = 123456789j.real
|
||||
-x = 123456789.123456789j.__add__(0b1011.bit_length())
|
||||
-x = 0xB1ACC.conjugate()
|
||||
-x = 0b1011.conjugate()
|
||||
-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 = NOT_IMPLEMENTED_call()
|
||||
+x = 123456789J.real
|
||||
+x = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+x = NOT_IMPLEMENTED_call()
|
||||
+x = NOT_IMPLEMENTED_call()
|
||||
+x = (0O777).real
|
||||
+x = NOT_IMPLEMENTED_call()
|
||||
+x = -100.0000J
|
||||
|
||||
if (10).real:
|
||||
...
|
||||
|
||||
y = 100[no]
|
||||
-y = 100(no)
|
||||
+y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
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 = NOT_IMPLEMENTED_call()
|
||||
x = 123456789J.real
|
||||
x = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
x = NOT_IMPLEMENTED_call()
|
||||
x = NOT_IMPLEMENTED_call()
|
||||
x = (0O777).real
|
||||
x = NOT_IMPLEMENTED_call()
|
||||
x = -100.0000J
|
||||
|
||||
if (10).real:
|
||||
...
|
||||
|
||||
y = 100[no]
|
||||
y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
x = (123456789).bit_count()
|
||||
x = (123456).__abs__()
|
||||
x = (0.1).is_integer()
|
||||
x = (1.0).imag
|
||||
x = (1e1).imag
|
||||
x = (1e-1).real
|
||||
x = (123456789.123456789).hex()
|
||||
x = (123456789.123456789e123456789).real
|
||||
x = (123456789e123456789).conjugate()
|
||||
x = 123456789j.real
|
||||
x = 123456789.123456789j.__add__(0b1011.bit_length())
|
||||
x = 0xB1ACC.conjugate()
|
||||
x = 0b1011.conjugate()
|
||||
x = 0o777.real
|
||||
x = (0.000000006).hex()
|
||||
x = -100.0000j
|
||||
|
||||
if (10).real:
|
||||
...
|
||||
|
||||
y = 100[no]
|
||||
y = 100(no)
|
||||
```
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
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")
|
||||
```
|
||||
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
for ((x in {}) or {})['a'] in x:
|
||||
pass
|
||||
pem_spam = lambda l, spam = {
|
||||
"x": 3
|
||||
}: not spam.get(l.strip())
|
||||
lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,4 @@
|
||||
for ((x in {}) or {})["a"] in x:
|
||||
pass
|
||||
-pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
|
||||
-lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
|
||||
+pem_spam = lambda x: True
|
||||
+lambda x: True
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
for ((x in {}) or {})["a"] in x:
|
||||
pass
|
||||
pem_spam = lambda x: True
|
||||
lambda x: True
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
for ((x in {}) or {})["a"] in x:
|
||||
pass
|
||||
pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
|
||||
lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
|
||||
```
|
||||
|
||||
|
|
@ -1,486 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
class ClassSimplest:
|
||||
pass
|
||||
class ClassWithSingleField:
|
||||
a = 1
|
||||
class ClassWithJustTheDocstring:
|
||||
"""Just a docstring."""
|
||||
class ClassWithInit:
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithTheDocstringAndInit:
|
||||
"""Just a docstring."""
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithInitAndVars:
|
||||
cls_var = 100
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInit:
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitAndVars:
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassSimplestWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
class ClassSimplestWithInnerWithDocstring:
|
||||
class Inner:
|
||||
"""Just a docstring."""
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithSingleFieldWithInner:
|
||||
a = 1
|
||||
class Inner:
|
||||
pass
|
||||
class ClassWithJustTheDocstringWithInner:
|
||||
"""Just a docstring."""
|
||||
class Inner:
|
||||
pass
|
||||
class ClassWithInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
"""Test class"""
|
||||
class Inner:
|
||||
pass
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
|
||||
def __init__(self):
|
||||
@@ -54,7 +53,6 @@
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
@@ -109,7 +107,6 @@
|
||||
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
@@ -141,7 +138,6 @@
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class ClassSimplest:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithSingleField:
|
||||
a = 1
|
||||
|
||||
|
||||
class ClassWithJustTheDocstring:
|
||||
"""Just a docstring."""
|
||||
|
||||
|
||||
class ClassWithInit:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithTheDocstringAndInit:
|
||||
"""Just a docstring."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVars:
|
||||
cls_var = 100
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInit:
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVars:
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassSimplestWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassSimplestWithInnerWithDocstring:
|
||||
class Inner:
|
||||
"""Just a docstring."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithSingleFieldWithInner:
|
||||
a = 1
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithJustTheDocstringWithInner:
|
||||
"""Just a docstring."""
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
"""Test class"""
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
class ClassSimplest:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithSingleField:
|
||||
a = 1
|
||||
|
||||
|
||||
class ClassWithJustTheDocstring:
|
||||
"""Just a docstring."""
|
||||
|
||||
|
||||
class ClassWithInit:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithTheDocstringAndInit:
|
||||
"""Just a docstring."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVars:
|
||||
cls_var = 100
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
|
||||
cls_var = 100
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInit:
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVars:
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassSimplestWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassSimplestWithInnerWithDocstring:
|
||||
class Inner:
|
||||
"""Just a docstring."""
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithSingleFieldWithInner:
|
||||
a = 1
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithJustTheDocstringWithInner:
|
||||
"""Just a docstring."""
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
|
||||
cls_var = 100
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
"""Test class"""
|
||||
|
||||
class Inner:
|
||||
pass
|
||||
|
||||
cls_var = 100
|
||||
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,361 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
import core, time, a
|
||||
|
||||
from . import A, B, C
|
||||
|
||||
# keeps existing trailing comma
|
||||
from foo import (
|
||||
bar,
|
||||
)
|
||||
|
||||
# also keeps existing structure
|
||||
from foo import (
|
||||
baz,
|
||||
qux,
|
||||
)
|
||||
|
||||
# `as` works as well
|
||||
from foo import (
|
||||
xyzzy as magic,
|
||||
)
|
||||
|
||||
a = {1,2,3,}
|
||||
b = {
|
||||
1,2,
|
||||
3}
|
||||
c = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
}
|
||||
x = 1,
|
||||
y = narf(),
|
||||
nested = {(1,2,3),(4,5,6),}
|
||||
nested_no_trailing_comma = {(1,2,3),(4,5,6)}
|
||||
nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"]
|
||||
{"oneple": (1,),}
|
||||
{"oneple": (1,)}
|
||||
['ls', 'lsoneple/%s' % (foo,)]
|
||||
x = {"oneple": (1,)}
|
||||
y = {"oneple": (1,),}
|
||||
assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar)
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
pass
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
|
||||
[1, 2, 3,]
|
||||
|
||||
division_result_tuple = (6/2,)
|
||||
print("foo %r", (foo.bar,))
|
||||
|
||||
if True:
|
||||
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||
| {pylons.controllers.WSGIController}
|
||||
)
|
||||
|
||||
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,},
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,40 +1,22 @@
|
||||
-import core, time, a
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-from . import A, B, C
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# keeps existing trailing comma
|
||||
-from foo import (
|
||||
- bar,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# also keeps existing structure
|
||||
-from foo import (
|
||||
- baz,
|
||||
- qux,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# `as` works as well
|
||||
-from foo import (
|
||||
- xyzzy as magic,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-a = {
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-}
|
||||
+a = {1, 2, 3}
|
||||
b = {1, 2, 3}
|
||||
-c = {
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-}
|
||||
+c = {1, 2, 3}
|
||||
x = (1,)
|
||||
-y = (narf(),)
|
||||
-nested = {
|
||||
- (1, 2, 3),
|
||||
- (4, 5, 6),
|
||||
-}
|
||||
+y = (NOT_IMPLEMENTED_call(),)
|
||||
+nested = {(1, 2, 3), (4, 5, 6)}
|
||||
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
|
||||
nested_long_lines = [
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
@@ -52,10 +34,7 @@
|
||||
y = {
|
||||
"oneple": (1,),
|
||||
}
|
||||
-assert False, (
|
||||
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||
- % bar
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
@@ -63,14 +42,10 @@
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
|
||||
-[
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-]
|
||||
+[1, 2, 3]
|
||||
|
||||
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 +54,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
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# keeps existing trailing comma
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# also keeps existing structure
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# `as` works as well
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
a = {1, 2, 3}
|
||||
b = {1, 2, 3}
|
||||
c = {1, 2, 3}
|
||||
x = (1,)
|
||||
y = (NOT_IMPLEMENTED_call(),)
|
||||
nested = {(1, 2, 3), (4, 5, 6)}
|
||||
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
|
||||
nested_long_lines = [
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"cccccccccccccccccccccccccccccccccccccccc",
|
||||
(1, 2, 3),
|
||||
"dddddddddddddddddddddddddddddddddddddddd",
|
||||
]
|
||||
{
|
||||
"oneple": (1,),
|
||||
}
|
||||
{"oneple": (1,)}
|
||||
["ls", "lsoneple/%s" % (foo,)]
|
||||
x = {"oneple": (1,)}
|
||||
y = {
|
||||
"oneple": (1,),
|
||||
}
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
pass
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
|
||||
[1, 2, 3]
|
||||
|
||||
division_result_tuple = (6 / 2,)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
if True:
|
||||
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||
| {pylons.controllers.WSGIController}
|
||||
)
|
||||
|
||||
if True:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
import core, time, a
|
||||
|
||||
from . import A, B, C
|
||||
|
||||
# keeps existing trailing comma
|
||||
from foo import (
|
||||
bar,
|
||||
)
|
||||
|
||||
# also keeps existing structure
|
||||
from foo import (
|
||||
baz,
|
||||
qux,
|
||||
)
|
||||
|
||||
# `as` works as well
|
||||
from foo import (
|
||||
xyzzy as magic,
|
||||
)
|
||||
|
||||
a = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
}
|
||||
b = {1, 2, 3}
|
||||
c = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
}
|
||||
x = (1,)
|
||||
y = (narf(),)
|
||||
nested = {
|
||||
(1, 2, 3),
|
||||
(4, 5, 6),
|
||||
}
|
||||
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
|
||||
nested_long_lines = [
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||
"cccccccccccccccccccccccccccccccccccccccc",
|
||||
(1, 2, 3),
|
||||
"dddddddddddddddddddddddddddddddddddddddd",
|
||||
]
|
||||
{
|
||||
"oneple": (1,),
|
||||
}
|
||||
{"oneple": (1,)}
|
||||
["ls", "lsoneple/%s" % (foo,)]
|
||||
x = {"oneple": (1,)}
|
||||
y = {
|
||||
"oneple": (1,),
|
||||
}
|
||||
assert False, (
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||
% bar
|
||||
)
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
pass
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
]
|
||||
|
||||
division_result_tuple = (6 / 2,)
|
||||
print("foo %r", (foo.bar,))
|
||||
|
||||
if True:
|
||||
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||
| {pylons.controllers.WSGIController}
|
||||
)
|
||||
|
||||
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,
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
def bob(): \
|
||||
# pylint: disable=W9016
|
||||
pass
|
||||
|
||||
|
||||
def bobtwo(): \
|
||||
\
|
||||
# some comment here
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,8 @@
|
||||
-def bob(): # pylint: disable=W9016
|
||||
+def bob():
|
||||
+ # pylint: disable=W9016
|
||||
pass
|
||||
|
||||
|
||||
-def bobtwo(): # some comment here
|
||||
+def bobtwo():
|
||||
+ # some comment here
|
||||
pass
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def bob():
|
||||
# pylint: disable=W9016
|
||||
pass
|
||||
|
||||
|
||||
def bobtwo():
|
||||
# some comment here
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
def bob(): # pylint: disable=W9016
|
||||
pass
|
||||
|
||||
|
||||
def bobtwo(): # some comment here
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,675 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component # DRY
|
||||
)
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
__all__ = [
|
||||
# Super-special typing primitives.
|
||||
'Any',
|
||||
'Callable',
|
||||
'ClassVar',
|
||||
|
||||
# ABCs (from collections.abc).
|
||||
'AbstractSet', # collections.abc.Set.
|
||||
'ByteString',
|
||||
'Container',
|
||||
|
||||
# Concrete collection types.
|
||||
'Counter',
|
||||
'Deque',
|
||||
'Dict',
|
||||
'DefaultDict',
|
||||
'List',
|
||||
'Set',
|
||||
'FrozenSet',
|
||||
'NamedTuple', # Not really a type.
|
||||
'Generator',
|
||||
]
|
||||
|
||||
not_shareables = [
|
||||
# singletons
|
||||
True,
|
||||
False,
|
||||
NotImplemented, ...,
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
object(),
|
||||
Exception(),
|
||||
42,
|
||||
100.0,
|
||||
"spam",
|
||||
# user-defined types and objects
|
||||
Cheese,
|
||||
Cheese("Wensleydale"),
|
||||
SubBytes(b"spam"),
|
||||
]
|
||||
|
||||
if 'PYTHON' in os.environ:
|
||||
add_compiler(compiler_from_env())
|
||||
else:
|
||||
# for compiler in compilers.values():
|
||||
# add_compiler(compiler)
|
||||
add_compiler(compilers[(7.0, 32)])
|
||||
# add_compiler(compilers[(7.1, 64)])
|
||||
|
||||
# Comment before function.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
parameters.children = [
|
||||
children[0], # (1
|
||||
body,
|
||||
children[-1] # )1
|
||||
]
|
||||
parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
]
|
||||
else:
|
||||
parameters.children = [
|
||||
parameters.children[0], # (2 what if this was actually long
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
if (self._proc is not None
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and self._proc.poll() is None):
|
||||
pass
|
||||
# no newline before or after
|
||||
short = [
|
||||
# one
|
||||
1,
|
||||
# two
|
||||
2]
|
||||
|
||||
# no newline after
|
||||
call(arg1, arg2, """
|
||||
short
|
||||
""", arg3=True)
|
||||
|
||||
############################################################################
|
||||
|
||||
call2(
|
||||
#short
|
||||
arg1,
|
||||
#but
|
||||
arg2,
|
||||
#multiline
|
||||
"""
|
||||
short
|
||||
""",
|
||||
# yup
|
||||
arg3=True)
|
||||
lcomp = [
|
||||
element # yup
|
||||
for element in collection # yup
|
||||
if element is not None # right
|
||||
]
|
||||
lcomp2 = [
|
||||
# hello
|
||||
element
|
||||
# yup
|
||||
for element in collection
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split('\n', 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
while True:
|
||||
if False:
|
||||
continue
|
||||
|
||||
# and round and round we go
|
||||
# and round and round we go
|
||||
|
||||
# let's return
|
||||
return Node(
|
||||
syms.simple_stmt,
|
||||
[
|
||||
Node(statement, result),
|
||||
Leaf(token.NEWLINE, '\n') # FIXME: \r\n?
|
||||
],
|
||||
)
|
||||
|
||||
CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
if (parsed.hostname is None or # type: ignore
|
||||
not parsed.hostname.strip()):
|
||||
pass
|
||||
|
||||
#######################
|
||||
### SECTION COMMENT ###
|
||||
#######################
|
||||
|
||||
|
||||
instruction()#comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,9 +1,5 @@
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
-)
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
@@ -37,31 +33,35 @@
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
- object(),
|
||||
- Exception(),
|
||||
+ NOT_IMPLEMENTED_call(),
|
||||
+ NOT_IMPLEMENTED_call(),
|
||||
42,
|
||||
100.0,
|
||||
"spam",
|
||||
# user-defined types and objects
|
||||
Cheese,
|
||||
- Cheese("Wensleydale"),
|
||||
- SubBytes(b"spam"),
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
]
|
||||
|
||||
if "PYTHON" in os.environ:
|
||||
- add_compiler(compiler_from_env())
|
||||
+ 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.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
- parameters.children = [children[0], body, children[-1]] # (1 # )1
|
||||
parameters.children = [
|
||||
+ children[0], # (1
|
||||
+ body,
|
||||
+ children[-1], # )1
|
||||
+ ]
|
||||
+ parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
@@ -72,14 +72,18 @@
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
- parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
+ parameters.children = [
|
||||
+ parameters.what_if_this_was_actually_long.children[0],
|
||||
+ body,
|
||||
+ parameters.children[-1],
|
||||
+ ] # type: ignore
|
||||
if (
|
||||
self._proc is not None
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
- 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 = [
|
||||
- element for element in collection if element is not None # yup # yup # right
|
||||
- ]
|
||||
- lcomp2 = [
|
||||
- # hello
|
||||
- element
|
||||
- # yup
|
||||
- for element in collection
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
- lcomp3 = [
|
||||
- # This one is actually too long to fit in a single line.
|
||||
- element.split("\n", 1)[0]
|
||||
- # yup
|
||||
- for element in collection.select_elements()
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ lcomp = [i for i in []]
|
||||
+ lcomp2 = [i for i in []]
|
||||
+ lcomp3 = [i for i in []]
|
||||
while True:
|
||||
if False:
|
||||
continue
|
||||
@@ -141,24 +111,19 @@
|
||||
# and round and round we go
|
||||
|
||||
# let's return
|
||||
- return Node(
|
||||
- syms.simple_stmt,
|
||||
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
|
||||
- )
|
||||
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-CONFIG_FILES = (
|
||||
- [
|
||||
- CONFIG_FILE,
|
||||
- ]
|
||||
- + SHARED_CONFIG_FILES
|
||||
- + USER_CONFIG_FILES
|
||||
-) # type: Final
|
||||
+CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
|
||||
+ if (
|
||||
+ parsed.hostname
|
||||
+ is None # type: ignore
|
||||
+ or not NOT_IMPLEMENTED_call()
|
||||
+ ):
|
||||
pass
|
||||
|
||||
|
||||
@@ -167,7 +132,7 @@
|
||||
#######################
|
||||
|
||||
|
||||
-instruction() # comment with bad spacing
|
||||
+NOT_IMPLEMENTED_call() # comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
__all__ = [
|
||||
# Super-special typing primitives.
|
||||
"Any",
|
||||
"Callable",
|
||||
"ClassVar",
|
||||
# ABCs (from collections.abc).
|
||||
"AbstractSet", # collections.abc.Set.
|
||||
"ByteString",
|
||||
"Container",
|
||||
# Concrete collection types.
|
||||
"Counter",
|
||||
"Deque",
|
||||
"Dict",
|
||||
"DefaultDict",
|
||||
"List",
|
||||
"Set",
|
||||
"FrozenSet",
|
||||
"NamedTuple", # Not really a type.
|
||||
"Generator",
|
||||
]
|
||||
|
||||
not_shareables = [
|
||||
# singletons
|
||||
True,
|
||||
False,
|
||||
NotImplemented,
|
||||
...,
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
NOT_IMPLEMENTED_call(),
|
||||
NOT_IMPLEMENTED_call(),
|
||||
42,
|
||||
100.0,
|
||||
"spam",
|
||||
# user-defined types and objects
|
||||
Cheese,
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
]
|
||||
|
||||
if "PYTHON" in os.environ:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
# for compiler in compilers.values():
|
||||
# add_compiler(compiler)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# add_compiler(compilers[(7.1, 64)])
|
||||
|
||||
|
||||
# Comment before function.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
parameters.children = [
|
||||
children[0], # (1
|
||||
body,
|
||||
children[-1], # )1
|
||||
]
|
||||
parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
]
|
||||
else:
|
||||
parameters.children = [
|
||||
parameters.children[0], # (2 what if this was actually long
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
parameters.children = [
|
||||
parameters.what_if_this_was_actually_long.children[0],
|
||||
body,
|
||||
parameters.children[-1],
|
||||
] # type: ignore
|
||||
if (
|
||||
self._proc is not None
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and NOT_IMPLEMENTED_call() is None
|
||||
):
|
||||
pass
|
||||
# no newline before or after
|
||||
short = [
|
||||
# one
|
||||
1,
|
||||
# two
|
||||
2,
|
||||
]
|
||||
|
||||
# no newline after
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
############################################################################
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
lcomp = [i for i in []]
|
||||
lcomp2 = [i for i in []]
|
||||
lcomp3 = [i for i in []]
|
||||
while True:
|
||||
if False:
|
||||
continue
|
||||
|
||||
# and round and round we go
|
||||
# and round and round we go
|
||||
|
||||
# let's return
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
if (
|
||||
parsed.hostname
|
||||
is None # type: ignore
|
||||
or not NOT_IMPLEMENTED_call()
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
#######################
|
||||
### SECTION COMMENT ###
|
||||
#######################
|
||||
|
||||
|
||||
NOT_IMPLEMENTED_call() # comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
)
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
__all__ = [
|
||||
# Super-special typing primitives.
|
||||
"Any",
|
||||
"Callable",
|
||||
"ClassVar",
|
||||
# ABCs (from collections.abc).
|
||||
"AbstractSet", # collections.abc.Set.
|
||||
"ByteString",
|
||||
"Container",
|
||||
# Concrete collection types.
|
||||
"Counter",
|
||||
"Deque",
|
||||
"Dict",
|
||||
"DefaultDict",
|
||||
"List",
|
||||
"Set",
|
||||
"FrozenSet",
|
||||
"NamedTuple", # Not really a type.
|
||||
"Generator",
|
||||
]
|
||||
|
||||
not_shareables = [
|
||||
# singletons
|
||||
True,
|
||||
False,
|
||||
NotImplemented,
|
||||
...,
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
object(),
|
||||
Exception(),
|
||||
42,
|
||||
100.0,
|
||||
"spam",
|
||||
# user-defined types and objects
|
||||
Cheese,
|
||||
Cheese("Wensleydale"),
|
||||
SubBytes(b"spam"),
|
||||
]
|
||||
|
||||
if "PYTHON" in os.environ:
|
||||
add_compiler(compiler_from_env())
|
||||
else:
|
||||
# for compiler in compilers.values():
|
||||
# add_compiler(compiler)
|
||||
add_compiler(compilers[(7.0, 32)])
|
||||
# add_compiler(compilers[(7.1, 64)])
|
||||
|
||||
|
||||
# Comment before function.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
parameters.children = [children[0], body, children[-1]] # (1 # )1
|
||||
parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
]
|
||||
else:
|
||||
parameters.children = [
|
||||
parameters.children[0], # (2 what if this was actually long
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
if (
|
||||
self._proc is not None
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and self._proc.poll() is None
|
||||
):
|
||||
pass
|
||||
# no newline before or after
|
||||
short = [
|
||||
# one
|
||||
1,
|
||||
# two
|
||||
2,
|
||||
]
|
||||
|
||||
# no newline after
|
||||
call(
|
||||
arg1,
|
||||
arg2,
|
||||
"""
|
||||
short
|
||||
""",
|
||||
arg3=True,
|
||||
)
|
||||
|
||||
############################################################################
|
||||
|
||||
call2(
|
||||
# short
|
||||
arg1,
|
||||
# but
|
||||
arg2,
|
||||
# multiline
|
||||
"""
|
||||
short
|
||||
""",
|
||||
# yup
|
||||
arg3=True,
|
||||
)
|
||||
lcomp = [
|
||||
element for element in collection if element is not None # yup # yup # right
|
||||
]
|
||||
lcomp2 = [
|
||||
# hello
|
||||
element
|
||||
# yup
|
||||
for element in collection
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split("\n", 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
while True:
|
||||
if False:
|
||||
continue
|
||||
|
||||
# and round and round we go
|
||||
# and round and round we go
|
||||
|
||||
# let's return
|
||||
return Node(
|
||||
syms.simple_stmt,
|
||||
[Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
|
||||
)
|
||||
|
||||
|
||||
CONFIG_FILES = (
|
||||
[
|
||||
CONFIG_FILE,
|
||||
]
|
||||
+ SHARED_CONFIG_FILES
|
||||
+ USER_CONFIG_FILES
|
||||
) # type: Final
|
||||
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
|
||||
pass
|
||||
|
||||
|
||||
#######################
|
||||
### SECTION COMMENT ###
|
||||
#######################
|
||||
|
||||
|
||||
instruction() # comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
```
|
||||
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split("\n", 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if isinstance(exc_value, MultiError):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
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
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -6,43 +6,16 @@
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
- lcomp3 = [
|
||||
- # This one is actually too long to fit in a single line.
|
||||
- element.split("\n", 1)[0]
|
||||
- # yup
|
||||
- for element in collection.select_elements()
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
+ lcomp3 = [i for i in []]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
- if isinstance(exc_value, MultiError):
|
||||
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
- 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)
|
||||
- )
|
||||
+ 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
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
lcomp3 = [i for i in []]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# everything is fine if the expression isn't nested
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split("\n", 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if isinstance(exc_value, MultiError):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
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
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
|
|
@ -1,347 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
)
|
||||
|
||||
|
||||
class C:
|
||||
@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(
|
||||
self, pyramid_config, db_request, post_data, message
|
||||
):
|
||||
pyramid_config.testing_securitypolicy(userid=1)
|
||||
db_request.POST = MultiDict(post_data)
|
||||
|
||||
|
||||
def foo(list_a, list_b):
|
||||
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
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
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):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
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))
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,94 +1,28 @@
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
-)
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
class C:
|
||||
- @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",
|
||||
- ),
|
||||
- ],
|
||||
- )
|
||||
+ @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):
|
||||
- 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()
|
||||
- )
|
||||
+ results = NOT_IMPLEMENTED_call()
|
||||
return results
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
- 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))
|
||||
- )
|
||||
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo3(list_a, list_b):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
- 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))
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
class C:
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def test_fails_invalid_post_data(
|
||||
self, pyramid_config, db_request, post_data, message
|
||||
):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
db_request.POST = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo(list_a, list_b):
|
||||
results = NOT_IMPLEMENTED_call()
|
||||
return results
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo3(list_a, list_b):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
)
|
||||
|
||||
|
||||
class C:
|
||||
@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(
|
||||
self, pyramid_config, db_request, post_data, message
|
||||
):
|
||||
pyramid_config.testing_securitypolicy(userid=1)
|
||||
db_request.POST = MultiDict(post_data)
|
||||
|
||||
|
||||
def foo(list_a, list_b):
|
||||
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
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
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):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
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))
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,305 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
while True:
|
||||
if something.changed:
|
||||
do.stuff() # trailing comment
|
||||
# Comment belongs to the `if` block.
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
|
||||
# This one is properly standalone now.
|
||||
|
||||
for i in range(100):
|
||||
# first we do this
|
||||
if i % 33 == 0:
|
||||
break
|
||||
|
||||
# then we do this
|
||||
print(i)
|
||||
# and finally we loop around
|
||||
|
||||
with open(some_temp_file) as f:
|
||||
data = f.read()
|
||||
|
||||
try:
|
||||
with open(some_other_file) as w:
|
||||
w.write(data)
|
||||
|
||||
except OSError:
|
||||
print("problems")
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
# leading function comment
|
||||
def wat():
|
||||
...
|
||||
# trailing function comment
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading function comment
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# Note: this is fixed in
|
||||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||
# In the current style, the user will have to split those lines by hand.
|
||||
some_instruction
|
||||
|
||||
|
||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||
def g():
|
||||
...
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,6 @@
|
||||
while True:
|
||||
if something.changed:
|
||||
- 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,20 @@
|
||||
|
||||
# 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()
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
-try:
|
||||
- with open(some_other_file) as w:
|
||||
- w.write(data)
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
-except OSError:
|
||||
- print("problems")
|
||||
-
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# leading function comment
|
||||
@@ -42,7 +36,7 @@
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
-@deco2(with_args=True)
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading 3
|
||||
@deco3
|
||||
def decorated1():
|
||||
@@ -52,7 +46,7 @@
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
-@deco2(with_args=True)
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading function comment
|
||||
def decorated1():
|
||||
...
|
||||
@@ -70,4 +64,4 @@
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
- main()
|
||||
+ NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
while True:
|
||||
if something.changed:
|
||||
NOT_IMPLEMENTED_call() # trailing comment
|
||||
# Comment belongs to the `if` block.
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
|
||||
# This one is properly standalone now.
|
||||
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
# first we do this
|
||||
if i % 33 == 0:
|
||||
break
|
||||
|
||||
# then we do this
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# and finally we loop around
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# leading function comment
|
||||
def wat():
|
||||
...
|
||||
# trailing function comment
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading 3
|
||||
@deco3
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading function comment
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# Note: this is fixed in
|
||||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||
# In the current style, the user will have to split those lines by hand.
|
||||
some_instruction
|
||||
|
||||
|
||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||
def g():
|
||||
...
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
while True:
|
||||
if something.changed:
|
||||
do.stuff() # trailing comment
|
||||
# Comment belongs to the `if` block.
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
|
||||
# This one is properly standalone now.
|
||||
|
||||
for i in range(100):
|
||||
# first we do this
|
||||
if i % 33 == 0:
|
||||
break
|
||||
|
||||
# then we do this
|
||||
print(i)
|
||||
# and finally we loop around
|
||||
|
||||
with open(some_temp_file) as f:
|
||||
data = f.read()
|
||||
|
||||
try:
|
||||
with open(some_other_file) as w:
|
||||
w.write(data)
|
||||
|
||||
except OSError:
|
||||
print("problems")
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
# leading function comment
|
||||
def wat():
|
||||
...
|
||||
# trailing function comment
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading function comment
|
||||
def decorated1():
|
||||
...
|
||||
|
||||
|
||||
# Note: this is fixed in
|
||||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||
# In the current style, the user will have to split those lines by hand.
|
||||
some_instruction
|
||||
|
||||
|
||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||
def g():
|
||||
...
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
|
|
@ -1,437 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# test type comments
|
||||
def f(a, b, c, d, e, f, g, h, i):
|
||||
# type: (int, int, int, int, int, int, int, int, int) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
e, # type: int
|
||||
f, # type: int
|
||||
g, # type: int
|
||||
h, # type: int
|
||||
i, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
arg, # type: int
|
||||
*args, # type: *Any
|
||||
default=False, # type: bool
|
||||
**kwargs, # type: **Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
|
||||
element = 0 # type: int
|
||||
another_element = 1 # type: float
|
||||
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
|
||||
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||
|
||||
tup = (
|
||||
another_element,
|
||||
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||
) # type: Tuple[int, int]
|
||||
|
||||
a = (
|
||||
element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
+ element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
) # type: int
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
y, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
): # type: (int) -> None
|
||||
pass
|
||||
|
||||
|
||||
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 = call(
|
||||
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||
)
|
||||
|
||||
|
||||
result = ( # aaa
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
|
||||
AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||
|
||||
call_to_some_function_asdf(
|
||||
foo,
|
||||
[AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,4 @@
|
||||
-from typing import Any, Tuple
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
def f(
|
||||
@@ -49,10 +49,11 @@
|
||||
element = 0 # type: int
|
||||
another_element = 1 # type: float
|
||||
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
|
||||
- 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
|
||||
+ an_element_with_a_long_value = (
|
||||
+ NOT_IMPLEMENTED_call()
|
||||
+ or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
|
||||
+ ) # type: bool
|
||||
|
||||
tup = (
|
||||
another_element,
|
||||
@@ -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(
|
||||
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||
- )
|
||||
+ c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-result = ( # aaa
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
-)
|
||||
+result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
|
||||
|
||||
-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||
+AAAAAAAAAAAAA = (
|
||||
+ [AAAAAAAAAAAAA]
|
||||
+ + SHARED_AAAAAAAAAAAAA
|
||||
+ + USER_AAAAAAAAAAAAA
|
||||
+ + AAAAAAAAAAAAA
|
||||
+) # type: ignore
|
||||
|
||||
-call_to_some_function_asdf(
|
||||
- foo,
|
||||
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||
-)
|
||||
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
-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]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# test type comments
|
||||
def f(a, b, c, d, e, f, g, h, i):
|
||||
# type: (int, int, int, int, int, int, int, int, int) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
e, # type: int
|
||||
f, # type: int
|
||||
g, # type: int
|
||||
h, # type: int
|
||||
i, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
arg, # type: int
|
||||
*args, # type: *Any
|
||||
default=False, # type: bool
|
||||
**kwargs, # type: **Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
|
||||
element = 0 # type: int
|
||||
another_element = 1 # type: float
|
||||
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
|
||||
an_element_with_a_long_value = (
|
||||
NOT_IMPLEMENTED_call()
|
||||
or NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
|
||||
) # type: bool
|
||||
|
||||
tup = (
|
||||
another_element,
|
||||
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||
) # type: Tuple[int, int]
|
||||
|
||||
a = (
|
||||
element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
+ element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
) # type: int
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
y, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
): # type: (int) -> None
|
||||
pass
|
||||
|
||||
|
||||
def func(
|
||||
a=some_list[0], # type: int
|
||||
): # type: () -> int
|
||||
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
|
||||
|
||||
AAAAAAAAAAAAA = (
|
||||
[AAAAAAAAAAAAA]
|
||||
+ SHARED_AAAAAAAAAAAAA
|
||||
+ USER_AAAAAAAAAAAAA
|
||||
+ AAAAAAAAAAAAA
|
||||
) # type: ignore
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
from typing import Any, Tuple
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# test type comments
|
||||
def f(a, b, c, d, e, f, g, h, i):
|
||||
# type: (int, int, int, int, int, int, int, int, int) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
e, # type: int
|
||||
f, # type: int
|
||||
g, # type: int
|
||||
h, # type: int
|
||||
i, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
arg, # type: int
|
||||
*args, # type: *Any
|
||||
default=False, # type: bool
|
||||
**kwargs, # type: **Any
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
b, # type: int
|
||||
c, # type: int
|
||||
d, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
|
||||
element = 0 # type: int
|
||||
another_element = 1 # type: float
|
||||
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
|
||||
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||
|
||||
tup = (
|
||||
another_element,
|
||||
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||
) # type: Tuple[int, int]
|
||||
|
||||
a = (
|
||||
element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
+ element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
) # type: int
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
y, # type: int
|
||||
):
|
||||
# type: (...) -> None
|
||||
pass
|
||||
|
||||
|
||||
def f(
|
||||
x, # not a type comment
|
||||
): # type: (int) -> None
|
||||
pass
|
||||
|
||||
|
||||
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 = call(
|
||||
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||
)
|
||||
|
||||
|
||||
result = ( # aaa
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
|
||||
AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||
|
||||
call_to_some_function_asdf(
|
||||
foo,
|
||||
[AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||
)
|
||||
|
||||
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||
```
|
||||
|
||||
|
|
@ -1,530 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
# This comment should be split from the statement above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This comment should be split from the statement above by two lines.
|
||||
async def async_function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This comment should be split from the statement above by two lines.
|
||||
class MyClass:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This should be stick to the statement above
|
||||
|
||||
# This should be split from the above by two lines
|
||||
class MyClassWithComplexLeadingComments:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
# Leading comment after a class with just a docstring
|
||||
class MyClassAfterAnotherClassWithDocstring:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
# leading 2 extra
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
|
||||
# leading 4 that already has an empty line
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
if a:
|
||||
# Leading comment before inline function
|
||||
def inline():
|
||||
pass
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
if a:
|
||||
# Leading comment before "top-level inline" function
|
||||
def top_level_quote_inline():
|
||||
pass
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
class MyClass:
|
||||
# First method has no empty lines between bare class def.
|
||||
# More comments.
|
||||
def first_method(self):
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function
|
||||
|
||||
|
||||
@decorator1
|
||||
@decorator2 # fmt: skip
|
||||
def bar():
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function.
|
||||
# NOTE this comment only has one empty line below, and the formatter
|
||||
# should enforce two blank lines.
|
||||
|
||||
@decorator1
|
||||
# A standalone comment
|
||||
def bar():
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ 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 @@
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
-
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
@@ -121,7 +120,6 @@
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
-
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
async def async_function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
class MyClass:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This should be stick to the statement above
|
||||
|
||||
|
||||
# This should be split from the above by two lines
|
||||
class MyClassWithComplexLeadingComments:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
|
||||
|
||||
# Leading comment after a class with just a docstring
|
||||
class MyClassAfterAnotherClassWithDocstring:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
# leading 2 extra
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading 3
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# leading 3
|
||||
@deco3
|
||||
|
||||
# leading 4 that already has an empty line
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
if a:
|
||||
# Leading comment before inline function
|
||||
def inline():
|
||||
pass
|
||||
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
if a:
|
||||
# Leading comment before "top-level inline" function
|
||||
def top_level_quote_inline():
|
||||
pass
|
||||
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
class MyClass:
|
||||
# First method has no empty lines between bare class def.
|
||||
# More comments.
|
||||
def first_method(self):
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function
|
||||
|
||||
|
||||
@decorator1
|
||||
@decorator2 # fmt: skip
|
||||
def bar():
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function.
|
||||
# NOTE this comment only has one empty line below, and the formatter
|
||||
# should enforce two blank lines.
|
||||
|
||||
|
||||
@decorator1
|
||||
# A standalone comment
|
||||
def bar():
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
def function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
async def async_function():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
class MyClass:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
# This should be stick to the statement above
|
||||
|
||||
|
||||
# This should be split from the above by two lines
|
||||
class MyClassWithComplexLeadingComments:
|
||||
pass
|
||||
|
||||
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
|
||||
|
||||
# Leading comment after a class with just a docstring
|
||||
class MyClassAfterAnotherClassWithDocstring:
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
# leading 2 extra
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
some = statement
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
|
||||
# leading 4 that already has an empty line
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
if a:
|
||||
# Leading comment before inline function
|
||||
def inline():
|
||||
pass
|
||||
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
if a:
|
||||
# Leading comment before "top-level inline" function
|
||||
def top_level_quote_inline():
|
||||
pass
|
||||
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
pass
|
||||
|
||||
|
||||
class MyClass:
|
||||
# First method has no empty lines between bare class def.
|
||||
# More comments.
|
||||
def first_method(self):
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function
|
||||
|
||||
|
||||
@decorator1
|
||||
@decorator2 # fmt: skip
|
||||
def bar():
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
# Trailing comment that belongs to this function.
|
||||
# NOTE this comment only has one empty line below, and the formatter
|
||||
# should enforce two blank lines.
|
||||
|
||||
|
||||
@decorator1
|
||||
# A standalone comment
|
||||
def bar():
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
from .config import ( ConfigTypeAttributes, Int, Path, # String,
|
||||
# DEFAULT_TYPE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
result = 1 # A simple comment
|
||||
result = ( 1, ) # Another one
|
||||
|
||||
result = 1 # type: ignore
|
||||
result = 1# This comment is talking about type: ignore
|
||||
square = Square(4) # type: Optional[Square]
|
||||
|
||||
def function(a:int=42):
|
||||
""" This docstring is already formatted
|
||||
a
|
||||
b
|
||||
"""
|
||||
# There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,22 +1,17 @@
|
||||
-from .config import (
|
||||
- ConfigTypeAttributes,
|
||||
- Int,
|
||||
- Path, # String,
|
||||
- # DEFAULT_TYPE_ATTRIBUTES,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
result = 1 # A simple comment
|
||||
result = (1,) # Another one
|
||||
|
||||
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):
|
||||
- """This docstring is already formatted
|
||||
- a
|
||||
- b
|
||||
+ """ This docstring is already formatted
|
||||
+ a
|
||||
+ b
|
||||
"""
|
||||
# There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
result = 1 # A simple comment
|
||||
result = (1,) # Another one
|
||||
|
||||
result = 1 # type: ignore
|
||||
result = 1 # This comment is talking about type: ignore
|
||||
square = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: Optional[Square]
|
||||
|
||||
|
||||
def function(a: int = 42):
|
||||
""" This docstring is already formatted
|
||||
a
|
||||
b
|
||||
"""
|
||||
# There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
from .config import (
|
||||
ConfigTypeAttributes,
|
||||
Int,
|
||||
Path, # String,
|
||||
# DEFAULT_TYPE_ATTRIBUTES,
|
||||
)
|
||||
|
||||
result = 1 # A simple comment
|
||||
result = (1,) # Another one
|
||||
|
||||
result = 1 # type: ignore
|
||||
result = 1 # This comment is talking about type: ignore
|
||||
square = Square(4) # type: Optional[Square]
|
||||
|
||||
|
||||
def function(a: int = 42):
|
||||
"""This docstring is already formatted
|
||||
a
|
||||
b
|
||||
"""
|
||||
# There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,393 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
# fmt: on
|
||||
# Some license here.
|
||||
#
|
||||
# Has many lines. Many, many lines.
|
||||
# Many, many, many lines.
|
||||
"""Module docstring.
|
||||
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
import a
|
||||
from b.c import X # some noqa comment
|
||||
|
||||
try:
|
||||
import fast
|
||||
except ImportError:
|
||||
import slow as fast
|
||||
|
||||
|
||||
# Some comment before a function.
|
||||
y = 1
|
||||
(
|
||||
# some strings
|
||||
y # type: ignore
|
||||
)
|
||||
|
||||
|
||||
def function(default=None):
|
||||
"""Docstring comes first.
|
||||
|
||||
Possibly many lines.
|
||||
"""
|
||||
# FIXME: Some comment about why this function is crap but still in production.
|
||||
import inner_imports
|
||||
|
||||
if inner_imports.are_evil():
|
||||
# Explains why we have this if.
|
||||
# In great detail indeed.
|
||||
x = X()
|
||||
return x.method1() # 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)}
|
||||
|
||||
|
||||
# Another comment!
|
||||
# This time two lines.
|
||||
|
||||
|
||||
class Foo:
|
||||
"""Docstring for class Foo. Example from Sphinx docs."""
|
||||
|
||||
#: Doc comment for class attribute Foo.bar.
|
||||
#: It can have multiple lines.
|
||||
bar = 1
|
||||
|
||||
flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||
|
||||
baz = 2
|
||||
"""Docstring for class attribute Foo.baz."""
|
||||
|
||||
def __init__(self):
|
||||
#: Doc comment for instance attribute qux.
|
||||
self.qux = 3
|
||||
|
||||
self.spam = 4
|
||||
"""Docstring for instance attribute spam."""
|
||||
|
||||
|
||||
#' <h1>This is pweave!</h1>
|
||||
|
||||
|
||||
@fast(really=True)
|
||||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
async with X.open_async() as x: # Some more comments
|
||||
result = await x.method1()
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
print("A OK", file=sys.stdout)
|
||||
# Comment between things.
|
||||
print()
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
# Who knows.
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -9,16 +9,13 @@
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
|
||||
-import os.path
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-import a
|
||||
-from b.c import X # some noqa comment
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
||||
|
||||
-try:
|
||||
- import fast
|
||||
-except ImportError:
|
||||
- import slow as fast
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
# Some comment before a function.
|
||||
@@ -35,20 +32,24 @@
|
||||
Possibly many lines.
|
||||
"""
|
||||
# FIXME: Some comment about why this function is crap but still in production.
|
||||
- import inner_imports
|
||||
+ NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
- if inner_imports.are_evil():
|
||||
+ if NOT_IMPLEMENTED_call():
|
||||
# Explains why we have this if.
|
||||
# In great detail indeed.
|
||||
- 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():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
- async with X.open_async() as x: # Some more comments
|
||||
- result = await x.method1()
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
- print("A OK", file=sys.stdout)
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# Comment between things.
|
||||
- print()
|
||||
+ NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
-# Who knows.
|
||||
\ No newline at end of file
|
||||
+# Who knows.
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
# fmt: on
|
||||
# Some license here.
|
||||
#
|
||||
# Has many lines. Many, many lines.
|
||||
# Many, many, many lines.
|
||||
"""Module docstring.
|
||||
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
# Some comment before a function.
|
||||
y = 1
|
||||
(
|
||||
# some strings
|
||||
y # type: ignore
|
||||
)
|
||||
|
||||
|
||||
def function(default=None):
|
||||
"""Docstring comes first.
|
||||
|
||||
Possibly many lines.
|
||||
"""
|
||||
# FIXME: Some comment about why this function is crap but still in production.
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
if NOT_IMPLEMENTED_call():
|
||||
# Explains why we have this if.
|
||||
# In great detail indeed.
|
||||
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": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
"b": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
"c": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
|
||||
}
|
||||
|
||||
|
||||
# Another comment!
|
||||
# This time two lines.
|
||||
|
||||
|
||||
class Foo:
|
||||
"""Docstring for class Foo. Example from Sphinx docs."""
|
||||
|
||||
#: Doc comment for class attribute Foo.bar.
|
||||
#: It can have multiple lines.
|
||||
bar = 1
|
||||
|
||||
flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||
|
||||
baz = 2
|
||||
"""Docstring for class attribute Foo.baz."""
|
||||
|
||||
def __init__(self):
|
||||
#: Doc comment for instance attribute qux.
|
||||
self.qux = 3
|
||||
|
||||
self.spam = 4
|
||||
"""Docstring for instance attribute spam."""
|
||||
|
||||
|
||||
#' <h1>This is pweave!</h1>
|
||||
|
||||
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# Comment between things.
|
||||
NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
# Who knows.
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
# fmt: on
|
||||
# Some license here.
|
||||
#
|
||||
# Has many lines. Many, many lines.
|
||||
# Many, many, many lines.
|
||||
"""Module docstring.
|
||||
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
import a
|
||||
from b.c import X # some noqa comment
|
||||
|
||||
try:
|
||||
import fast
|
||||
except ImportError:
|
||||
import slow as fast
|
||||
|
||||
|
||||
# Some comment before a function.
|
||||
y = 1
|
||||
(
|
||||
# some strings
|
||||
y # type: ignore
|
||||
)
|
||||
|
||||
|
||||
def function(default=None):
|
||||
"""Docstring comes first.
|
||||
|
||||
Possibly many lines.
|
||||
"""
|
||||
# FIXME: Some comment about why this function is crap but still in production.
|
||||
import inner_imports
|
||||
|
||||
if inner_imports.are_evil():
|
||||
# Explains why we have this if.
|
||||
# In great detail indeed.
|
||||
x = X()
|
||||
return x.method1() # 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)}
|
||||
|
||||
|
||||
# Another comment!
|
||||
# This time two lines.
|
||||
|
||||
|
||||
class Foo:
|
||||
"""Docstring for class Foo. Example from Sphinx docs."""
|
||||
|
||||
#: Doc comment for class attribute Foo.bar.
|
||||
#: It can have multiple lines.
|
||||
bar = 1
|
||||
|
||||
flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||
|
||||
baz = 2
|
||||
"""Docstring for class attribute Foo.baz."""
|
||||
|
||||
def __init__(self):
|
||||
#: Doc comment for instance attribute qux.
|
||||
self.qux = 3
|
||||
|
||||
self.spam = 4
|
||||
"""Docstring for instance attribute spam."""
|
||||
|
||||
|
||||
#' <h1>This is pweave!</h1>
|
||||
|
||||
|
||||
@fast(really=True)
|
||||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
async with X.open_async() as x: # Some more comments
|
||||
result = await x.method1()
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
print("A OK", file=sys.stdout)
|
||||
# Comment between things.
|
||||
print()
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
# Who knows.```
|
||||
|
||||
|
|
@ -1,644 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
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.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
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 (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
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]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,159 +1,42 @@
|
||||
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.",
|
||||
- )
|
||||
- for i in (a,):
|
||||
- if (
|
||||
- # Rule 1
|
||||
- i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
- ):
|
||||
- while (
|
||||
- # Just a comment
|
||||
- call()
|
||||
- # Another
|
||||
- ):
|
||||
- print(i)
|
||||
- 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]
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtWith
|
||||
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
- 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]
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex]
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][
|
||||
+ ThreeLevelIndex
|
||||
+ ][
|
||||
+ FourLevelIndex
|
||||
+ ]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
- assignment = (
|
||||
- some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
- )
|
||||
+ assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123]
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ), "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ) == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- " because it's too long"
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- dis_c_instance_method = """\
|
||||
+ dis_c_instance_method = (
|
||||
+ """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
@@ -161,21 +44,8 @@
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
- """ % (
|
||||
- _C.__init__.__code__.co_firstlineno + 1,
|
||||
+ """
|
||||
+ % (_C.__init__.__code__.co_firstlineno + 1,)
|
||||
)
|
||||
|
||||
- assert (
|
||||
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
- == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex]
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][
|
||||
ThreeLevelIndex
|
||||
][
|
||||
FourLevelIndex
|
||||
]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123]
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
dis_c_instance_method = (
|
||||
"""\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
"""
|
||||
% (_C.__init__.__code__.co_firstlineno + 1,)
|
||||
)
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
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.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
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 (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
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]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,644 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
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.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
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 (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
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]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,159 +1,42 @@
|
||||
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.",
|
||||
- )
|
||||
- for i in (a,):
|
||||
- if (
|
||||
- # Rule 1
|
||||
- i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
- ):
|
||||
- while (
|
||||
- # Just a comment
|
||||
- call()
|
||||
- # Another
|
||||
- ):
|
||||
- print(i)
|
||||
- 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]
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtWith
|
||||
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
- 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]
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex]
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][
|
||||
+ ThreeLevelIndex
|
||||
+ ][
|
||||
+ FourLevelIndex
|
||||
+ ]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
- assignment = (
|
||||
- some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
- )
|
||||
+ assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123]
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ), "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ) == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- " because it's too long"
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
- dis_c_instance_method = """\
|
||||
+ dis_c_instance_method = (
|
||||
+ """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
@@ -161,21 +44,8 @@
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
- """ % (
|
||||
- _C.__init__.__code__.co_firstlineno + 1,
|
||||
+ """
|
||||
+ % (_C.__init__.__code__.co_firstlineno + 1,)
|
||||
)
|
||||
|
||||
- assert (
|
||||
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
- == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex]
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)[OneLevelIndex][TwoLevelIndex][
|
||||
ThreeLevelIndex
|
||||
][
|
||||
FourLevelIndex
|
||||
]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = NOT_IMPLEMENTED_call() and another.rule.ending_with.index[123]
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
dis_c_instance_method = (
|
||||
"""\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
"""
|
||||
% (_C.__init__.__code__.co_firstlineno + 1,)
|
||||
)
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
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.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
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 (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
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]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................
|
||||
"""
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def docstring_at_line_limit_with_prefix():
|
||||
f"""long docstring..............................................................."""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit_with_prefix():
|
||||
f"""first line----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit():
|
||||
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit2():
|
||||
'We do not want to put the closing quote on a new line as that is invalid (see GH-3141).'
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,9 +1,10 @@
|
||||
def docstring_almost_at_line_limit():
|
||||
- """long docstring................................................................."""
|
||||
+ """long docstring.................................................................
|
||||
+ """
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit_with_prefix():
|
||||
- f"""long docstring................................................................"""
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
@@ -14,10 +15,7 @@
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
- f"""long docstring................................................................
|
||||
-
|
||||
- ..................................................................................
|
||||
- """
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
@@ -25,7 +23,7 @@
|
||||
|
||||
|
||||
def docstring_at_line_limit_with_prefix():
|
||||
- f"""long docstring..............................................................."""
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
@@ -35,9 +33,7 @@
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit_with_prefix():
|
||||
- f"""first line----------------------------------------------------------------------
|
||||
-
|
||||
- second line----------------------------------------------------------------------"""
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit():
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit_with_prefix():
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def docstring_at_line_limit_with_prefix():
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit_with_prefix():
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit():
|
||||
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit2():
|
||||
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................"""
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def docstring_at_line_limit_with_prefix():
|
||||
f"""long docstring..............................................................."""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit_with_prefix():
|
||||
f"""first line----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit():
|
||||
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit2():
|
||||
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||
```
|
||||
|
||||
|
|
@ -1,925 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
class MyClass:
|
||||
""" Multiline
|
||||
class docstring
|
||||
"""
|
||||
|
||||
def method(self):
|
||||
"""Multiline
|
||||
method docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
"""This is a docstring with
|
||||
some lines of text here
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def bar():
|
||||
'''This is another docstring
|
||||
with more lines of text
|
||||
'''
|
||||
return
|
||||
|
||||
|
||||
def baz():
|
||||
'''"This" is a string with some
|
||||
embedded "quotes"'''
|
||||
return
|
||||
|
||||
|
||||
def troz():
|
||||
'''Indentation with tabs
|
||||
is just as OK
|
||||
'''
|
||||
return
|
||||
|
||||
|
||||
def zort():
|
||||
"""Another
|
||||
multiline
|
||||
docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
def poit():
|
||||
"""
|
||||
Lorem ipsum dolor sit amet.
|
||||
|
||||
Consectetur adipiscing elit:
|
||||
- sed do eiusmod tempor incididunt ut labore
|
||||
- dolore magna aliqua
|
||||
- enim ad minim veniam
|
||||
- quis nostrud exercitation ullamco laboris nisi
|
||||
- aliquip ex ea commodo consequat
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def under_indent():
|
||||
"""
|
||||
These lines are indented in a way that does not
|
||||
make sense.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def over_indent():
|
||||
"""
|
||||
This has a shallow indent
|
||||
- But some lines are deeper
|
||||
- And the closing quote is too deep
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def single_line():
|
||||
"""But with a newline after it!
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def this():
|
||||
r"""
|
||||
'hey ho'
|
||||
"""
|
||||
|
||||
|
||||
def that():
|
||||
""" "hey yah" """
|
||||
|
||||
|
||||
def and_that():
|
||||
"""
|
||||
"hey yah" """
|
||||
|
||||
|
||||
def and_this():
|
||||
'''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
''' '''
|
||||
|
||||
|
||||
def empty():
|
||||
""""""
|
||||
|
||||
|
||||
def single_quotes():
|
||||
'testing'
|
||||
|
||||
|
||||
def believe_it_or_not_this_is_in_the_py_stdlib(): '''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def ignored_docstring():
|
||||
"""a => \
|
||||
b"""
|
||||
|
||||
def single_line_docstring_with_whitespace():
|
||||
""" This should be stripped """
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_tab_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def backslash_space():
|
||||
"""\ """
|
||||
|
||||
|
||||
def multiline_backslash_1():
|
||||
'''
|
||||
hey\there\
|
||||
\ '''
|
||||
|
||||
|
||||
def multiline_backslash_2():
|
||||
'''
|
||||
hey there \ '''
|
||||
|
||||
# Regression test for #3425
|
||||
def multiline_backslash_really_long_dont_crash():
|
||||
"""
|
||||
hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||
|
||||
|
||||
def multiline_backslash_3():
|
||||
'''
|
||||
already escaped \\ '''
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
"I'm sorry Dave\u2001"
|
||||
|
||||
|
||||
# the space below is actually a \u2001, removed in output
|
||||
def my_god_its_full_of_stars_2():
|
||||
"I'm sorry Dave "
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit2():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
''''<text here>
|
||||
|
||||
<text here, since without another non-empty line black is stable>
|
||||
'''
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,83 +1,85 @@
|
||||
class MyClass:
|
||||
- """Multiline
|
||||
- class docstring
|
||||
- """
|
||||
+ """ Multiline
|
||||
+ class docstring
|
||||
+ """
|
||||
|
||||
def method(self):
|
||||
"""Multiline
|
||||
- method docstring
|
||||
- """
|
||||
+ method docstring
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
- """This is a docstring with
|
||||
- some lines of text here
|
||||
- """
|
||||
+ """This is a docstring with
|
||||
+ some lines of text here
|
||||
+ """
|
||||
return
|
||||
|
||||
|
||||
def bar():
|
||||
"""This is another docstring
|
||||
- with more lines of text
|
||||
- """
|
||||
+ with more lines of text
|
||||
+ """
|
||||
return
|
||||
|
||||
|
||||
def baz():
|
||||
'''"This" is a string with some
|
||||
- embedded "quotes"'''
|
||||
+ embedded "quotes"'''
|
||||
return
|
||||
|
||||
|
||||
def troz():
|
||||
"""Indentation with tabs
|
||||
- is just as OK
|
||||
- """
|
||||
+ is just as OK
|
||||
+ """
|
||||
return
|
||||
|
||||
|
||||
def zort():
|
||||
"""Another
|
||||
- multiline
|
||||
- docstring
|
||||
- """
|
||||
+ multiline
|
||||
+ docstring
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
def poit():
|
||||
"""
|
||||
- Lorem ipsum dolor sit amet.
|
||||
+ Lorem ipsum dolor sit amet.
|
||||
|
||||
- Consectetur adipiscing elit:
|
||||
- - sed do eiusmod tempor incididunt ut labore
|
||||
- - dolore magna aliqua
|
||||
- - enim ad minim veniam
|
||||
- - quis nostrud exercitation ullamco laboris nisi
|
||||
- - aliquip ex ea commodo consequat
|
||||
- """
|
||||
+ Consectetur adipiscing elit:
|
||||
+ - sed do eiusmod tempor incididunt ut labore
|
||||
+ - dolore magna aliqua
|
||||
+ - enim ad minim veniam
|
||||
+ - quis nostrud exercitation ullamco laboris nisi
|
||||
+ - aliquip ex ea commodo consequat
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
def under_indent():
|
||||
"""
|
||||
- These lines are indented in a way that does not
|
||||
- make sense.
|
||||
- """
|
||||
+ These lines are indented in a way that does not
|
||||
+make sense.
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
def over_indent():
|
||||
"""
|
||||
- This has a shallow indent
|
||||
- - But some lines are deeper
|
||||
- - And the closing quote is too deep
|
||||
+ This has a shallow indent
|
||||
+ - But some lines are deeper
|
||||
+ - And the closing quote is too deep
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def single_line():
|
||||
- """But with a newline after it!"""
|
||||
+ """But with a newline after it!
|
||||
+
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
@@ -93,20 +95,25 @@
|
||||
|
||||
def and_that():
|
||||
"""
|
||||
- "hey yah" """
|
||||
+ "hey yah" """
|
||||
|
||||
|
||||
def and_this():
|
||||
- '''
|
||||
- "hey yah"'''
|
||||
+ '''
|
||||
+ "hey yah"'''
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
- """ """
|
||||
+ """
|
||||
+
|
||||
+
|
||||
+
|
||||
+
|
||||
+ """
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
- """ """
|
||||
+ """ """
|
||||
|
||||
|
||||
def empty():
|
||||
@@ -118,8 +125,8 @@
|
||||
|
||||
|
||||
def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||
- '''
|
||||
- "hey yah"'''
|
||||
+ '''
|
||||
+"hey yah"'''
|
||||
|
||||
|
||||
def ignored_docstring():
|
||||
@@ -128,31 +135,31 @@
|
||||
|
||||
|
||||
def single_line_docstring_with_whitespace():
|
||||
- """This should be stripped"""
|
||||
+ """ This should be stripped """
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
- tab at start of line and then a tab separated value
|
||||
- multiple tabs at the beginning and inline
|
||||
- mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
-
|
||||
- line ends with some tabs
|
||||
+ tab at start of line and then a tab separated value
|
||||
+ multiple tabs at the beginning and inline
|
||||
+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
+
|
||||
+ line ends with some tabs
|
||||
"""
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_tab_indentation():
|
||||
"""hey
|
||||
|
||||
- tab separated value
|
||||
- tab at start of line and then a tab separated value
|
||||
- multiple tabs at the beginning and inline
|
||||
- mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
-
|
||||
- line ends with some tabs
|
||||
- """
|
||||
+ tab separated value
|
||||
+ tab at start of line and then a tab separated value
|
||||
+ multiple tabs at the beginning and inline
|
||||
+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
+
|
||||
+ line ends with some tabs
|
||||
+ """
|
||||
pass
|
||||
|
||||
|
||||
@@ -168,7 +175,7 @@
|
||||
|
||||
def multiline_backslash_2():
|
||||
"""
|
||||
- hey there \ """
|
||||
+ hey there \ """
|
||||
|
||||
|
||||
# Regression test for #3425
|
||||
@@ -179,7 +186,7 @@
|
||||
|
||||
def multiline_backslash_3():
|
||||
"""
|
||||
- already escaped \\"""
|
||||
+ already escaped \\ """
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
@@ -188,7 +195,7 @@
|
||||
|
||||
# the space below is actually a \u2001, removed in output
|
||||
def my_god_its_full_of_stars_2():
|
||||
- "I'm sorry Dave"
|
||||
+ "I'm sorry Dave "
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class MyClass:
|
||||
""" Multiline
|
||||
class docstring
|
||||
"""
|
||||
|
||||
def method(self):
|
||||
"""Multiline
|
||||
method docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
"""This is a docstring with
|
||||
some lines of text here
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def bar():
|
||||
"""This is another docstring
|
||||
with more lines of text
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def baz():
|
||||
'''"This" is a string with some
|
||||
embedded "quotes"'''
|
||||
return
|
||||
|
||||
|
||||
def troz():
|
||||
"""Indentation with tabs
|
||||
is just as OK
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def zort():
|
||||
"""Another
|
||||
multiline
|
||||
docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def poit():
|
||||
"""
|
||||
Lorem ipsum dolor sit amet.
|
||||
|
||||
Consectetur adipiscing elit:
|
||||
- sed do eiusmod tempor incididunt ut labore
|
||||
- dolore magna aliqua
|
||||
- enim ad minim veniam
|
||||
- quis nostrud exercitation ullamco laboris nisi
|
||||
- aliquip ex ea commodo consequat
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def under_indent():
|
||||
"""
|
||||
These lines are indented in a way that does not
|
||||
make sense.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def over_indent():
|
||||
"""
|
||||
This has a shallow indent
|
||||
- But some lines are deeper
|
||||
- And the closing quote is too deep
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def single_line():
|
||||
"""But with a newline after it!
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def this():
|
||||
r"""
|
||||
'hey ho'
|
||||
"""
|
||||
|
||||
|
||||
def that():
|
||||
""" "hey yah" """
|
||||
|
||||
|
||||
def and_that():
|
||||
"""
|
||||
"hey yah" """
|
||||
|
||||
|
||||
def and_this():
|
||||
'''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
""" """
|
||||
|
||||
|
||||
def empty():
|
||||
""""""
|
||||
|
||||
|
||||
def single_quotes():
|
||||
"testing"
|
||||
|
||||
|
||||
def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||
'''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def ignored_docstring():
|
||||
"""a => \
|
||||
b"""
|
||||
|
||||
|
||||
def single_line_docstring_with_whitespace():
|
||||
""" This should be stripped """
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_tab_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def backslash_space():
|
||||
"""\ """
|
||||
|
||||
|
||||
def multiline_backslash_1():
|
||||
"""
|
||||
hey\there\
|
||||
\ """
|
||||
|
||||
|
||||
def multiline_backslash_2():
|
||||
"""
|
||||
hey there \ """
|
||||
|
||||
|
||||
# Regression test for #3425
|
||||
def multiline_backslash_really_long_dont_crash():
|
||||
"""
|
||||
hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||
|
||||
|
||||
def multiline_backslash_3():
|
||||
"""
|
||||
already escaped \\ """
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
"I'm sorry Dave\u2001"
|
||||
|
||||
|
||||
# the space below is actually a \u2001, removed in output
|
||||
def my_god_its_full_of_stars_2():
|
||||
"I'm sorry Dave "
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit2():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
"""'<text here>
|
||||
|
||||
<text here, since without another non-empty line black is stable>
|
||||
"""
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
class MyClass:
|
||||
"""Multiline
|
||||
class docstring
|
||||
"""
|
||||
|
||||
def method(self):
|
||||
"""Multiline
|
||||
method docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def foo():
|
||||
"""This is a docstring with
|
||||
some lines of text here
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def bar():
|
||||
"""This is another docstring
|
||||
with more lines of text
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def baz():
|
||||
'''"This" is a string with some
|
||||
embedded "quotes"'''
|
||||
return
|
||||
|
||||
|
||||
def troz():
|
||||
"""Indentation with tabs
|
||||
is just as OK
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
def zort():
|
||||
"""Another
|
||||
multiline
|
||||
docstring
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def poit():
|
||||
"""
|
||||
Lorem ipsum dolor sit amet.
|
||||
|
||||
Consectetur adipiscing elit:
|
||||
- sed do eiusmod tempor incididunt ut labore
|
||||
- dolore magna aliqua
|
||||
- enim ad minim veniam
|
||||
- quis nostrud exercitation ullamco laboris nisi
|
||||
- aliquip ex ea commodo consequat
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def under_indent():
|
||||
"""
|
||||
These lines are indented in a way that does not
|
||||
make sense.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def over_indent():
|
||||
"""
|
||||
This has a shallow indent
|
||||
- But some lines are deeper
|
||||
- And the closing quote is too deep
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def single_line():
|
||||
"""But with a newline after it!"""
|
||||
pass
|
||||
|
||||
|
||||
def this():
|
||||
r"""
|
||||
'hey ho'
|
||||
"""
|
||||
|
||||
|
||||
def that():
|
||||
""" "hey yah" """
|
||||
|
||||
|
||||
def and_that():
|
||||
"""
|
||||
"hey yah" """
|
||||
|
||||
|
||||
def and_this():
|
||||
'''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
""" """
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
""" """
|
||||
|
||||
|
||||
def empty():
|
||||
""""""
|
||||
|
||||
|
||||
def single_quotes():
|
||||
"testing"
|
||||
|
||||
|
||||
def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||
'''
|
||||
"hey yah"'''
|
||||
|
||||
|
||||
def ignored_docstring():
|
||||
"""a => \
|
||||
b"""
|
||||
|
||||
|
||||
def single_line_docstring_with_whitespace():
|
||||
"""This should be stripped"""
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_tab_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def backslash_space():
|
||||
"""\ """
|
||||
|
||||
|
||||
def multiline_backslash_1():
|
||||
"""
|
||||
hey\there\
|
||||
\ """
|
||||
|
||||
|
||||
def multiline_backslash_2():
|
||||
"""
|
||||
hey there \ """
|
||||
|
||||
|
||||
# Regression test for #3425
|
||||
def multiline_backslash_really_long_dont_crash():
|
||||
"""
|
||||
hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||
|
||||
|
||||
def multiline_backslash_3():
|
||||
"""
|
||||
already escaped \\"""
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
"I'm sorry Dave\u2001"
|
||||
|
||||
|
||||
# the space below is actually a \u2001, removed in output
|
||||
def my_god_its_full_of_stars_2():
|
||||
"I'm sorry Dave"
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit2():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
|
||||
|
||||
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
"""'<text here>
|
||||
|
||||
<text here, since without another non-empty line black is stable>
|
||||
"""
|
||||
```
|
||||
|
||||
|
|
@ -1,411 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
"""Docstring."""
|
||||
|
||||
|
||||
# leading comment
|
||||
def f():
|
||||
NO = ''
|
||||
SPACE = ' '
|
||||
DOUBLESPACE = ' '
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent # trailing comment
|
||||
v = leaf.value
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
|
||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
|
||||
|
||||
return NO
|
||||
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
|
||||
elif prevp.type == token.DOUBLESTAR:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.dictsetmaker,
|
||||
}:
|
||||
return NO
|
||||
|
||||
###############################################################################
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
|
||||
def g():
|
||||
NO = ''
|
||||
SPACE = ' '
|
||||
DOUBLESPACE = ' '
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent
|
||||
v = leaf.value
|
||||
|
||||
# Comment because comments
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT:
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}'
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
# Start of the line or a bracketed expression.
|
||||
# More than one line for the comment.
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -16,32 +16,40 @@
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
- prevp = preceding_leaf(p)
|
||||
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.argument,
|
||||
- }:
|
||||
+ if (
|
||||
+ prevp.parent
|
||||
+ and prevp.parent.type
|
||||
+ in {
|
||||
+ syms.typedargslist,
|
||||
+ syms.varargslist,
|
||||
+ syms.parameters,
|
||||
+ syms.arglist,
|
||||
+ syms.argument,
|
||||
+ }
|
||||
+ ):
|
||||
return NO
|
||||
|
||||
elif prevp.type == token.DOUBLESTAR:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.dictsetmaker,
|
||||
- }:
|
||||
+ if (
|
||||
+ prevp.parent
|
||||
+ and prevp.parent.type
|
||||
+ in {
|
||||
+ syms.typedargslist,
|
||||
+ syms.varargslist,
|
||||
+ syms.parameters,
|
||||
+ syms.arglist,
|
||||
+ syms.dictsetmaker,
|
||||
+ }
|
||||
+ ):
|
||||
return NO
|
||||
|
||||
|
||||
@@ -49,7 +57,6 @@
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
|
||||
-
|
||||
def g():
|
||||
NO = ""
|
||||
SPACE = " "
|
||||
@@ -67,11 +74,11 @@
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
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 @@
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.argument,
|
||||
- }:
|
||||
+ if (
|
||||
+ prevp.parent
|
||||
+ and prevp.parent.type
|
||||
+ in {
|
||||
+ syms.typedargslist,
|
||||
+ syms.varargslist,
|
||||
+ syms.parameters,
|
||||
+ syms.arglist,
|
||||
+ syms.argument,
|
||||
+ }
|
||||
+ ):
|
||||
return NO
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
"""Docstring."""
|
||||
|
||||
|
||||
# leading comment
|
||||
def f():
|
||||
NO = ""
|
||||
SPACE = " "
|
||||
DOUBLESPACE = " "
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent # trailing comment
|
||||
v = leaf.value
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if (
|
||||
prevp.parent
|
||||
and prevp.parent.type
|
||||
in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}
|
||||
):
|
||||
return NO
|
||||
|
||||
elif prevp.type == token.DOUBLESTAR:
|
||||
if (
|
||||
prevp.parent
|
||||
and prevp.parent.type
|
||||
in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.dictsetmaker,
|
||||
}
|
||||
):
|
||||
return NO
|
||||
|
||||
|
||||
###############################################################################
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
|
||||
def g():
|
||||
NO = ""
|
||||
SPACE = " "
|
||||
DOUBLESPACE = " "
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent
|
||||
v = leaf.value
|
||||
|
||||
# Comment because comments
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT:
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
# Start of the line or a bracketed expression.
|
||||
# More than one line for the comment.
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if (
|
||||
prevp.parent
|
||||
and prevp.parent.type
|
||||
in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}
|
||||
):
|
||||
return NO
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
"""Docstring."""
|
||||
|
||||
|
||||
# leading comment
|
||||
def f():
|
||||
NO = ""
|
||||
SPACE = " "
|
||||
DOUBLESPACE = " "
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent # trailing comment
|
||||
v = leaf.value
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
|
||||
elif prevp.type == token.DOUBLESTAR:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.dictsetmaker,
|
||||
}:
|
||||
return NO
|
||||
|
||||
|
||||
###############################################################################
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
|
||||
|
||||
def g():
|
||||
NO = ""
|
||||
SPACE = " "
|
||||
DOUBLESPACE = " "
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent
|
||||
v = leaf.value
|
||||
|
||||
# Comment because comments
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT:
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
# Start of the line or a bracketed expression.
|
||||
# More than one line for the comment.
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
```
|
||||
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,198 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
import pytest
|
||||
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
|
||||
# fmt: off
|
||||
|
||||
# Test data:
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
@pytest.mark.parametrize('test', [
|
||||
|
||||
# Test don't manage the volume
|
||||
[
|
||||
('stuff', 'in')
|
||||
],
|
||||
])
|
||||
def test_fader(test):
|
||||
pass
|
||||
|
||||
def check_fader(test):
|
||||
|
||||
pass
|
||||
|
||||
def verify_fader(test):
|
||||
# misaligned comment
|
||||
pass
|
||||
|
||||
def verify_fader(test):
|
||||
"""Hey, ho."""
|
||||
assert test.passed()
|
||||
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
(0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
(None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
]
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,40 +1,38 @@
|
||||
-import pytest
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
|
||||
# fmt: off
|
||||
|
||||
+
|
||||
# Test data:
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
-@pytest.mark.parametrize('test', [
|
||||
-
|
||||
- # Test don't manage the volume
|
||||
- [
|
||||
- ('stuff', 'in')
|
||||
- ],
|
||||
-])
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def test_fader(test):
|
||||
pass
|
||||
|
||||
+
|
||||
def check_fader(test):
|
||||
+ pass
|
||||
|
||||
- pass
|
||||
|
||||
def verify_fader(test):
|
||||
- # misaligned comment
|
||||
+ # misaligned comment
|
||||
pass
|
||||
|
||||
+
|
||||
def verify_fader(test):
|
||||
"""Hey, ho."""
|
||||
- assert test.passed()
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
+
|
||||
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
- (0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
- (None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
+ (0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
+ (None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
]
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
|
||||
# fmt: off
|
||||
|
||||
|
||||
# Test data:
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def test_fader(test):
|
||||
pass
|
||||
|
||||
|
||||
def check_fader(test):
|
||||
pass
|
||||
|
||||
|
||||
def verify_fader(test):
|
||||
# misaligned comment
|
||||
pass
|
||||
|
||||
|
||||
def verify_fader(test):
|
||||
"""Hey, ho."""
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
(0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
(None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
]
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
import pytest
|
||||
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
|
||||
# fmt: off
|
||||
|
||||
# Test data:
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
@pytest.mark.parametrize('test', [
|
||||
|
||||
# Test don't manage the volume
|
||||
[
|
||||
('stuff', 'in')
|
||||
],
|
||||
])
|
||||
def test_fader(test):
|
||||
pass
|
||||
|
||||
def check_fader(test):
|
||||
|
||||
pass
|
||||
|
||||
def verify_fader(test):
|
||||
# misaligned comment
|
||||
pass
|
||||
|
||||
def verify_fader(test):
|
||||
"""Hey, ho."""
|
||||
assert test.passed()
|
||||
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
(0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
(None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
]
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
x = [
|
||||
1, 2, 3, 4
|
||||
]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,15 +1,9 @@
|
||||
# fmt: off
|
||||
-x = [
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-]
|
||||
+x = [1, 2, 3, 4]
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
-x = [
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-]
|
||||
+x = [1, 2, 3, 4]
|
||||
# fmt: on
|
||||
|
||||
x = [1, 2, 3, 4]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
x = [1, 2, 3, 4]
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
x = [1, 2, 3, 4]
|
||||
# fmt: on
|
||||
|
||||
x = [1, 2, 3, 4]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
x = [1, 2, 3, 4]
|
||||
```
|
||||
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
3, 4,
|
||||
])
|
||||
# fmt: on
|
||||
def f(): pass
|
||||
|
||||
@test([
|
||||
1, 2,
|
||||
3, 4,
|
||||
])
|
||||
def f(): pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,20 +1,10 @@
|
||||
# fmt: off
|
||||
-@test([
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-])
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# fmt: on
|
||||
def f():
|
||||
pass
|
||||
|
||||
|
||||
-@test(
|
||||
- [
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
- 4,
|
||||
- ]
|
||||
-)
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def f():
|
||||
pass
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# fmt: on
|
||||
def f():
|
||||
pass
|
||||
|
||||
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def f():
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
3, 4,
|
||||
])
|
||||
# fmt: on
|
||||
def f():
|
||||
pass
|
||||
|
||||
|
||||
@test(
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
]
|
||||
)
|
||||
def f():
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,366 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
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.
|
||||
run(
|
||||
# fmt: off
|
||||
[
|
||||
"ls",
|
||||
"-la",
|
||||
]
|
||||
# fmt: on
|
||||
+ path,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
def test_func():
|
||||
# yapf: disable
|
||||
if unformatted( args ):
|
||||
return True
|
||||
# yapf: enable
|
||||
elif b:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
if True:
|
||||
# fmt: off
|
||||
for _ in range( 1 ):
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
print ( "This won't be formatted either" )
|
||||
else:
|
||||
print ( "This will be formatted" )
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
class A:
|
||||
async def call(param):
|
||||
if param:
|
||||
# fmt: off
|
||||
if param[0:4] in (
|
||||
"ABCD", "EFGH"
|
||||
) :
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
print ( "This won't be formatted either" )
|
||||
|
||||
print ( "This will be formatted" )
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
class Named(t.Protocol):
|
||||
# fmt: off
|
||||
@property
|
||||
def this_wont_be_formatted ( self ) -> str: ...
|
||||
|
||||
class Factory(t.Protocol):
|
||||
def this_will_be_formatted ( self, **kwargs ) -> Named: ...
|
||||
# fmt: on
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3436.
|
||||
if x:
|
||||
return x
|
||||
# fmt: off
|
||||
elif unformatted:
|
||||
# fmt: on
|
||||
will_be_formatted ()
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,33 +1,15 @@
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
-setup(
|
||||
- entry_points={
|
||||
- # fmt: off
|
||||
- "console_scripts": [
|
||||
- "foo-bar"
|
||||
- "=foo.bar.:main",
|
||||
- # 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)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
def test_func():
|
||||
# yapf: disable
|
||||
- if unformatted( args ):
|
||||
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
return True
|
||||
# yapf: enable
|
||||
elif b:
|
||||
@@ -39,12 +21,12 @@
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
if True:
|
||||
# fmt: off
|
||||
- for _ in range( 1 ):
|
||||
- # fmt: on
|
||||
- print ( "This won't be formatted" )
|
||||
- print ( "This won't be formatted either" )
|
||||
+ for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ # fmt: on
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
- print("This will be formatted")
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
@@ -52,29 +34,27 @@
|
||||
async def call(param):
|
||||
if param:
|
||||
# fmt: off
|
||||
- if param[0:4] in (
|
||||
- "ABCD", "EFGH"
|
||||
- ) :
|
||||
+ if param[0:4] in ("ABCD", "EFGH"):
|
||||
# fmt: on
|
||||
- print ( "This won't be formatted" )
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
- print ( "This won't be formatted either" )
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
- print("This will be formatted")
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
class Named(t.Protocol):
|
||||
# fmt: off
|
||||
@property
|
||||
- def this_wont_be_formatted ( self ) -> str: ...
|
||||
+ def this_wont_be_formatted(self) -> str:
|
||||
+ ...
|
||||
|
||||
|
||||
class Factory(t.Protocol):
|
||||
def this_will_be_formatted(self, **kwargs) -> Named:
|
||||
...
|
||||
-
|
||||
# fmt: on
|
||||
|
||||
|
||||
@@ -82,6 +62,6 @@
|
||||
if x:
|
||||
return x
|
||||
# fmt: off
|
||||
-elif unformatted:
|
||||
+elif unformatted:
|
||||
# fmt: on
|
||||
- will_be_formatted()
|
||||
+ NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2015.
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
def test_func():
|
||||
# yapf: disable
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
return True
|
||||
# yapf: enable
|
||||
elif b:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
if True:
|
||||
# fmt: off
|
||||
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
# fmt: on
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
class A:
|
||||
async def call(param):
|
||||
if param:
|
||||
# fmt: off
|
||||
if param[0:4] in ("ABCD", "EFGH"):
|
||||
# fmt: on
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
class Named(t.Protocol):
|
||||
# fmt: off
|
||||
@property
|
||||
def this_wont_be_formatted(self) -> str:
|
||||
...
|
||||
|
||||
|
||||
class Factory(t.Protocol):
|
||||
def this_will_be_formatted(self, **kwargs) -> Named:
|
||||
...
|
||||
# fmt: on
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3436.
|
||||
if x:
|
||||
return x
|
||||
# fmt: off
|
||||
elif unformatted:
|
||||
# fmt: on
|
||||
NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
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.
|
||||
run(
|
||||
# fmt: off
|
||||
[
|
||||
"ls",
|
||||
"-la",
|
||||
]
|
||||
# fmt: on
|
||||
+ path,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
def test_func():
|
||||
# yapf: disable
|
||||
if unformatted( args ):
|
||||
return True
|
||||
# yapf: enable
|
||||
elif b:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
if True:
|
||||
# fmt: off
|
||||
for _ in range( 1 ):
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
print ( "This won't be formatted either" )
|
||||
else:
|
||||
print("This will be formatted")
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
class A:
|
||||
async def call(param):
|
||||
if param:
|
||||
# fmt: off
|
||||
if param[0:4] in (
|
||||
"ABCD", "EFGH"
|
||||
) :
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
print ( "This won't be formatted either" )
|
||||
|
||||
print("This will be formatted")
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
class Named(t.Protocol):
|
||||
# fmt: off
|
||||
@property
|
||||
def this_wont_be_formatted ( self ) -> str: ...
|
||||
|
||||
|
||||
class Factory(t.Protocol):
|
||||
def this_will_be_formatted(self, **kwargs) -> Named:
|
||||
...
|
||||
|
||||
# fmt: on
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3436.
|
||||
if x:
|
||||
return x
|
||||
# fmt: off
|
||||
elif unformatted:
|
||||
# fmt: on
|
||||
will_be_formatted()
|
||||
```
|
||||
|
||||
|
|
@ -1,912 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from third_party import X, Y, Z
|
||||
|
||||
from library import some_connection, \
|
||||
some_decorator
|
||||
# fmt: off
|
||||
from third_party import (X,
|
||||
Y, Z)
|
||||
# fmt: on
|
||||
f'trigger 3.6 mode'
|
||||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
a; b; c
|
||||
if True: raise RuntimeError
|
||||
if False: ...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec('new-style exec', {}, {})
|
||||
return None
|
||||
async def coroutine(arg, exec=False):
|
||||
'Single-line docstring. Multiline is harder to reformat.'
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
many_args=[1,2,3]
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
# fmt: on
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2)))
|
||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
def spaces2(result= _core.Value(None)):
|
||||
...
|
||||
something = {
|
||||
# fmt: off
|
||||
key: 'value',
|
||||
}
|
||||
|
||||
def subscriptlist():
|
||||
atom[
|
||||
# fmt: off
|
||||
'some big and',
|
||||
'complex subscript',
|
||||
# fmt: on
|
||||
goes + here, andhere,
|
||||
]
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
from hello import a, b
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
a , b = *hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
def yield_expr():
|
||||
# fmt: off
|
||||
yield hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
'formatted'
|
||||
# fmt: off
|
||||
( yield hello )
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
def example(session):
|
||||
# fmt: off
|
||||
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
|
||||
def off_and_on_without_data():
|
||||
"""All comments here are technically on the same prefix.
|
||||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
# fmt: off
|
||||
|
||||
|
||||
#hey, that won't work
|
||||
|
||||
|
||||
# fmt: on
|
||||
pass
|
||||
def on_and_off_broken():
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
this=should.not_be.formatted()
|
||||
and_=indeed . it is not formatted
|
||||
because . the . handling . inside . generate_ignored_nodes()
|
||||
now . considers . multiple . fmt . directives . within . one . prefix
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
# ...but comments still get reformatted even though they should not be
|
||||
# fmt: on
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
||||
)
|
||||
# fmt: off
|
||||
a = (
|
||||
unnecessary_bracket()
|
||||
)
|
||||
# fmt: on
|
||||
_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():
|
||||
"""Black does not support this."""
|
||||
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
|
||||
)
|
||||
# fmt: off
|
||||
yield 'hello'
|
||||
# No formatting to the end of the file
|
||||
l=[1,2,3]
|
||||
d={'a':1,
|
||||
'b':2}
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,16 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
-import asyncio
|
||||
-import sys
|
||||
-
|
||||
-from third_party import X, Y, Z
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-from library import some_connection, some_decorator
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: off
|
||||
-from third_party import (X,
|
||||
- Y, Z)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: on
|
||||
-f"trigger 3.6 mode"
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
@@ -18,30 +16,53 @@
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
- a; b; c
|
||||
- if True: raise RuntimeError
|
||||
- if False: ...
|
||||
- for i in range(10):
|
||||
- print(i)
|
||||
- continue
|
||||
- exec('new-style exec', {}, {})
|
||||
- return None
|
||||
+ a
|
||||
+ b
|
||||
+ c
|
||||
+ if True:
|
||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
||||
+ if False:
|
||||
+ ...
|
||||
+ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ continue
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ return None
|
||||
+
|
||||
+
|
||||
async def coroutine(arg, exec=False):
|
||||
- 'Single-line docstring. Multiline is harder to reformat.'
|
||||
- async with some_connection() as conn:
|
||||
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
- await asyncio.sleep(1)
|
||||
+ "Single-line docstring. Multiline is harder to reformat."
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+
|
||||
+
|
||||
@asyncio.coroutine
|
||||
-@some_decorator(
|
||||
-with_args=True,
|
||||
-many_args=[1,2,3]
|
||||
-)
|
||||
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
- return text[number:-1]
|
||||
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+def function_signature_stress_test(
|
||||
+ number: int,
|
||||
+ no_annotation=None,
|
||||
+ text: str = "default",
|
||||
+ *,
|
||||
+ debug: bool = False,
|
||||
+ **kwargs,
|
||||
+) -> str:
|
||||
+ return text[number : -1]
|
||||
+
|
||||
+
|
||||
# fmt: on
|
||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
|
||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
+def spaces(
|
||||
+ a=1,
|
||||
+ b=(),
|
||||
+ c=[],
|
||||
+ d={},
|
||||
+ e=True,
|
||||
+ f=-1,
|
||||
+ g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
+ h="",
|
||||
+ i=r"",
|
||||
+):
|
||||
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def spaces_types(
|
||||
@@ -51,68 +72,66 @@
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
- g: int = 1 if False else 2,
|
||||
+ g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
-def spaces2(result=_core.Value(None)):
|
||||
+def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
|
||||
...
|
||||
|
||||
|
||||
something = {
|
||||
# fmt: off
|
||||
- key: 'value',
|
||||
+ key: "value",
|
||||
}
|
||||
|
||||
|
||||
def subscriptlist():
|
||||
atom[
|
||||
# fmt: off
|
||||
- 'some big and',
|
||||
- 'complex subscript',
|
||||
- # fmt: on
|
||||
- goes + here,
|
||||
- andhere,
|
||||
+ (
|
||||
+ "some big and",
|
||||
+ "complex subscript",
|
||||
+ # fmt: on
|
||||
+ goes
|
||||
+ + here,
|
||||
+ andhere,
|
||||
+ )
|
||||
]
|
||||
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
- from hello import a, b
|
||||
- 'unformatted'
|
||||
+ NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+ "unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
- a , b = *hello
|
||||
- 'unformatted'
|
||||
+ a, b = NOT_YET_IMPLEMENTED_ExprStarred
|
||||
+ "unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def yield_expr():
|
||||
# fmt: off
|
||||
- yield hello
|
||||
- 'unformatted'
|
||||
+ NOT_YET_IMPLEMENTED_ExprYield
|
||||
+ "unformatted"
|
||||
# fmt: on
|
||||
"formatted"
|
||||
# fmt: off
|
||||
- ( yield hello )
|
||||
- 'unformatted'
|
||||
+ (NOT_YET_IMPLEMENTED_ExprYield)
|
||||
+ "unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def example(session):
|
||||
# fmt: off
|
||||
- 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()
|
||||
+ result = NOT_IMPLEMENTED_call()
|
||||
# fmt: on
|
||||
|
||||
|
||||
@@ -133,10 +152,10 @@
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
- this=should.not_be.formatted()
|
||||
- and_=indeed . it is not formatted
|
||||
- because . the . handling . inside . generate_ignored_nodes()
|
||||
- now . considers . multiple . fmt . directives . within . one . prefix
|
||||
+ this = NOT_IMPLEMENTED_call()
|
||||
+ and_ = indeed.it is not formatted
|
||||
+ NOT_IMPLEMENTED_call()
|
||||
+ now.considers.multiple.fmt.directives.within.one.prefix
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
# ...but comments still get reformatted even though they should not be
|
||||
@@ -145,43 +164,11 @@
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
- typedargslist.extend(
|
||||
- gen_annotated_params(
|
||||
- ast_args.kwonlyargs,
|
||||
- ast_args.kw_defaults,
|
||||
- parameters,
|
||||
- implicit_default=True,
|
||||
- )
|
||||
- )
|
||||
- # fmt: off
|
||||
- a = (
|
||||
- unnecessary_bracket()
|
||||
- )
|
||||
- # fmt: on
|
||||
- _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?
|
||||
- )
|
||||
- $
|
||||
- """,
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# fmt: off
|
||||
- re.MULTILINE|re.VERBOSE
|
||||
+ a = NOT_IMPLEMENTED_call()
|
||||
# fmt: on
|
||||
- )
|
||||
+ _type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def single_literal_yapf_disable():
|
||||
@@ -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
|
||||
-yield 'hello'
|
||||
+NOT_YET_IMPLEMENTED_ExprYield
|
||||
# No formatting to the end of the file
|
||||
-l=[1,2,3]
|
||||
-d={'a':1,
|
||||
- 'b':2}
|
||||
+l = [1, 2, 3]
|
||||
+d = {"a": 1, "b": 2}
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: off
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: on
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
a
|
||||
b
|
||||
c
|
||||
if True:
|
||||
NOT_YET_IMPLEMENTED_StmtRaise
|
||||
if False:
|
||||
...
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
continue
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return None
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def function_signature_stress_test(
|
||||
number: int,
|
||||
no_annotation=None,
|
||||
text: str = "default",
|
||||
*,
|
||||
debug: bool = False,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
return text[number : -1]
|
||||
|
||||
|
||||
# fmt: on
|
||||
def spaces(
|
||||
a=1,
|
||||
b=(),
|
||||
c=[],
|
||||
d={},
|
||||
e=True,
|
||||
f=-1,
|
||||
g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h="",
|
||||
i=r"",
|
||||
):
|
||||
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def spaces_types(
|
||||
a: int = 1,
|
||||
b: tuple = (),
|
||||
c: list = [],
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
|
||||
...
|
||||
|
||||
|
||||
something = {
|
||||
# fmt: off
|
||||
key: "value",
|
||||
}
|
||||
|
||||
|
||||
def subscriptlist():
|
||||
atom[
|
||||
# fmt: off
|
||||
(
|
||||
"some big and",
|
||||
"complex subscript",
|
||||
# fmt: on
|
||||
goes
|
||||
+ here,
|
||||
andhere,
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
"unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
a, b = NOT_YET_IMPLEMENTED_ExprStarred
|
||||
"unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def yield_expr():
|
||||
# fmt: off
|
||||
NOT_YET_IMPLEMENTED_ExprYield
|
||||
"unformatted"
|
||||
# fmt: on
|
||||
"formatted"
|
||||
# fmt: off
|
||||
(NOT_YET_IMPLEMENTED_ExprYield)
|
||||
"unformatted"
|
||||
# fmt: on
|
||||
|
||||
|
||||
def example(session):
|
||||
# fmt: off
|
||||
result = NOT_IMPLEMENTED_call()
|
||||
# fmt: on
|
||||
|
||||
|
||||
def off_and_on_without_data():
|
||||
"""All comments here are technically on the same prefix.
|
||||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
# fmt: off
|
||||
|
||||
# hey, that won't work
|
||||
|
||||
# fmt: on
|
||||
pass
|
||||
|
||||
|
||||
def on_and_off_broken():
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
this = NOT_IMPLEMENTED_call()
|
||||
and_ = indeed.it is not formatted
|
||||
NOT_IMPLEMENTED_call()
|
||||
now.considers.multiple.fmt.directives.within.one.prefix
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
# ...but comments still get reformatted even though they should not be
|
||||
# fmt: on
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# fmt: off
|
||||
a = NOT_IMPLEMENTED_call()
|
||||
# fmt: on
|
||||
_type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def single_literal_yapf_disable():
|
||||
"""Black does not support this."""
|
||||
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# fmt: off
|
||||
NOT_YET_IMPLEMENTED_ExprYield
|
||||
# No formatting to the end of the file
|
||||
l = [1, 2, 3]
|
||||
d = {"a": 1, "b": 2}
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from third_party import X, Y, Z
|
||||
|
||||
from library import some_connection, some_decorator
|
||||
|
||||
# fmt: off
|
||||
from third_party import (X,
|
||||
Y, Z)
|
||||
# fmt: on
|
||||
f"trigger 3.6 mode"
|
||||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
a; b; c
|
||||
if True: raise RuntimeError
|
||||
if False: ...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec('new-style exec', {}, {})
|
||||
return None
|
||||
async def coroutine(arg, exec=False):
|
||||
'Single-line docstring. Multiline is harder to reformat.'
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
many_args=[1,2,3]
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
# fmt: on
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
|
||||
assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
|
||||
|
||||
def spaces_types(
|
||||
a: int = 1,
|
||||
b: tuple = (),
|
||||
c: list = [],
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
g: int = 1 if False else 2,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def spaces2(result=_core.Value(None)):
|
||||
...
|
||||
|
||||
|
||||
something = {
|
||||
# fmt: off
|
||||
key: 'value',
|
||||
}
|
||||
|
||||
|
||||
def subscriptlist():
|
||||
atom[
|
||||
# fmt: off
|
||||
'some big and',
|
||||
'complex subscript',
|
||||
# fmt: on
|
||||
goes + here,
|
||||
andhere,
|
||||
]
|
||||
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
from hello import a, b
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
a , b = *hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
|
||||
def yield_expr():
|
||||
# fmt: off
|
||||
yield hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
"formatted"
|
||||
# fmt: off
|
||||
( yield hello )
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
|
||||
|
||||
def example(session):
|
||||
# fmt: off
|
||||
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
|
||||
|
||||
|
||||
def off_and_on_without_data():
|
||||
"""All comments here are technically on the same prefix.
|
||||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
# fmt: off
|
||||
|
||||
# hey, that won't work
|
||||
|
||||
# fmt: on
|
||||
pass
|
||||
|
||||
|
||||
def on_and_off_broken():
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
this=should.not_be.formatted()
|
||||
and_=indeed . it is not formatted
|
||||
because . the . handling . inside . generate_ignored_nodes()
|
||||
now . considers . multiple . fmt . directives . within . one . prefix
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
# ...but comments still get reformatted even though they should not be
|
||||
# fmt: on
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(
|
||||
ast_args.kwonlyargs,
|
||||
ast_args.kw_defaults,
|
||||
parameters,
|
||||
implicit_default=True,
|
||||
)
|
||||
)
|
||||
# fmt: off
|
||||
a = (
|
||||
unnecessary_bracket()
|
||||
)
|
||||
# fmt: on
|
||||
_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():
|
||||
"""Black does not support this."""
|
||||
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,
|
||||
)
|
||||
# fmt: off
|
||||
yield 'hello'
|
||||
# No formatting to the end of the file
|
||||
l=[1,2,3]
|
||||
d={'a':1,
|
||||
'b':2}
|
||||
```
|
||||
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
l3 = ["I have", "trailing comma", "so I should be braked",]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -3,9 +3,9 @@
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
-l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
-l3 = [
|
||||
- "I have",
|
||||
- "trailing comma",
|
||||
- "so I should be braked",
|
||||
-]
|
||||
+l2 = [
|
||||
+ "But this list shouldn't",
|
||||
+ "even though it also has",
|
||||
+ "way too many characters in it",
|
||||
+] # fmt: skip
|
||||
+l3 = ["I have", "trailing comma", "so I should be braked"]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
l1 = [
|
||||
"This list should be broken up",
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
l2 = [
|
||||
"But this list shouldn't",
|
||||
"even though it also has",
|
||||
"way too many characters in it",
|
||||
] # fmt: skip
|
||||
l3 = ["I have", "trailing comma", "so I should be braked"]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
l1 = [
|
||||
"This list should be broken up",
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
l3 = [
|
||||
"I have",
|
||||
"trailing comma",
|
||||
"so I should be braked",
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a = 3
|
||||
# fmt: off
|
||||
b, c = 1, 2
|
||||
d = 6 # fmt: skip
|
||||
e = 5
|
||||
# fmt: on
|
||||
f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,7 +1,7 @@
|
||||
a = 3
|
||||
# fmt: off
|
||||
-b, c = 1, 2
|
||||
-d = 6 # fmt: skip
|
||||
+b, c = 1, 2
|
||||
+d = 6 # fmt: skip
|
||||
e = 5
|
||||
# fmt: on
|
||||
f = [
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = 3
|
||||
# fmt: off
|
||||
b, c = 1, 2
|
||||
d = 6 # fmt: skip
|
||||
e = 5
|
||||
# fmt: on
|
||||
f = [
|
||||
"This is a very long line that should be formatted into a clearer line ",
|
||||
"by rearranging.",
|
||||
]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a = 3
|
||||
# fmt: off
|
||||
b, c = 1, 2
|
||||
d = 6 # fmt: skip
|
||||
e = 5
|
||||
# fmt: on
|
||||
f = [
|
||||
"This is a very long line that should be formatted into a clearer line ",
|
||||
"by rearranging.",
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a = 2
|
||||
# fmt: skip
|
||||
l = [1, 2, 3,]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,7 +1,3 @@
|
||||
a = 2
|
||||
# fmt: skip
|
||||
-l = [
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-]
|
||||
+l = [1, 2, 3]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = 2
|
||||
# fmt: skip
|
||||
l = [1, 2, 3]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a = 2
|
||||
# fmt: skip
|
||||
l = [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
and b != 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
print("I'm good!")
|
||||
else:
|
||||
print("I'm bad")
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,9 +1,10 @@
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
- and b != 9 # fmt: skip
|
||||
+ and b
|
||||
+ != 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
- print("I'm good!")
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
- print("I'm bad")
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
and b
|
||||
!= 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
and b != 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
print("I'm good!")
|
||||
else:
|
||||
print("I'm bad")
|
||||
```
|
||||
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
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
|
||||
```
|
||||
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 #fmt:skip
|
||||
c = 9 #fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,4 @@
|
||||
a = "this is some code"
|
||||
-b = 5 # fmt:skip
|
||||
+b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
|
|
@ -1,294 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Make sure a leading comment is not removed.
|
||||
def some_func( unformatted, args ): # fmt: skip
|
||||
print("I am some_func")
|
||||
return 0
|
||||
# Make sure this comment is not removed.
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
async def some_async_func( unformatted, args): # fmt: skip
|
||||
print("I am some_async_func")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
||||
def some_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_method")
|
||||
return 0
|
||||
|
||||
async def some_async_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_async_method")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
if unformatted_call( args ): # fmt: skip
|
||||
print("First branch")
|
||||
# Make sure this is not removed.
|
||||
elif another_unformatted_call( args ): # fmt: skip
|
||||
print("Second branch")
|
||||
else : # fmt: skip
|
||||
print("Last branch")
|
||||
|
||||
|
||||
while some_condition( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
for i in some_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
try : # fmt: skip
|
||||
some_call()
|
||||
except UnformattedError as ex: # fmt: skip
|
||||
handle_exception()
|
||||
finally : # fmt: skip
|
||||
finally_call()
|
||||
|
||||
|
||||
with give_me_context( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,62 +1,54 @@
|
||||
# Make sure a leading comment is not removed.
|
||||
-def some_func( unformatted, args ): # fmt: skip
|
||||
- print("I am some_func")
|
||||
+def some_func(unformatted, args): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return 0
|
||||
# Make sure this comment is not removed.
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
-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
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
-class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
||||
- def some_method( self, unformatted, args ): # fmt: skip
|
||||
- print("I am some_method")
|
||||
+class SomeClass(Unformatted, SuperClasses): # fmt: skip
|
||||
+ def some_method(self, unformatted, args): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return 0
|
||||
|
||||
- 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
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
-if unformatted_call( args ): # fmt: skip
|
||||
- print("First branch")
|
||||
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# Make sure this is not removed.
|
||||
-elif another_unformatted_call( args ): # fmt: skip
|
||||
- print("Second branch")
|
||||
-else : # fmt: skip
|
||||
- print("Last branch")
|
||||
+elif NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+else: # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-while some_condition( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-for i in some_iter( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
- async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
||||
|
||||
|
||||
-try : # fmt: skip
|
||||
- some_call()
|
||||
-except UnformattedError as ex: # fmt: skip
|
||||
- handle_exception()
|
||||
-finally : # fmt: skip
|
||||
- finally_call()
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
-with give_me_context( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Make sure a leading comment is not removed.
|
||||
def some_func(unformatted, args): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return 0
|
||||
# Make sure this comment is not removed.
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
async def some_async_func(unformatted, args): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
class SomeClass(Unformatted, SuperClasses): # fmt: skip
|
||||
def some_method(self, unformatted, args): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return 0
|
||||
|
||||
async def some_async_method(self, unformatted, args): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
# Make sure this is not removed.
|
||||
elif NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else: # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Make sure a leading comment is not removed.
|
||||
def some_func( unformatted, args ): # fmt: skip
|
||||
print("I am some_func")
|
||||
return 0
|
||||
# Make sure this comment is not removed.
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
async def some_async_func( unformatted, args): # fmt: skip
|
||||
print("I am some_async_func")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
||||
def some_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_method")
|
||||
return 0
|
||||
|
||||
async def some_async_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_async_method")
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
if unformatted_call( args ): # fmt: skip
|
||||
print("First branch")
|
||||
# Make sure this is not removed.
|
||||
elif another_unformatted_call( args ): # fmt: skip
|
||||
print("Second branch")
|
||||
else : # fmt: skip
|
||||
print("Last branch")
|
||||
|
||||
|
||||
while some_condition( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
for i in some_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
try : # fmt: skip
|
||||
some_call()
|
||||
except UnformattedError as ex: # fmt: skip
|
||||
handle_exception()
|
||||
finally : # fmt: skip
|
||||
finally_call()
|
||||
|
||||
|
||||
with give_me_context( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
```
|
||||
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,3 +1,3 @@
|
||||
a, b = 1, 2
|
||||
-c = 6 # fmt: skip
|
||||
+c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
f"f-string without formatted values is just a string"
|
||||
f"{{NOT a formatted value}}"
|
||||
f"{{NOT 'a' \"formatted\" \"value\"}}"
|
||||
f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
f"{f'''{'nested'} inner'''} outer"
|
||||
f"\"{f'{nested} inner'}\" outer"
|
||||
f"space between opening braces: { {a for a in (1, 2, 3)}}"
|
||||
f'Hello \'{tricky + "example"}\''
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,9 +1,9 @@
|
||||
-f"f-string without formatted values is just a string"
|
||||
-f"{{NOT a formatted value}}"
|
||||
-f'{{NOT \'a\' "formatted" "value"}}'
|
||||
-f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
-f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
-f"{f'''{'nested'} inner'''} outer"
|
||||
-f"\"{f'{nested} inner'}\" outer"
|
||||
-f"space between opening braces: { {a for a in (1, 2, 3)}}"
|
||||
-f'Hello \'{tricky + "example"}\''
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
f"f-string without formatted values is just a string"
|
||||
f"{{NOT a formatted value}}"
|
||||
f'{{NOT \'a\' "formatted" "value"}}'
|
||||
f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
f"{f'''{'nested'} inner'''} outer"
|
||||
f"\"{f'{nested} inner'}\" outer"
|
||||
f"space between opening braces: { {a for a in (1, 2, 3)}}"
|
||||
f'Hello \'{tricky + "example"}\''
|
||||
```
|
||||
|
||||
|
|
@ -1,261 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
with cache_dir():
|
||||
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,
|
||||
)
|
||||
def g():
|
||||
"Docstring."
|
||||
def inner():
|
||||
pass
|
||||
print("Inner defs should breathe a little.")
|
||||
def h():
|
||||
def inner():
|
||||
pass
|
||||
print("Inner defs should breathe a little.")
|
||||
|
||||
|
||||
if os.name == "posix":
|
||||
import termios
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
elif os.name == "nt":
|
||||
try:
|
||||
import msvcrt
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
except ImportError:
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
elif False:
|
||||
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
print("i_should_be_followed_by_only_one_newline")
|
||||
else:
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
with hmm_but_this_should_get_two_preceding_newlines():
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,17 +2,9 @@
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
- with cache_dir():
|
||||
- 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,
|
||||
- )
|
||||
+ NOT_YET_IMPLEMENTED_StmtWith
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top
|
||||
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def g():
|
||||
@@ -21,45 +13,30 @@
|
||||
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":
|
||||
- import termios
|
||||
+ NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
-
|
||||
elif os.name == "nt":
|
||||
- try:
|
||||
- import msvcrt
|
||||
-
|
||||
- def i_should_be_followed_by_only_one_newline():
|
||||
- pass
|
||||
-
|
||||
- except ImportError:
|
||||
-
|
||||
- def i_should_be_followed_by_only_one_newline():
|
||||
- pass
|
||||
+ NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
elif False:
|
||||
-
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
- print("i_should_be_followed_by_only_one_newline")
|
||||
-
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
-
|
||||
def foo():
|
||||
pass
|
||||
-
|
||||
|
||||
-with hmm_but_this_should_get_two_preceding_newlines():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def g():
|
||||
"Docstring."
|
||||
|
||||
def inner():
|
||||
pass
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def h():
|
||||
def inner():
|
||||
pass
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
if os.name == "posix":
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
elif os.name == "nt":
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
elif False:
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
else:
|
||||
def foo():
|
||||
pass
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
with cache_dir():
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
def g():
|
||||
"Docstring."
|
||||
|
||||
def inner():
|
||||
pass
|
||||
|
||||
print("Inner defs should breathe a little.")
|
||||
|
||||
|
||||
def h():
|
||||
def inner():
|
||||
pass
|
||||
|
||||
print("Inner defs should breathe a little.")
|
||||
|
||||
|
||||
if os.name == "posix":
|
||||
import termios
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
elif os.name == "nt":
|
||||
try:
|
||||
import msvcrt
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
except ImportError:
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
elif False:
|
||||
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
print("i_should_be_followed_by_only_one_newline")
|
||||
|
||||
else:
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
|
||||
with hmm_but_this_should_get_two_preceding_newlines():
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,550 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from third_party import X, Y, Z
|
||||
|
||||
from library import some_connection, \
|
||||
some_decorator
|
||||
f'trigger 3.6 mode'
|
||||
def func_no_args():
|
||||
a; b; c
|
||||
if True: raise RuntimeError
|
||||
if False: ...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec("new-style exec", {}, {})
|
||||
return None
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
many_args=[1,2,3]
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
|
||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
def spaces2(result= _core.Value(None)):
|
||||
assert fut is self._read_fut, (fut, self._read_fut)
|
||||
|
||||
def example(session):
|
||||
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():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(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():
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
return (
|
||||
yield from A(
|
||||
very_long_argument_name1=very_long_value_for_the_argument,
|
||||
very_long_argument_name2=very_long_value_for_the_argument,
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
def __await__(): return (yield)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
-import asyncio
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-from third_party import X, Y, Z
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from library import some_connection, some_decorator
|
||||
-
|
||||
-f"trigger 3.6 mode"
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def func_no_args():
|
||||
@@ -14,25 +13,24 @@
|
||||
b
|
||||
c
|
||||
if True:
|
||||
- raise RuntimeError
|
||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
||||
if False:
|
||||
...
|
||||
- for i in range(10):
|
||||
- print(i)
|
||||
+ 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):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
- async with some_connection() as conn:
|
||||
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
- await asyncio.sleep(1)
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
@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 @@
|
||||
debug: bool = False,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
- return text[number:-1]
|
||||
+ return text[number : -1]
|
||||
|
||||
|
||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
+def spaces(
|
||||
+ a=1,
|
||||
+ b=(),
|
||||
+ c=[],
|
||||
+ d={},
|
||||
+ e=True,
|
||||
+ f=-1,
|
||||
+ g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
+ h="",
|
||||
+ i=r"",
|
||||
+):
|
||||
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def spaces_types(
|
||||
@@ -56,70 +64,26 @@
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
- g: int = 1 if False else 2,
|
||||
+ g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
-def spaces2(result=_core.Value(None)):
|
||||
- assert fut is self._read_fut, (fut, self._read_fut)
|
||||
+def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
|
||||
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def example(session):
|
||||
- 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()
|
||||
- )
|
||||
+ result = NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
- typedargslist.extend(
|
||||
- gen_annotated_params(
|
||||
- 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,
|
||||
- )
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ _type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def trailing_comma():
|
||||
@@ -135,14 +99,8 @@
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
- return (
|
||||
- yield from A(
|
||||
- very_long_argument_name1=very_long_value_for_the_argument,
|
||||
- very_long_argument_name2=very_long_value_for_the_argument,
|
||||
- **kwargs,
|
||||
- )
|
||||
- )
|
||||
+ return NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||
|
||||
|
||||
def __await__():
|
||||
- return (yield)
|
||||
+ return NOT_YET_IMPLEMENTED_ExprYield
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def func_no_args():
|
||||
a
|
||||
b
|
||||
c
|
||||
if True:
|
||||
NOT_YET_IMPLEMENTED_StmtRaise
|
||||
if False:
|
||||
...
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
continue
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
return None
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
def function_signature_stress_test(
|
||||
number: int,
|
||||
no_annotation=None,
|
||||
text: str = "default",
|
||||
*,
|
||||
debug: bool = False,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
return text[number : -1]
|
||||
|
||||
|
||||
def spaces(
|
||||
a=1,
|
||||
b=(),
|
||||
c=[],
|
||||
d={},
|
||||
e=True,
|
||||
f=-1,
|
||||
g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h="",
|
||||
i=r"",
|
||||
):
|
||||
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def spaces_types(
|
||||
a: int = 1,
|
||||
b: tuple = (),
|
||||
c: list = [],
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
|
||||
def example(session):
|
||||
result = NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
_type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def trailing_comma():
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
|
||||
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
return NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||
|
||||
|
||||
def __await__():
|
||||
return NOT_YET_IMPLEMENTED_ExprYield
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from third_party import X, Y, Z
|
||||
|
||||
from library import some_connection, some_decorator
|
||||
|
||||
f"trigger 3.6 mode"
|
||||
|
||||
|
||||
def func_no_args():
|
||||
a
|
||||
b
|
||||
c
|
||||
if True:
|
||||
raise RuntimeError
|
||||
if False:
|
||||
...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec("new-style exec", {}, {})
|
||||
return None
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@some_decorator(with_args=True, many_args=[1, 2, 3])
|
||||
def function_signature_stress_test(
|
||||
number: int,
|
||||
no_annotation=None,
|
||||
text: str = "default",
|
||||
*,
|
||||
debug: bool = False,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
return text[number:-1]
|
||||
|
||||
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
||||
assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
|
||||
|
||||
def spaces_types(
|
||||
a: int = 1,
|
||||
b: tuple = (),
|
||||
c: list = [],
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
g: int = 1 if False else 2,
|
||||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def spaces2(result=_core.Value(None)):
|
||||
assert fut is self._read_fut, (fut, self._read_fut)
|
||||
|
||||
|
||||
def example(session):
|
||||
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():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(
|
||||
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():
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
|
||||
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
return (
|
||||
yield from A(
|
||||
very_long_argument_name1=very_long_value_for_the_argument,
|
||||
very_long_argument_name2=very_long_value_for_the_argument,
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def __await__():
|
||||
return (yield)
|
||||
```
|
||||
|
||||
|
|
@ -1,383 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
def f(a,):
|
||||
d = {'key': 'value',}
|
||||
tup = (1,)
|
||||
|
||||
def f2(a,b,):
|
||||
d = {'key': 'value', 'key2': 'value2',}
|
||||
tup = (1,2,)
|
||||
|
||||
def f(a:int=1,):
|
||||
call(arg={'explode': 'this',})
|
||||
call2(arg=[1,2,3],)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}["a"]
|
||||
if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]:
|
||||
pass
|
||||
|
||||
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
]:
|
||||
json = {"k": {"k2": {"k3": [1,]}}}
|
||||
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||
def some_function_with_a_really_long_name() -> (
|
||||
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def some_method_with_a_really_long_name(very_long_parameter_so_yeah: str, another_long_parameter: int) -> (
|
||||
another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# Make sure inner one-element tuple won't explode
|
||||
some_module.some_function(
|
||||
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||
)
|
||||
|
||||
# Inner trailing comma causes outer to explode
|
||||
some_module.some_function(
|
||||
argument1, (one, two,), argument4, argument5, argument6
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -24,18 +24,14 @@
|
||||
def f(
|
||||
a: int = 1,
|
||||
):
|
||||
- call(
|
||||
- arg={
|
||||
- "explode": "this",
|
||||
- }
|
||||
- )
|
||||
- call2(
|
||||
- arg=[1, 2, 3],
|
||||
- )
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
- }["a"]
|
||||
+ }[
|
||||
+ "a"
|
||||
+ ]
|
||||
if (
|
||||
a
|
||||
== {
|
||||
@@ -47,23 +43,17 @@
|
||||
"f": 6,
|
||||
"g": 7,
|
||||
"h": 8,
|
||||
- }["a"]
|
||||
+ }[
|
||||
+ "a"
|
||||
+ ]
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
-def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||
- Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
|
||||
-):
|
||||
- json = {
|
||||
- "k": {
|
||||
- "k2": {
|
||||
- "k3": [
|
||||
- 1,
|
||||
- ]
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
+]:
|
||||
+ json = {"k": {"k2": {"k3": [1]}}}
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
@@ -80,35 +70,16 @@
|
||||
pass
|
||||
|
||||
|
||||
-def func() -> (
|
||||
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
- this_shouldn_t_get_a_trailing_comma_too
|
||||
- )
|
||||
-):
|
||||
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
pass
|
||||
|
||||
|
||||
-def func() -> (
|
||||
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
- this_shouldn_t_get_a_trailing_comma_too
|
||||
- )
|
||||
-):
|
||||
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
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
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
):
|
||||
d = {
|
||||
"key": "value",
|
||||
}
|
||||
tup = (1,)
|
||||
|
||||
|
||||
def f2(
|
||||
a,
|
||||
b,
|
||||
):
|
||||
d = {
|
||||
"key": "value",
|
||||
"key2": "value2",
|
||||
}
|
||||
tup = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
|
||||
|
||||
def f(
|
||||
a: int = 1,
|
||||
):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}[
|
||||
"a"
|
||||
]
|
||||
if (
|
||||
a
|
||||
== {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3,
|
||||
"d": 4,
|
||||
"e": 5,
|
||||
"f": 6,
|
||||
"g": 7,
|
||||
"h": 8,
|
||||
}[
|
||||
"a"
|
||||
]
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
]:
|
||||
json = {"k": {"k2": {"k3": [1]}}}
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||
def some_function_with_a_really_long_name() -> (
|
||||
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def some_method_with_a_really_long_name(
|
||||
very_long_parameter_so_yeah: str, another_long_parameter: int
|
||||
) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
||||
pass
|
||||
|
||||
|
||||
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
pass
|
||||
|
||||
|
||||
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
pass
|
||||
|
||||
|
||||
# Make sure inner one-element tuple won't explode
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# Inner trailing comma causes outer to explode
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
):
|
||||
d = {
|
||||
"key": "value",
|
||||
}
|
||||
tup = (1,)
|
||||
|
||||
|
||||
def f2(
|
||||
a,
|
||||
b,
|
||||
):
|
||||
d = {
|
||||
"key": "value",
|
||||
"key2": "value2",
|
||||
}
|
||||
tup = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
|
||||
|
||||
def f(
|
||||
a: int = 1,
|
||||
):
|
||||
call(
|
||||
arg={
|
||||
"explode": "this",
|
||||
}
|
||||
)
|
||||
call2(
|
||||
arg=[1, 2, 3],
|
||||
)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}["a"]
|
||||
if (
|
||||
a
|
||||
== {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3,
|
||||
"d": 4,
|
||||
"e": 5,
|
||||
"f": 6,
|
||||
"g": 7,
|
||||
"h": 8,
|
||||
}["a"]
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||
Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
|
||||
):
|
||||
json = {
|
||||
"k": {
|
||||
"k2": {
|
||||
"k3": [
|
||||
1,
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||
def some_function_with_a_really_long_name() -> (
|
||||
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def some_method_with_a_really_long_name(
|
||||
very_long_parameter_so_yeah: str, another_long_parameter: int
|
||||
) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
||||
pass
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# Make sure inner one-element tuple won't explode
|
||||
some_module.some_function(
|
||||
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||
)
|
||||
|
||||
# Inner trailing comma causes outer to explode
|
||||
some_module.some_function(
|
||||
argument1,
|
||||
(
|
||||
one,
|
||||
two,
|
||||
),
|
||||
argument4,
|
||||
argument5,
|
||||
argument6,
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
"""The asyncio package, tracking PEP 3156."""
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
from logging import (
|
||||
WARNING
|
||||
)
|
||||
from logging import (
|
||||
ERROR,
|
||||
)
|
||||
import sys
|
||||
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
from .base_events import *
|
||||
from .coroutines import *
|
||||
from .events import * # comment here
|
||||
|
||||
from .futures import *
|
||||
from .locks import * # comment here
|
||||
from .protocols import *
|
||||
|
||||
from ..runners import * # comment here
|
||||
from ..queues import *
|
||||
from ..streams import *
|
||||
|
||||
from some_library import (
|
||||
Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
|
||||
)
|
||||
from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy
|
||||
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
|
||||
from .a.b.c.subprocess import *
|
||||
from . import (tasks)
|
||||
from . import (A, B, C)
|
||||
from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \
|
||||
SomeVeryLongNameAndAllOfItsAdditionalLetters2
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
+ coroutines.__all__
|
||||
+ events.__all__
|
||||
+ futures.__all__
|
||||
+ locks.__all__
|
||||
+ protocols.__all__
|
||||
+ runners.__all__
|
||||
+ queues.__all__
|
||||
+ streams.__all__
|
||||
+ tasks.__all__
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,53 +2,31 @@
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
-from logging import WARNING
|
||||
-from logging import (
|
||||
- ERROR,
|
||||
-)
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
-from .base_events import *
|
||||
-from .coroutines import *
|
||||
-from .events import * # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
|
||||
-from .futures import *
|
||||
-from .locks import * # comment here
|
||||
-from .protocols import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from ..runners import * # comment here
|
||||
-from ..queues import *
|
||||
-from ..streams import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from some_library import (
|
||||
- Just,
|
||||
- Enough,
|
||||
- Libraries,
|
||||
- To,
|
||||
- Fit,
|
||||
- In,
|
||||
- This,
|
||||
- Nice,
|
||||
- Split,
|
||||
- Which,
|
||||
- We,
|
||||
- No,
|
||||
- Longer,
|
||||
- Use,
|
||||
-)
|
||||
-from name_of_a_company.extremely_long_project_name.component.ttypes import (
|
||||
- CuteLittleServiceHandlerFactoryyy,
|
||||
-)
|
||||
-from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from .a.b.c.subprocess import *
|
||||
-from . import tasks
|
||||
-from . import A, B, C
|
||||
-from . import (
|
||||
- SomeVeryLongNameAndAllOfItsAdditionalLetters1,
|
||||
- SomeVeryLongNameAndAllOfItsAdditionalLetters2,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
"""The asyncio package, tracking PEP 3156."""
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
+ coroutines.__all__
|
||||
+ events.__all__
|
||||
+ futures.__all__
|
||||
+ locks.__all__
|
||||
+ protocols.__all__
|
||||
+ runners.__all__
|
||||
+ queues.__all__
|
||||
+ streams.__all__
|
||||
+ tasks.__all__
|
||||
)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
"""The asyncio package, tracking PEP 3156."""
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
from logging import WARNING
|
||||
from logging import (
|
||||
ERROR,
|
||||
)
|
||||
import sys
|
||||
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
from .base_events import *
|
||||
from .coroutines import *
|
||||
from .events import * # comment here
|
||||
|
||||
from .futures import *
|
||||
from .locks import * # comment here
|
||||
from .protocols import *
|
||||
|
||||
from ..runners import * # comment here
|
||||
from ..queues import *
|
||||
from ..streams import *
|
||||
|
||||
from some_library import (
|
||||
Just,
|
||||
Enough,
|
||||
Libraries,
|
||||
To,
|
||||
Fit,
|
||||
In,
|
||||
This,
|
||||
Nice,
|
||||
Split,
|
||||
Which,
|
||||
We,
|
||||
No,
|
||||
Longer,
|
||||
Use,
|
||||
)
|
||||
from name_of_a_company.extremely_long_project_name.component.ttypes import (
|
||||
CuteLittleServiceHandlerFactoryyy,
|
||||
)
|
||||
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
|
||||
from .a.b.c.subprocess import *
|
||||
from . import tasks
|
||||
from . import A, B, C
|
||||
from . import (
|
||||
SomeVeryLongNameAndAllOfItsAdditionalLetters1,
|
||||
SomeVeryLongNameAndAllOfItsAdditionalLetters2,
|
||||
)
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
+ coroutines.__all__
|
||||
+ events.__all__
|
||||
+ futures.__all__
|
||||
+ locks.__all__
|
||||
+ protocols.__all__
|
||||
+ runners.__all__
|
||||
+ queues.__all__
|
||||
+ streams.__all__
|
||||
+ tasks.__all__
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
c: tuple[int, int,]
|
||||
d = tuple[int, int,]
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
small_list = [1,]
|
||||
list_of_types = [tuple[int,],]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,22 +1,17 @@
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
-a: tuple[int,]
|
||||
-b = tuple[int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+b = tuple[(int,)]
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
-c: tuple[
|
||||
- int,
|
||||
- int,
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
d = tuple[
|
||||
- int,
|
||||
- int,
|
||||
+ (
|
||||
+ int,
|
||||
+ int,
|
||||
+ )
|
||||
]
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
-small_list = [
|
||||
- 1,
|
||||
-]
|
||||
-list_of_types = [
|
||||
- tuple[int,],
|
||||
-]
|
||||
+small_list = [1]
|
||||
+list_of_types = [tuple[(int,)]]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
b = tuple[(int,)]
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
d = tuple[
|
||||
(
|
||||
int,
|
||||
int,
|
||||
)
|
||||
]
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
small_list = [1]
|
||||
list_of_types = [tuple[(int,)]]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
c: tuple[
|
||||
int,
|
||||
int,
|
||||
]
|
||||
d = tuple[
|
||||
int,
|
||||
int,
|
||||
]
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
small_list = [
|
||||
1,
|
||||
]
|
||||
list_of_types = [
|
||||
tuple[int,],
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,288 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
def function(**kwargs):
|
||||
t = a**2 + b**3
|
||||
return t ** 2
|
||||
|
||||
|
||||
def function_replace_spaces(**kwargs):
|
||||
t = a **2 + b** 3 + c ** 4
|
||||
|
||||
|
||||
def function_dont_replace_spaces():
|
||||
{**a, **b, **c}
|
||||
|
||||
|
||||
a = 5**~4
|
||||
b = 5 ** f()
|
||||
c = -(5**2)
|
||||
d = 5 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5
|
||||
g = a.b**c.d
|
||||
h = 5 ** funcs.f()
|
||||
i = funcs.f() ** 5
|
||||
j = super().name ** 5
|
||||
k = [(2**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2**63], [1, 2**63])]
|
||||
n = count <= 10**5
|
||||
o = settings(max_examples=10**6)
|
||||
p = {(k, k**2): v**2 for k, v in pairs}
|
||||
q = [10**i for i in range(6)]
|
||||
r = x**y
|
||||
|
||||
a = 5.0**~4.0
|
||||
b = 5.0 ** f()
|
||||
c = -(5.0**2.0)
|
||||
d = 5.0 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5.0
|
||||
g = a.b**c.d
|
||||
h = 5.0 ** funcs.f()
|
||||
i = funcs.f() ** 5.0
|
||||
j = super().name ** 5.0
|
||||
k = [(2.0**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
n = count <= 10**5.0
|
||||
o = settings(max_examples=10**6.0)
|
||||
p = {(k, k**2): v**2.0 for k, v in pairs}
|
||||
q = [10.5**i for i in range(6)]
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
if hasattr(view, "sum_of_weights"):
|
||||
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 np.divide(
|
||||
where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -12,52 +12,45 @@
|
||||
|
||||
|
||||
a = 5**~4
|
||||
-b = 5 ** f()
|
||||
+b = 5 ** NOT_IMPLEMENTED_call()
|
||||
c = -(5**2)
|
||||
d = 5 ** f["hi"]
|
||||
-e = lazy(lambda **kwargs: 5)
|
||||
-f = f() ** 5
|
||||
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+f = NOT_IMPLEMENTED_call() ** 5
|
||||
g = a.b**c.d
|
||||
-h = 5 ** funcs.f()
|
||||
-i = funcs.f() ** 5
|
||||
-j = super().name ** 5
|
||||
-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 []]
|
||||
+l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
m = [([2**63], [1, 2**63])]
|
||||
n = count <= 10**5
|
||||
-o = settings(max_examples=10**6)
|
||||
-p = {(k, k**2): v**2 for k, v in pairs}
|
||||
-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}
|
||||
+q = [i for i in []]
|
||||
r = x**y
|
||||
|
||||
a = 5.0**~4.0
|
||||
-b = 5.0 ** f()
|
||||
+b = 5.0 ** NOT_IMPLEMENTED_call()
|
||||
c = -(5.0**2.0)
|
||||
d = 5.0 ** f["hi"]
|
||||
-e = lazy(lambda **kwargs: 5)
|
||||
-f = f() ** 5.0
|
||||
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+f = NOT_IMPLEMENTED_call() ** 5.0
|
||||
g = a.b**c.d
|
||||
-h = 5.0 ** funcs.f()
|
||||
-i = funcs.f() ** 5.0
|
||||
-j = super().name ** 5.0
|
||||
-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 []]
|
||||
+l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
n = count <= 10**5.0
|
||||
-o = settings(max_examples=10**6.0)
|
||||
-p = {(k, k**2): v**2.0 for k, v in pairs}
|
||||
-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}
|
||||
+q = [i for i in []]
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
-if hasattr(view, "sum_of_weights"):
|
||||
- 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]
|
||||
- )
|
||||
+if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ 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
|
||||
-)
|
||||
+return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def function(**kwargs):
|
||||
t = a**2 + b**3
|
||||
return t**2
|
||||
|
||||
|
||||
def function_replace_spaces(**kwargs):
|
||||
t = a**2 + b**3 + c**4
|
||||
|
||||
|
||||
def function_dont_replace_spaces():
|
||||
{**a, **b, **c}
|
||||
|
||||
|
||||
a = 5**~4
|
||||
b = 5 ** NOT_IMPLEMENTED_call()
|
||||
c = -(5**2)
|
||||
d = 5 ** f["hi"]
|
||||
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
f = NOT_IMPLEMENTED_call() ** 5
|
||||
g = a.b**c.d
|
||||
h = 5 ** NOT_IMPLEMENTED_call()
|
||||
i = NOT_IMPLEMENTED_call() ** 5
|
||||
j = NOT_IMPLEMENTED_call().name ** 5
|
||||
k = [i for i in []]
|
||||
l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
m = [([2**63], [1, 2**63])]
|
||||
n = count <= 10**5
|
||||
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
q = [i for i in []]
|
||||
r = x**y
|
||||
|
||||
a = 5.0**~4.0
|
||||
b = 5.0 ** NOT_IMPLEMENTED_call()
|
||||
c = -(5.0**2.0)
|
||||
d = 5.0 ** f["hi"]
|
||||
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
f = NOT_IMPLEMENTED_call() ** 5.0
|
||||
g = a.b**c.d
|
||||
h = 5.0 ** NOT_IMPLEMENTED_call()
|
||||
i = NOT_IMPLEMENTED_call() ** 5.0
|
||||
j = NOT_IMPLEMENTED_call().name ** 5.0
|
||||
k = [i for i in []]
|
||||
l = mod.weights_[0] == NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
n = count <= 10**5.0
|
||||
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
q = [i for i in []]
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
def function(**kwargs):
|
||||
t = a**2 + b**3
|
||||
return t**2
|
||||
|
||||
|
||||
def function_replace_spaces(**kwargs):
|
||||
t = a**2 + b**3 + c**4
|
||||
|
||||
|
||||
def function_dont_replace_spaces():
|
||||
{**a, **b, **c}
|
||||
|
||||
|
||||
a = 5**~4
|
||||
b = 5 ** f()
|
||||
c = -(5**2)
|
||||
d = 5 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5
|
||||
g = a.b**c.d
|
||||
h = 5 ** funcs.f()
|
||||
i = funcs.f() ** 5
|
||||
j = super().name ** 5
|
||||
k = [(2**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2**63], [1, 2**63])]
|
||||
n = count <= 10**5
|
||||
o = settings(max_examples=10**6)
|
||||
p = {(k, k**2): v**2 for k, v in pairs}
|
||||
q = [10**i for i in range(6)]
|
||||
r = x**y
|
||||
|
||||
a = 5.0**~4.0
|
||||
b = 5.0 ** f()
|
||||
c = -(5.0**2.0)
|
||||
d = 5.0 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5.0
|
||||
g = a.b**c.d
|
||||
h = 5.0 ** funcs.f()
|
||||
i = funcs.f() ** 5.0
|
||||
j = super().name ** 5.0
|
||||
k = [(2.0**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
n = count <= 10**5.0
|
||||
o = settings(max_examples=10**6.0)
|
||||
p = {(k, k**2): v**2.0 for k, v in pairs}
|
||||
q = [10.5**i for i in range(6)]
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
if hasattr(view, "sum_of_weights"):
|
||||
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 np.divide(
|
||||
where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
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
|
||||
```
|
||||
|
||||
|
|
@ -1,401 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
import asyncio
|
||||
|
||||
# Control example
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
await (asyncio.sleep(1))
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1)
|
||||
)
|
||||
|
||||
async def main():
|
||||
await (asyncio.sleep(1)
|
||||
)
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
await ( # Hello
|
||||
asyncio.sleep(1)
|
||||
)
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1) # Hello
|
||||
)
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1)
|
||||
) # Hello
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
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
|
||||
async def main():
|
||||
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
|
||||
async def main():
|
||||
await (
|
||||
(((((((((((((
|
||||
((( (((
|
||||
((( (((
|
||||
((( (((
|
||||
((( (((
|
||||
((black(1)))
|
||||
))) )))
|
||||
))) )))
|
||||
))) )))
|
||||
))) )))
|
||||
)))))))))))))
|
||||
)
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
async def main():
|
||||
await (set_of_tasks | other_set)
|
||||
|
||||
async def main():
|
||||
await (await asyncio.sleep(1))
|
||||
|
||||
# It's awaits all the way down...
|
||||
async def main():
|
||||
await (await x)
|
||||
|
||||
async def main():
|
||||
await (yield x)
|
||||
|
||||
async def main():
|
||||
await (await (asyncio.sleep(1)))
|
||||
|
||||
async def main():
|
||||
await (await (await (await (await (asyncio.sleep(1))))))
|
||||
|
||||
async def main():
|
||||
await (yield)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,66 +1,57 @@
|
||||
-import asyncio
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# Control example
|
||||
async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ (
|
||||
+ await # Hello
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+ )
|
||||
|
||||
|
||||
async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ (
|
||||
+ await (
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello
|
||||
+ )
|
||||
+ )
|
||||
|
||||
|
||||
async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello
|
||||
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
- await asyncio.gather(
|
||||
- asyncio.sleep(1),
|
||||
- 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)
|
||||
|
||||
|
||||
# Same as above but with magic trailing comma in function
|
||||
async def main():
|
||||
- await asyncio.gather(
|
||||
- asyncio.sleep(1),
|
||||
- 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)
|
||||
|
||||
|
||||
# Cr@zY Br@ck3Tz
|
||||
async def main():
|
||||
- await black(1)
|
||||
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
@@ -69,7 +60,7 @@
|
||||
|
||||
|
||||
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():
|
||||
- await (yield x)
|
||||
+ await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||
|
||||
|
||||
async def main():
|
||||
- await (await asyncio.sleep(1))
|
||||
+ await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))
|
||||
|
||||
|
||||
async def main():
|
||||
- await (await (await (await (await asyncio.sleep(1)))))
|
||||
+ await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))))))
|
||||
|
||||
|
||||
async def main():
|
||||
- await (yield)
|
||||
+ await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# Control example
|
||||
async def main():
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
async def main():
|
||||
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
async def main():
|
||||
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
(
|
||||
await # Hello
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
(
|
||||
await (
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello
|
||||
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Same as above but with magic trailing comma in function
|
||||
async def main():
|
||||
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Cr@zY Br@ck3Tz
|
||||
async def main():
|
||||
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
async def main():
|
||||
await (set_of_tasks | other_set)
|
||||
|
||||
|
||||
async def main():
|
||||
await (await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
|
||||
|
||||
|
||||
# It's awaits all the way down...
|
||||
async def main():
|
||||
await (await x)
|
||||
|
||||
|
||||
async def main():
|
||||
await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||
|
||||
|
||||
async def main():
|
||||
await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))
|
||||
|
||||
|
||||
async def main():
|
||||
await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))))))
|
||||
|
||||
|
||||
async def main():
|
||||
await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
import asyncio
|
||||
|
||||
|
||||
# Control example
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
await asyncio.sleep(1) # Hello
|
||||
|
||||
|
||||
async def main():
|
||||
await asyncio.sleep(1) # Hello
|
||||
|
||||
|
||||
async def main():
|
||||
await asyncio.sleep(1) # Hello
|
||||
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
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
|
||||
async def main():
|
||||
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
|
||||
async def main():
|
||||
await black(1)
|
||||
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
async def main():
|
||||
await (set_of_tasks | other_set)
|
||||
|
||||
|
||||
async def main():
|
||||
await (await asyncio.sleep(1))
|
||||
|
||||
|
||||
# It's awaits all the way down...
|
||||
async def main():
|
||||
await (await x)
|
||||
|
||||
|
||||
async def main():
|
||||
await (yield x)
|
||||
|
||||
|
||||
async def main():
|
||||
await (await asyncio.sleep(1))
|
||||
|
||||
|
||||
async def main():
|
||||
await (await (await (await (await asyncio.sleep(1)))))
|
||||
|
||||
|
||||
async def main():
|
||||
await (yield)
|
||||
```
|
||||
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError) as err:
|
||||
raise err
|
||||
|
||||
# This is tuple of exceptions.
|
||||
# Although this could be replaced with just the exception,
|
||||
# we do not remove brackets to preserve AST.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError,) as err:
|
||||
raise err
|
||||
|
||||
# This is a tuple of exceptions. Do not remove brackets.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError, ValueError) as err:
|
||||
raise err
|
||||
|
||||
# Test long variants.
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err:
|
||||
raise err
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,42 +1,17 @@
|
||||
# These brackets are redundant, therefore remove.
|
||||
-try:
|
||||
- a.something
|
||||
-except AttributeError as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# This is tuple of exceptions.
|
||||
# Although this could be replaced with just the exception,
|
||||
# we do not remove brackets to preserve AST.
|
||||
-try:
|
||||
- a.something
|
||||
-except (AttributeError,) as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# This is a tuple of exceptions. Do not remove brackets.
|
||||
-try:
|
||||
- a.something
|
||||
-except (AttributeError, ValueError) as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# Test long variants.
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error
|
||||
-) as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
-) as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
-) as err:
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# These brackets are redundant, therefore remove.
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# This is tuple of exceptions.
|
||||
# Although this could be replaced with just the exception,
|
||||
# we do not remove brackets to preserve AST.
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# This is a tuple of exceptions. Do not remove brackets.
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
# Test long variants.
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
except AttributeError as err:
|
||||
raise err
|
||||
|
||||
# This is tuple of exceptions.
|
||||
# Although this could be replaced with just the exception,
|
||||
# we do not remove brackets to preserve AST.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError,) as err:
|
||||
raise err
|
||||
|
||||
# This is a tuple of exceptions. Do not remove brackets.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError, ValueError) as err:
|
||||
raise err
|
||||
|
||||
# Test long variants.
|
||||
try:
|
||||
a.something
|
||||
except (
|
||||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error
|
||||
) as err:
|
||||
raise err
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (
|
||||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
) as err:
|
||||
raise err
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (
|
||||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
) as err:
|
||||
raise err
|
||||
```
|
||||
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Only remove tuple brackets after `for`
|
||||
for (k, v) in d.items():
|
||||
print(k, v)
|
||||
|
||||
# Don't touch tuple brackets after `in`
|
||||
for module in (core, _unicodefun):
|
||||
if hasattr(module, "_verify_python3_env"):
|
||||
module._verify_python3_env = lambda: None
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
for (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) in d.items():
|
||||
print(k, v)
|
||||
|
||||
for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
|
||||
print(k, v)
|
||||
|
||||
# Test deeply nested brackets
|
||||
for (((((k, v))))) in d.items():
|
||||
print(k, v)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,27 +1,22 @@
|
||||
# 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`
|
||||
for module in (core, _unicodefun):
|
||||
- if hasattr(module, "_verify_python3_env"):
|
||||
- module._verify_python3_env = lambda: None
|
||||
+ if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ module._verify_python3_env = lambda x: True
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
for (
|
||||
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,
|
||||
-) in d.items():
|
||||
- print(k, v)
|
||||
+) in NOT_IMPLEMENTED_call():
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
-for (
|
||||
- k,
|
||||
- v,
|
||||
-) in (
|
||||
- dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items()
|
||||
-):
|
||||
- print(k, v)
|
||||
+for k, v in NOT_IMPLEMENTED_call():
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# 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
|
||||
|
||||
```py
|
||||
# Only remove tuple brackets after `for`
|
||||
for k, v in NOT_IMPLEMENTED_call():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# Don't touch tuple brackets after `in`
|
||||
for module in (core, _unicodefun):
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
module._verify_python3_env = lambda x: True
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
for (
|
||||
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,
|
||||
) in NOT_IMPLEMENTED_call():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
for k, v in NOT_IMPLEMENTED_call():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# Test deeply nested brackets
|
||||
for k, v in NOT_IMPLEMENTED_call():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Only remove tuple brackets after `for`
|
||||
for k, v in d.items():
|
||||
print(k, v)
|
||||
|
||||
# Don't touch tuple brackets after `in`
|
||||
for module in (core, _unicodefun):
|
||||
if hasattr(module, "_verify_python3_env"):
|
||||
module._verify_python3_env = lambda: None
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
for (
|
||||
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,
|
||||
) in d.items():
|
||||
print(k, v)
|
||||
|
||||
for (
|
||||
k,
|
||||
v,
|
||||
) in (
|
||||
dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items()
|
||||
):
|
||||
print(k, v)
|
||||
|
||||
# Test deeply nested brackets
|
||||
for k, v in d.items():
|
||||
print(k, v)
|
||||
```
|
||||
|
||||
|
|
@ -1,394 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
import random
|
||||
|
||||
|
||||
def foo1():
|
||||
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
def foo2():
|
||||
|
||||
|
||||
|
||||
print("All the newlines above me should be deleted!")
|
||||
|
||||
|
||||
def foo3():
|
||||
|
||||
print("No newline above me!")
|
||||
|
||||
print("There is a newline above me, and that's OK!")
|
||||
|
||||
|
||||
def foo4():
|
||||
|
||||
# There is a comment here
|
||||
|
||||
print("The newline above me should not be deleted!")
|
||||
|
||||
|
||||
class Foo:
|
||||
def bar(self):
|
||||
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
|
||||
print(f"{i}) The line above me should be removed!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
|
||||
|
||||
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
|
||||
for j in range(7):
|
||||
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
|
||||
print("The new line above me is about to be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
|
||||
|
||||
|
||||
|
||||
print("The new lines above me is about to be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
if random.uniform(0, 1) > 0.5:
|
||||
print("Two lines above me are about to be removed!")
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
|
||||
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
while False:
|
||||
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
|
||||
file.write("The new line above me is about to be removed!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
|
||||
|
||||
|
||||
file.write("The new lines above me is about to be removed!")
|
||||
|
||||
|
||||
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())
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,78 +1,74 @@
|
||||
-import random
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
def foo1():
|
||||
- print("The newline above me should be deleted!")
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo2():
|
||||
- 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!")
|
||||
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-for i in range(5):
|
||||
- print(f"{i}) The lines above me should be removed!")
|
||||
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-for i in range(5):
|
||||
- for j in range(7):
|
||||
- print(f"{i}) The lines above me should be removed!")
|
||||
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ for j in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
-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!")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
-with open("/path/to/file.txt", mode="w") as file:
|
||||
- file.write("The new lines above me is about to be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
-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())
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
def foo1():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo2():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo3():
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def foo4():
|
||||
# There is a comment here
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
class Foo:
|
||||
def bar(self):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
for j in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) == 0:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
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:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
while True:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
while True:
|
||||
while False:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
import random
|
||||
|
||||
|
||||
def foo1():
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
def foo2():
|
||||
print("All the newlines above me should be deleted!")
|
||||
|
||||
|
||||
def foo3():
|
||||
print("No newline above me!")
|
||||
|
||||
print("There is a newline above me, and that's OK!")
|
||||
|
||||
|
||||
def foo4():
|
||||
# There is a comment here
|
||||
|
||||
print("The newline above me should not be deleted!")
|
||||
|
||||
|
||||
class Foo:
|
||||
def bar(self):
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
print(f"{i}) The line above me should be removed!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
|
||||
|
||||
for i in range(5):
|
||||
for j in range(7):
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
print("The new line above me is about to be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
print("The new lines above me is about to be removed!")
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
if random.uniform(0, 1) > 0.5:
|
||||
print("Two lines above me are about to be removed!")
|
||||
|
||||
|
||||
while True:
|
||||
print("The newline above me should be deleted!")
|
||||
|
||||
|
||||
while True:
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
while True:
|
||||
while False:
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
file.write("The new line above me is about to be removed!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
file.write("The new lines above me is about to be removed!")
|
||||
|
||||
|
||||
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())
|
||||
```
|
||||
|
||||
|
|
@ -1,296 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
x = (1)
|
||||
x = (1.2)
|
||||
|
||||
data = (
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
|
||||
async def show_status():
|
||||
while True:
|
||||
try:
|
||||
if report_host:
|
||||
data = (
|
||||
f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
def example():
|
||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
|
||||
|
||||
def example1():
|
||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
|
||||
|
||||
def example1point5():
|
||||
return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))))))
|
||||
|
||||
|
||||
def example2():
|
||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
|
||||
|
||||
def example3():
|
||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
|
||||
|
||||
def example4():
|
||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
|
||||
|
||||
def example5():
|
||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
|
||||
|
||||
def example6():
|
||||
return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]})))))))))
|
||||
|
||||
|
||||
def example7():
|
||||
return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]})))))))))
|
||||
|
||||
|
||||
def example8():
|
||||
return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,20 +1,12 @@
|
||||
x = 1
|
||||
x = 1.2
|
||||
|
||||
-data = (
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
-).encode()
|
||||
+data = NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
async def show_status():
|
||||
while True:
|
||||
- try:
|
||||
- if report_host:
|
||||
- data = (
|
||||
- f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
- ).encode()
|
||||
- except Exception as e:
|
||||
- pass
|
||||
+ NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
def example():
|
||||
@@ -30,15 +22,11 @@
|
||||
|
||||
|
||||
def example2():
|
||||
- return (
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
- )
|
||||
+ return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
|
||||
def example3():
|
||||
- return (
|
||||
- 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
- )
|
||||
+ return 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example4():
|
||||
@@ -50,35 +38,11 @@
|
||||
|
||||
|
||||
def example6():
|
||||
- return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
|
||||
+ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
|
||||
|
||||
def example7():
|
||||
- return {
|
||||
- a: a
|
||||
- for a in [
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
- 4,
|
||||
- 5,
|
||||
- 6,
|
||||
- 7,
|
||||
- 8,
|
||||
- 9,
|
||||
- 10,
|
||||
- 11,
|
||||
- 12,
|
||||
- 13,
|
||||
- 14,
|
||||
- 15,
|
||||
- 16,
|
||||
- 17,
|
||||
- 18,
|
||||
- 19,
|
||||
- 20000000000000000000,
|
||||
- ]
|
||||
- }
|
||||
+ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
|
||||
|
||||
def example8():
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
x = 1
|
||||
x = 1.2
|
||||
|
||||
data = NOT_IMPLEMENTED_call()
|
||||
|
||||
|
||||
async def show_status():
|
||||
while True:
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
def example():
|
||||
return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
|
||||
def example1():
|
||||
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example1point5():
|
||||
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example2():
|
||||
return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
|
||||
def example3():
|
||||
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example4():
|
||||
return True
|
||||
|
||||
|
||||
def example5():
|
||||
return ()
|
||||
|
||||
|
||||
def example6():
|
||||
return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
|
||||
|
||||
def example7():
|
||||
return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||
|
||||
|
||||
def example8():
|
||||
return None
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
x = 1
|
||||
x = 1.2
|
||||
|
||||
data = (
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
|
||||
|
||||
async def show_status():
|
||||
while True:
|
||||
try:
|
||||
if report_host:
|
||||
data = (
|
||||
f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
def example():
|
||||
return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
|
||||
def example1():
|
||||
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example1point5():
|
||||
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
|
||||
|
||||
def example2():
|
||||
return (
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
|
||||
|
||||
def example3():
|
||||
return (
|
||||
1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
)
|
||||
|
||||
|
||||
def example4():
|
||||
return True
|
||||
|
||||
|
||||
def example5():
|
||||
return ()
|
||||
|
||||
|
||||
def example6():
|
||||
return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
|
||||
|
||||
|
||||
def example7():
|
||||
return {
|
||||
a: a
|
||||
for a in [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20000000000000000000,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def example8():
|
||||
return None
|
||||
```
|
||||
|
||||
|
|
@ -1,413 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2*a
|
||||
|
||||
# Remove the brackets
|
||||
def double(a: int) -> (int):
|
||||
return 2*a
|
||||
|
||||
# Some newline variations
|
||||
def double(a: int) -> (
|
||||
int):
|
||||
return 2*a
|
||||
|
||||
def double(a: int) -> (int
|
||||
):
|
||||
return 2*a
|
||||
|
||||
def double(a: int) -> (
|
||||
int
|
||||
):
|
||||
return 2*a
|
||||
|
||||
# Don't lose the comments
|
||||
def double(a: int) -> ( # Hello
|
||||
int
|
||||
):
|
||||
return 2*a
|
||||
|
||||
def double(a: int) -> (
|
||||
int # Hello
|
||||
):
|
||||
return 2*a
|
||||
|
||||
# Really long annotations
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
|
||||
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
|
||||
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
|
||||
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
|
||||
# Split args but no need to split return
|
||||
def foo(a: int, b: int, c: int,) -> int:
|
||||
return 2
|
||||
|
||||
# Deeply nested brackets
|
||||
# with *interesting* spacing
|
||||
def double(a: int) -> (((((int))))):
|
||||
return 2*a
|
||||
|
||||
def double(a: int) -> (
|
||||
( (
|
||||
((int)
|
||||
)
|
||||
)
|
||||
)
|
||||
):
|
||||
return 2*a
|
||||
|
||||
def foo() -> (
|
||||
( (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
)
|
||||
)):
|
||||
return 2
|
||||
|
||||
# Return type with commas
|
||||
def foo() -> (
|
||||
tuple[int, int, int]
|
||||
):
|
||||
return 2
|
||||
|
||||
def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]:
|
||||
return 2
|
||||
|
||||
# Magic trailing comma example
|
||||
def foo() -> tuple[int, int, int,]:
|
||||
return 2
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -26,7 +26,9 @@
|
||||
return 2 * a
|
||||
|
||||
|
||||
-def double(a: int) -> int: # Hello
|
||||
+def double(a: int) -> (
|
||||
+ int # Hello
|
||||
+):
|
||||
return 2 * a
|
||||
|
||||
|
||||
@@ -54,7 +56,9 @@
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
-) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
+) -> (
|
||||
+ intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
+):
|
||||
return 2
|
||||
|
||||
|
||||
@@ -99,22 +103,22 @@
|
||||
return 2
|
||||
|
||||
|
||||
-def foo() -> (
|
||||
- tuple[
|
||||
+def foo() -> tuple[
|
||||
+ (
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
- ]
|
||||
-):
|
||||
+ )
|
||||
+]:
|
||||
return 2
|
||||
|
||||
|
||||
# Magic trailing comma example
|
||||
-def foo() -> (
|
||||
- tuple[
|
||||
+def foo() -> tuple[
|
||||
+ (
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
- ]
|
||||
-):
|
||||
+ )
|
||||
+]:
|
||||
return 2
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Remove the brackets
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Some newline variations
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Don't lose the comments
|
||||
def double(a: int) -> int: # Hello
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> (
|
||||
int # Hello
|
||||
):
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Really long annotations
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
# Split args but no need to split return
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> int:
|
||||
return 2
|
||||
|
||||
|
||||
# Deeply nested brackets
|
||||
# with *interesting* spacing
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
# Return type with commas
|
||||
def foo() -> tuple[int, int, int]:
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> tuple[
|
||||
(
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
)
|
||||
]:
|
||||
return 2
|
||||
|
||||
|
||||
# Magic trailing comma example
|
||||
def foo() -> tuple[
|
||||
(
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
)
|
||||
]:
|
||||
return 2
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Remove the brackets
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Some newline variations
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Don't lose the comments
|
||||
def double(a: int) -> int: # Hello
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int: # Hello
|
||||
return 2 * a
|
||||
|
||||
|
||||
# Really long annotations
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
|
||||
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
# Split args but no need to split return
|
||||
def foo(
|
||||
a: int,
|
||||
b: int,
|
||||
c: int,
|
||||
) -> int:
|
||||
return 2
|
||||
|
||||
|
||||
# Deeply nested brackets
|
||||
# with *interesting* spacing
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def double(a: int) -> int:
|
||||
return 2 * a
|
||||
|
||||
|
||||
def foo() -> (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
# Return type with commas
|
||||
def foo() -> tuple[int, int, int]:
|
||||
return 2
|
||||
|
||||
|
||||
def foo() -> (
|
||||
tuple[
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
]
|
||||
):
|
||||
return 2
|
||||
|
||||
|
||||
# Magic trailing comma example
|
||||
def foo() -> (
|
||||
tuple[
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
]
|
||||
):
|
||||
return 2
|
||||
```
|
||||
|
||||
|
|
@ -1,181 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
c: tuple[int, int,]
|
||||
d = tuple[int, int,]
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
small_list = [1,]
|
||||
list_of_types = [tuple[int,],]
|
||||
small_set = {1,}
|
||||
set_of_types = {tuple[int,],}
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
zero(
|
||||
one,
|
||||
).two(
|
||||
three,
|
||||
).four(
|
||||
five,
|
||||
)
|
||||
|
||||
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||
|
||||
(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
) = func1(
|
||||
arg1
|
||||
) and func2(arg2)
|
||||
|
||||
func(
|
||||
argument1,
|
||||
(
|
||||
one,
|
||||
two,
|
||||
),
|
||||
argument4,
|
||||
argument5,
|
||||
argument6,
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,25 +1,35 @@
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
-a: tuple[int,]
|
||||
-b = tuple[int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+b = tuple[(int,)]
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
-c: tuple[int, int]
|
||||
-d = tuple[int, int]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+d = tuple[
|
||||
+ (
|
||||
+ int,
|
||||
+ int,
|
||||
+ )
|
||||
+]
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
small_list = [1]
|
||||
-list_of_types = [tuple[int,]]
|
||||
+list_of_types = [tuple[(int,)]]
|
||||
small_set = {1}
|
||||
-set_of_types = {tuple[int,]}
|
||||
+set_of_types = {tuple[(int,)]}
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
-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)
|
||||
|
||||
-(a, b, c, d) = func1(arg1) and func2(arg2)
|
||||
+(
|
||||
+ a,
|
||||
+ b,
|
||||
+ c,
|
||||
+ d,
|
||||
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
-func(argument1, (one, two), argument4, argument5, argument6)
|
||||
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
b = tuple[(int,)]
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
d = tuple[
|
||||
(
|
||||
int,
|
||||
int,
|
||||
)
|
||||
]
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
small_list = [1]
|
||||
list_of_types = [tuple[(int,)]]
|
||||
small_set = {1}
|
||||
set_of_types = {tuple[(int,)]}
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
c: tuple[int, int]
|
||||
d = tuple[int, int]
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
small_list = [1]
|
||||
list_of_types = [tuple[int,]]
|
||||
small_set = {1}
|
||||
set_of_types = {tuple[int,]}
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
zero(one).two(three).four(five)
|
||||
|
||||
func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5)
|
||||
|
||||
(a, b, c, d) = func1(arg1) and func2(arg2)
|
||||
|
||||
func(argument1, (one, two), argument4, argument5, argument6)
|
||||
```
|
||||
|
||||
|
|
@ -1,281 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
slice[a.b : c.d]
|
||||
slice[d :: d + 1]
|
||||
slice[d + 1 :: d]
|
||||
slice[d::d]
|
||||
slice[0]
|
||||
slice[-1]
|
||||
slice[:-1]
|
||||
slice[::-1]
|
||||
slice[:c, c - 1]
|
||||
slice[c, c + 1, d::]
|
||||
slice[ham[c::d] :: 1]
|
||||
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
slice[:-1:]
|
||||
slice[lambda: None : lambda: None]
|
||||
slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
|
||||
slice[1 or 2 : True and False]
|
||||
slice[not so_simple : 1 < val <= 10]
|
||||
slice[(1 for i in range(42)) : x]
|
||||
slice[:: [i for i in range(42)]]
|
||||
|
||||
|
||||
async def f():
|
||||
slice[await x : [i async for i in arange(42)] : 42]
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
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+offset : upper+offset]
|
||||
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
|
||||
ham[lower + offset : upper + offset]
|
||||
|
||||
slice[::, ::]
|
||||
slice[
|
||||
# A
|
||||
:
|
||||
# B
|
||||
:
|
||||
# C
|
||||
]
|
||||
slice[
|
||||
# A
|
||||
1:
|
||||
# B
|
||||
2:
|
||||
# C
|
||||
3
|
||||
]
|
||||
|
||||
slice[
|
||||
# A
|
||||
1
|
||||
+ 2 :
|
||||
# B
|
||||
3 :
|
||||
# C
|
||||
4
|
||||
]
|
||||
x[
|
||||
1: # A
|
||||
2: # B
|
||||
3 # C
|
||||
]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,30 +4,35 @@
|
||||
slice[d::d]
|
||||
slice[0]
|
||||
slice[-1]
|
||||
-slice[:-1]
|
||||
-slice[::-1]
|
||||
+slice[ : -1]
|
||||
+slice[ :: -1]
|
||||
slice[:c, c - 1]
|
||||
slice[c, c + 1, d::]
|
||||
slice[ham[c::d] :: 1]
|
||||
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
-slice[:-1:]
|
||||
-slice[lambda: None : lambda: None]
|
||||
-slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
|
||||
+slice[ : -1 :]
|
||||
+slice[lambda x: True : lambda x: True]
|
||||
+slice[lambda x: True :, None::]
|
||||
slice[1 or 2 : True and False]
|
||||
slice[not so_simple : 1 < val <= 10]
|
||||
-slice[(1 for i in range(42)) : x]
|
||||
-slice[:: [i for i in range(42)]]
|
||||
+slice[(i for i in []) : x]
|
||||
+slice[ :: [i for i in []]]
|
||||
|
||||
|
||||
async def f():
|
||||
- slice[await x : [i async for i in arange(42)] : 42]
|
||||
+ slice[await x : [i for i in []] : 42]
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
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+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]
|
||||
|
||||
slice[::, ::]
|
||||
@@ -50,10 +55,14 @@
|
||||
slice[
|
||||
# A
|
||||
1
|
||||
- + 2 :
|
||||
+ + 2 :
|
||||
# B
|
||||
- 3 :
|
||||
+ 3 :
|
||||
# C
|
||||
4
|
||||
]
|
||||
-x[1:2:3] # A # B # C
|
||||
+x[
|
||||
+ 1: # A
|
||||
+ 2: # B
|
||||
+ 3 # C
|
||||
+]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
slice[a.b : c.d]
|
||||
slice[d :: d + 1]
|
||||
slice[d + 1 :: d]
|
||||
slice[d::d]
|
||||
slice[0]
|
||||
slice[-1]
|
||||
slice[ : -1]
|
||||
slice[ :: -1]
|
||||
slice[:c, c - 1]
|
||||
slice[c, c + 1, d::]
|
||||
slice[ham[c::d] :: 1]
|
||||
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
slice[ : -1 :]
|
||||
slice[lambda x: True : lambda x: True]
|
||||
slice[lambda x: True :, None::]
|
||||
slice[1 or 2 : True and False]
|
||||
slice[not so_simple : 1 < val <= 10]
|
||||
slice[(i for i in []) : x]
|
||||
slice[ :: [i for i in []]]
|
||||
|
||||
|
||||
async def f():
|
||||
slice[await x : [i for i in []] : 42]
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
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+offset : upper+offset]
|
||||
(
|
||||
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]
|
||||
|
||||
slice[::, ::]
|
||||
slice[
|
||||
# A
|
||||
:
|
||||
# B
|
||||
:
|
||||
# C
|
||||
]
|
||||
slice[
|
||||
# A
|
||||
1:
|
||||
# B
|
||||
2:
|
||||
# C
|
||||
3
|
||||
]
|
||||
|
||||
slice[
|
||||
# A
|
||||
1
|
||||
+ 2 :
|
||||
# B
|
||||
3 :
|
||||
# C
|
||||
4
|
||||
]
|
||||
x[
|
||||
1: # A
|
||||
2: # B
|
||||
3 # C
|
||||
]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
slice[a.b : c.d]
|
||||
slice[d :: d + 1]
|
||||
slice[d + 1 :: d]
|
||||
slice[d::d]
|
||||
slice[0]
|
||||
slice[-1]
|
||||
slice[:-1]
|
||||
slice[::-1]
|
||||
slice[:c, c - 1]
|
||||
slice[c, c + 1, d::]
|
||||
slice[ham[c::d] :: 1]
|
||||
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
slice[:-1:]
|
||||
slice[lambda: None : lambda: None]
|
||||
slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
|
||||
slice[1 or 2 : True and False]
|
||||
slice[not so_simple : 1 < val <= 10]
|
||||
slice[(1 for i in range(42)) : x]
|
||||
slice[:: [i for i in range(42)]]
|
||||
|
||||
|
||||
async def f():
|
||||
slice[await x : [i async for i in arange(42)] : 42]
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
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+offset : upper+offset]
|
||||
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
|
||||
ham[lower + offset : upper + offset]
|
||||
|
||||
slice[::, ::]
|
||||
slice[
|
||||
# A
|
||||
:
|
||||
# B
|
||||
:
|
||||
# C
|
||||
]
|
||||
slice[
|
||||
# A
|
||||
1:
|
||||
# B
|
||||
2:
|
||||
# C
|
||||
3
|
||||
]
|
||||
|
||||
slice[
|
||||
# A
|
||||
1
|
||||
+ 2 :
|
||||
# B
|
||||
3 :
|
||||
# C
|
||||
4
|
||||
]
|
||||
x[1:2:3] # A # B # C
|
||||
```
|
||||
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
(f"hello {name}", F"hello {name}")
|
||||
(b"", B"")
|
||||
(u"", U"")
|
||||
(r"", R"")
|
||||
|
||||
(rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"")
|
||||
(rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"")
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||
|
||||
|
||||
def docstring_multiline():
|
||||
R"""
|
||||
clear out all of the issues opened in that time :p
|
||||
"""
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,13 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
-(f"hello {name}", f"hello {name}")
|
||||
-(b"", b"")
|
||||
+(NOT_YET_IMPLEMENTED_ExprJoinedStr, NOT_YET_IMPLEMENTED_ExprJoinedStr)
|
||||
+(b"NOT_YET_IMPLEMENTED_BYTE_STRING", b"NOT_YET_IMPLEMENTED_BYTE_STRING")
|
||||
("", "")
|
||||
(r"", R"")
|
||||
|
||||
-(rf"", rf"", Rf"", Rf"", rf"", rf"", Rf"", Rf"")
|
||||
-(rb"", rb"", Rb"", Rb"", rb"", rb"", Rb"", Rb"")
|
||||
+(
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+ NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
+)
|
||||
+(
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+ b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
+)
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
(NOT_YET_IMPLEMENTED_ExprJoinedStr, NOT_YET_IMPLEMENTED_ExprJoinedStr)
|
||||
(b"NOT_YET_IMPLEMENTED_BYTE_STRING", b"NOT_YET_IMPLEMENTED_BYTE_STRING")
|
||||
("", "")
|
||||
(r"", R"")
|
||||
|
||||
(
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr,
|
||||
)
|
||||
(
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
b"NOT_YET_IMPLEMENTED_BYTE_STRING",
|
||||
)
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||
|
||||
|
||||
def docstring_multiline():
|
||||
R"""
|
||||
clear out all of the issues opened in that time :p
|
||||
"""
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
(f"hello {name}", f"hello {name}")
|
||||
(b"", b"")
|
||||
("", "")
|
||||
(r"", R"")
|
||||
|
||||
(rf"", rf"", Rf"", Rf"", rf"", rf"", Rf"", Rf"")
|
||||
(rb"", rb"", Rb"", Rb"", rb"", rb"", Rb"", Rb"")
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||
|
||||
|
||||
def docstring_multiline():
|
||||
R"""
|
||||
clear out all of the issues opened in that time :p
|
||||
"""
|
||||
```
|
||||
|
||||
|
|
@ -1,246 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
importA;() << 0 ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525 #
|
||||
|
||||
assert sort_by_dependency(
|
||||
{
|
||||
"1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"},
|
||||
"2a": set(), "2b": set(), "3a": set(), "3b": set()
|
||||
}
|
||||
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
|
||||
importA
|
||||
0;0^0#
|
||||
|
||||
class A:
|
||||
def foo(self):
|
||||
for _ in range(10):
|
||||
aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member
|
||||
xxxxxxxxxxxx
|
||||
)
|
||||
|
||||
def test(self, othr):
|
||||
return (1 == 2 and
|
||||
(name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) ==
|
||||
(name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule))
|
||||
|
||||
|
||||
assert (
|
||||
a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more)
|
||||
== {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,20 +2,10 @@
|
||||
(
|
||||
()
|
||||
<< 0
|
||||
- ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
+ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
) #
|
||||
|
||||
-assert sort_by_dependency(
|
||||
- {
|
||||
- "1": {"2", "3"},
|
||||
- "2": {"2a", "2b"},
|
||||
- "3": {"3a", "3b"},
|
||||
- "2a": set(),
|
||||
- "2b": set(),
|
||||
- "3a": set(),
|
||||
- "3b": set(),
|
||||
- }
|
||||
-) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
importA
|
||||
0
|
||||
@@ -24,35 +14,34 @@
|
||||
|
||||
class A:
|
||||
def foo(self):
|
||||
- for _ in range(10):
|
||||
- aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(
|
||||
- xxxxxxxxxxxx
|
||||
- ) # pylint: disable=no-member
|
||||
+ for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
+ aaaaaaaaaaaaaaaaaaa = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def test(self, othr):
|
||||
- return 1 == 2 and (
|
||||
- name,
|
||||
- description,
|
||||
- self.default,
|
||||
- self.selected,
|
||||
- self.auto_generated,
|
||||
- self.parameters,
|
||||
- self.meta_data,
|
||||
- self.schedule,
|
||||
- ) == (
|
||||
- name,
|
||||
- description,
|
||||
- othr.default,
|
||||
- othr.selected,
|
||||
- othr.auto_generated,
|
||||
- othr.parameters,
|
||||
- othr.meta_data,
|
||||
- othr.schedule,
|
||||
+ return (
|
||||
+ 1 == 2
|
||||
+ and (
|
||||
+ name,
|
||||
+ description,
|
||||
+ self.default,
|
||||
+ self.selected,
|
||||
+ self.auto_generated,
|
||||
+ self.parameters,
|
||||
+ self.meta_data,
|
||||
+ self.schedule,
|
||||
+ )
|
||||
+ == (
|
||||
+ name,
|
||||
+ description,
|
||||
+ othr.default,
|
||||
+ othr.selected,
|
||||
+ othr.auto_generated,
|
||||
+ othr.parameters,
|
||||
+ othr.meta_data,
|
||||
+ othr.schedule,
|
||||
+ )
|
||||
)
|
||||
|
||||
|
||||
-assert a_function(
|
||||
- very_long_arguments_that_surpass_the_limit,
|
||||
- which_is_eighty_eight_in_this_case_plus_a_bit_more,
|
||||
-) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
importA
|
||||
(
|
||||
()
|
||||
<< 0
|
||||
**101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
) #
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
importA
|
||||
0
|
||||
0 ^ 0 #
|
||||
|
||||
|
||||
class A:
|
||||
def foo(self):
|
||||
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
|
||||
aaaaaaaaaaaaaaaaaaa = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
def test(self, othr):
|
||||
return (
|
||||
1 == 2
|
||||
and (
|
||||
name,
|
||||
description,
|
||||
self.default,
|
||||
self.selected,
|
||||
self.auto_generated,
|
||||
self.parameters,
|
||||
self.meta_data,
|
||||
self.schedule,
|
||||
)
|
||||
== (
|
||||
name,
|
||||
description,
|
||||
othr.default,
|
||||
othr.selected,
|
||||
othr.auto_generated,
|
||||
othr.parameters,
|
||||
othr.meta_data,
|
||||
othr.schedule,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
importA
|
||||
(
|
||||
()
|
||||
<< 0
|
||||
** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
) #
|
||||
|
||||
assert sort_by_dependency(
|
||||
{
|
||||
"1": {"2", "3"},
|
||||
"2": {"2a", "2b"},
|
||||
"3": {"3a", "3b"},
|
||||
"2a": set(),
|
||||
"2b": set(),
|
||||
"3a": set(),
|
||||
"3b": set(),
|
||||
}
|
||||
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
|
||||
importA
|
||||
0
|
||||
0 ^ 0 #
|
||||
|
||||
|
||||
class A:
|
||||
def foo(self):
|
||||
for _ in range(10):
|
||||
aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(
|
||||
xxxxxxxxxxxx
|
||||
) # pylint: disable=no-member
|
||||
|
||||
|
||||
def test(self, othr):
|
||||
return 1 == 2 and (
|
||||
name,
|
||||
description,
|
||||
self.default,
|
||||
self.selected,
|
||||
self.auto_generated,
|
||||
self.parameters,
|
||||
self.meta_data,
|
||||
self.schedule,
|
||||
) == (
|
||||
name,
|
||||
description,
|
||||
othr.default,
|
||||
othr.selected,
|
||||
othr.auto_generated,
|
||||
othr.parameters,
|
||||
othr.meta_data,
|
||||
othr.schedule,
|
||||
)
|
||||
|
||||
|
||||
assert a_function(
|
||||
very_long_arguments_that_surpass_the_limit,
|
||||
which_is_eighty_eight_in_this_case_plus_a_bit_more,
|
||||
) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
```
|
||||
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
|
||||
_winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
|
||||
pass
|
||||
|
||||
if x:
|
||||
if y:
|
||||
new_id = max(Vegetable.objects.order_by('-id')[0].id,
|
||||
Mineral.objects.order_by('-id')[0].id) + 1
|
||||
|
||||
class X:
|
||||
def get_help_text(self):
|
||||
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}
|
||||
|
||||
class A:
|
||||
def b(self):
|
||||
if self.connection.mysql_is_mariadb and (
|
||||
10,
|
||||
4,
|
||||
3,
|
||||
) < self.connection.mysql_version < (10, 5, 2):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,34 +1,32 @@
|
||||
-if e1234123412341234.winerror not in (
|
||||
- _winapi.ERROR_SEM_TIMEOUT,
|
||||
- _winapi.ERROR_PIPE_BUSY,
|
||||
-) or _check_timeout(t):
|
||||
+if (
|
||||
+ e1234123412341234.winerror
|
||||
+ not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
|
||||
+ or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
+):
|
||||
pass
|
||||
|
||||
if x:
|
||||
if y:
|
||||
- new_id = (
|
||||
- max(
|
||||
- Vegetable.objects.order_by("-id")[0].id,
|
||||
- Mineral.objects.order_by("-id")[0].id,
|
||||
- )
|
||||
- + 1
|
||||
- )
|
||||
+ new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1
|
||||
|
||||
|
||||
class X:
|
||||
def get_help_text(self):
|
||||
- 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:
|
||||
def b(self):
|
||||
- if self.connection.mysql_is_mariadb and (
|
||||
- 10,
|
||||
- 4,
|
||||
- 3,
|
||||
- ) < self.connection.mysql_version < (10, 5, 2):
|
||||
+ if (
|
||||
+ self.connection.mysql_is_mariadb
|
||||
+ and (
|
||||
+ 10,
|
||||
+ 4,
|
||||
+ 3,
|
||||
+ )
|
||||
+ < self.connection.mysql_version
|
||||
+ < (10, 5, 2)
|
||||
+ ):
|
||||
pass
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
if (
|
||||
e1234123412341234.winerror
|
||||
not in (_winapi.ERROR_SEM_TIMEOUT, _winapi.ERROR_PIPE_BUSY)
|
||||
or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
):
|
||||
pass
|
||||
|
||||
if x:
|
||||
if y:
|
||||
new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1
|
||||
|
||||
|
||||
class X:
|
||||
def get_help_text(self):
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
|
||||
"min_length": self.min_length,
|
||||
}
|
||||
|
||||
|
||||
class A:
|
||||
def b(self):
|
||||
if (
|
||||
self.connection.mysql_is_mariadb
|
||||
and (
|
||||
10,
|
||||
4,
|
||||
3,
|
||||
)
|
||||
< self.connection.mysql_version
|
||||
< (10, 5, 2)
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
if e1234123412341234.winerror not in (
|
||||
_winapi.ERROR_SEM_TIMEOUT,
|
||||
_winapi.ERROR_PIPE_BUSY,
|
||||
) or _check_timeout(t):
|
||||
pass
|
||||
|
||||
if x:
|
||||
if y:
|
||||
new_id = (
|
||||
max(
|
||||
Vegetable.objects.order_by("-id")[0].id,
|
||||
Mineral.objects.order_by("-id")[0].id,
|
||||
)
|
||||
+ 1
|
||||
)
|
||||
|
||||
|
||||
class X:
|
||||
def get_help_text(self):
|
||||
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}
|
||||
|
||||
|
||||
class A:
|
||||
def b(self):
|
||||
if self.connection.mysql_is_mariadb and (
|
||||
10,
|
||||
4,
|
||||
3,
|
||||
) < self.connection.mysql_version < (10, 5, 2):
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
|
||||
(8, 5, 8) <= get_tk_patchlevel() < (8, 6)):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,5 @@
|
||||
-if e123456.get_tk_patchlevel() >= (8, 6, 0, "final") or (
|
||||
- 8,
|
||||
- 5,
|
||||
- 8,
|
||||
-) <= get_tk_patchlevel() < (8, 6):
|
||||
+if (
|
||||
+ NOT_IMPLEMENTED_call() >= (8, 6, 0, "final")
|
||||
+ or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6)
|
||||
+):
|
||||
pass
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
if (
|
||||
NOT_IMPLEMENTED_call() >= (8, 6, 0, "final")
|
||||
or (8, 5, 8) <= NOT_IMPLEMENTED_call() < (8, 6)
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
if e123456.get_tk_patchlevel() >= (8, 6, 0, "final") or (
|
||||
8,
|
||||
5,
|
||||
8,
|
||||
) <= get_tk_patchlevel() < (8, 6):
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
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}
|
||||
```
|
||||
|
||||
|
|
@ -1,195 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
zero(one,).two(three,).four(five,)
|
||||
|
||||
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||
|
||||
# Inner one-element tuple shouldn't explode
|
||||
func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
|
||||
|
||||
(a, b, c, d,) = func1(arg1) and func2(arg2)
|
||||
|
||||
|
||||
# Example from https://github.com/psf/black/issues/3229
|
||||
def refresh_token(self, device_family, refresh_token, api_key):
|
||||
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
|
||||
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||
assert (
|
||||
long_module.long_class.long_func().another_func()
|
||||
== long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3414.
|
||||
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||
xxxxxxxxx
|
||||
).xxxxxxxxxxxxxxxxxx(), (
|
||||
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,50 +1,26 @@
|
||||
-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,
|
||||
c,
|
||||
d,
|
||||
-) = func1(
|
||||
- arg1
|
||||
-) and func2(arg2)
|
||||
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Example from https://github.com/psf/black/issues/3229
|
||||
def refresh_token(self, device_family, refresh_token, api_key):
|
||||
- return self.orchestration.refresh_token(
|
||||
- data={
|
||||
- "refreshToken": refresh_token,
|
||||
- },
|
||||
- api_key=api_key,
|
||||
- )["extensions"]["sdk"]["token"]
|
||||
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)["extensions"]["sdk"]["token"]
|
||||
|
||||
|
||||
# Edge case where a bug in a working-in-progress version of
|
||||
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||
-assert (
|
||||
- long_module.long_class.long_func().another_func()
|
||||
- == long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3414.
|
||||
-assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||
- xxxxxxxxx
|
||||
-).xxxxxxxxxxxxxxxxxx(), (
|
||||
- "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
# Inner one-element tuple shouldn't explode
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
# Example from https://github.com/psf/black/issues/3229
|
||||
def refresh_token(self, device_family, refresh_token, api_key):
|
||||
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)["extensions"]["sdk"]["token"]
|
||||
|
||||
|
||||
# Edge case where a bug in a working-in-progress version of
|
||||
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3414.
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
zero(
|
||||
one,
|
||||
).two(
|
||||
three,
|
||||
).four(
|
||||
five,
|
||||
)
|
||||
|
||||
func1(arg1).func2(
|
||||
arg2,
|
||||
).func3(arg3).func4(
|
||||
arg4,
|
||||
).func5(arg5)
|
||||
|
||||
# Inner one-element tuple shouldn't explode
|
||||
func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
|
||||
|
||||
(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
) = func1(
|
||||
arg1
|
||||
) and func2(arg2)
|
||||
|
||||
|
||||
# Example from https://github.com/psf/black/issues/3229
|
||||
def refresh_token(self, device_family, refresh_token, api_key):
|
||||
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
|
||||
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||
assert (
|
||||
long_module.long_class.long_func().another_func()
|
||||
== long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||
)
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3414.
|
||||
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||
xxxxxxxxx
|
||||
).xxxxxxxxxxxxxxxxxx(), (
|
||||
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# This is a standalone comment.
|
||||
sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3
|
||||
|
||||
# This is as well.
|
||||
this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
|
||||
|
||||
(a,) = call()
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,9 +4,9 @@
|
||||
sdfjsdfjlksdljkfsdlkf,
|
||||
sdfsdjfklsdfjlksdljkf,
|
||||
sdsfsdfjskdflsfsdf,
|
||||
-) = (1, 2, 3)
|
||||
+) = 1, 2, 3
|
||||
|
||||
# This is as well.
|
||||
-(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
|
||||
+(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
-(a,) = call()
|
||||
+(a,) = NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# This is a standalone comment.
|
||||
(
|
||||
sdfjklsdfsjldkflkjsf,
|
||||
sdfjsdfjlksdljkfsdlkf,
|
||||
sdfsdjfklsdfjlksdljkf,
|
||||
sdsfsdfjskdflsfsdf,
|
||||
) = 1, 2, 3
|
||||
|
||||
# This is as well.
|
||||
(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
(a,) = NOT_IMPLEMENTED_call()
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# This is a standalone comment.
|
||||
(
|
||||
sdfjklsdfsjldkflkjsf,
|
||||
sdfjsdfjlksdljkfsdlkf,
|
||||
sdfsdjfklsdfjlksdljkf,
|
||||
sdsfsdfjskdflsfsdf,
|
||||
) = (1, 2, 3)
|
||||
|
||||
# This is as well.
|
||||
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
|
||||
|
||||
(a,) = call()
|
||||
```
|
||||
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing comment
|
||||
)
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing dot comment # trailing identifier comment
|
||||
)
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing identifier comment
|
||||
)
|
||||
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
. # trailing dot comment
|
||||
# in between
|
||||
b # trailing identifier comment
|
||||
)
|
||||
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaa.lllllllllllllllllllllllllllloooooooooong.chaaaaaaaaaaaaaaaaaaaaaaiiiiiiiiiiiiiiiiiiiiiiinnnnnnnn.ooooooooooooooooooooooooofffffffff.aaaaaaaaaattr
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing comment
|
||||
)
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing dot comment # trailing identifier comment
|
||||
)
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
.b # trailing identifier comment
|
||||
)
|
||||
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
. # trailing dot comment
|
||||
# in between
|
||||
b # trailing identifier comment
|
||||
)
|
||||
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaa.lllllllllllllllllllllllllllloooooooooong.chaaaaaaaaaaaaaaaaaaaaaaiiiiiiiiiiiiiiiiiiiiiiinnnnnnnn.ooooooooooooooooooooooooofffffffff.aaaaaaaaaattr
|
||||
```
|
||||
|
||||
|
|
@ -1,449 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
(aaaaaaaa
|
||||
+ # trailing operator comment
|
||||
b # trailing right comment
|
||||
)
|
||||
|
||||
|
||||
(aaaaaaaa # trailing left comment
|
||||
+ # trailing operator comment
|
||||
# leading right comment
|
||||
b
|
||||
)
|
||||
|
||||
|
||||
# Black breaks the right side first for the following expressions:
|
||||
aaaaaaaaaaaaaa + caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal(argument1, argument2, argument3)
|
||||
aaaaaaaaaaaaaa + [bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee]
|
||||
aaaaaaaaaaaaaa + (bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee)
|
||||
aaaaaaaaaaaaaa + { key1:bbbbbbbbbbbbbbbbbbbbbb, key2: ccccccccccccccccccccc, key3: dddddddddddddddd, key4: eeeeeee }
|
||||
aaaaaaaaaaaaaa + { bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eeeeeee }
|
||||
aaaaaaaaaaaaaa + [a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ]
|
||||
aaaaaaaaaaaaaa + (a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb )
|
||||
aaaaaaaaaaaaaa + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}
|
||||
|
||||
# Wraps it in parentheses if it needs to break both left and right
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + [
|
||||
bbbbbbbbbbbbbbbbbbbbbb,
|
||||
ccccccccccccccccccccc,
|
||||
dddddddddddddddd,
|
||||
eee
|
||||
] # comment
|
||||
|
||||
|
||||
|
||||
# But only for expressions that have a statement parent.
|
||||
not (aaaaaaaaaaaaaa + {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb})
|
||||
[a + [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] in c ]
|
||||
|
||||
|
||||
# leading comment
|
||||
(
|
||||
# comment
|
||||
content + b
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaa +
|
||||
# has the child process finished?
|
||||
bbbbbbbbbbbbbbb +
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
ccccccccccc
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# Left only breaks
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & aaaaaaaaaaaaaaaaaaaaaaaaaa:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
|
||||
...
|
||||
|
||||
# Right only can break
|
||||
if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
|
||||
# Left or right can break
|
||||
if [2222, 333] & [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & [2222, 333]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & [fffffffffffffffff, gggggggggggggggggggg, hhhhhhhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjj]:
|
||||
...
|
||||
|
||||
if (
|
||||
# comment
|
||||
[
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]
|
||||
) & [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]:
|
||||
pass
|
||||
|
||||
...
|
||||
|
||||
# Nesting
|
||||
if (aaaa + b) & [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
] & (a + b):
|
||||
...
|
||||
|
||||
|
||||
if [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
] & (
|
||||
# comment
|
||||
a
|
||||
+ b
|
||||
):
|
||||
...
|
||||
|
||||
if (
|
||||
[
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]
|
||||
&
|
||||
# comment
|
||||
a + b
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py
|
||||
for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
||||
updates.append(UserPresenceState.default(user_id))
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
(
|
||||
aaaaaaaa
|
||||
+ b # trailing operator comment # trailing right comment
|
||||
)
|
||||
|
||||
|
||||
(
|
||||
aaaaaaaa # trailing left comment
|
||||
+ # trailing operator comment
|
||||
# leading right comment
|
||||
b
|
||||
)
|
||||
|
||||
|
||||
# Black breaks the right side first for the following expressions:
|
||||
aaaaaaaaaaaaaa + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
aaaaaaaaaaaaaa + [
|
||||
bbbbbbbbbbbbbbbbbbbbbb,
|
||||
ccccccccccccccccccccc,
|
||||
dddddddddddddddd,
|
||||
eeeeeee,
|
||||
]
|
||||
aaaaaaaaaaaaaa + (
|
||||
bbbbbbbbbbbbbbbbbbbbbb,
|
||||
ccccccccccccccccccccc,
|
||||
dddddddddddddddd,
|
||||
eeeeeee,
|
||||
)
|
||||
aaaaaaaaaaaaaa + {
|
||||
key1: bbbbbbbbbbbbbbbbbbbbbb,
|
||||
key2: ccccccccccccccccccccc,
|
||||
key3: dddddddddddddddd,
|
||||
key4: eeeeeee,
|
||||
}
|
||||
aaaaaaaaaaaaaa + {
|
||||
bbbbbbbbbbbbbbbbbbbbbb,
|
||||
ccccccccccccccccccccc,
|
||||
dddddddddddddddd,
|
||||
eeeeeee,
|
||||
}
|
||||
aaaaaaaaaaaaaa + [i for i in []]
|
||||
aaaaaaaaaaaaaa + (i for i in [])
|
||||
aaaaaaaaaaaaaa + {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
|
||||
|
||||
# Wraps it in parentheses if it needs to break both left and right
|
||||
(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ [bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eee]
|
||||
) # comment
|
||||
|
||||
|
||||
# But only for expressions that have a statement parent.
|
||||
not (aaaaaaaaaaaaaa + {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set})
|
||||
[
|
||||
a
|
||||
+ [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||
]
|
||||
in c,
|
||||
]
|
||||
|
||||
|
||||
# leading comment
|
||||
(
|
||||
# comment
|
||||
content
|
||||
+ b
|
||||
)
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaa
|
||||
+
|
||||
# has the child process finished?
|
||||
bbbbbbbbbbbbbbb
|
||||
+
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
ccccccccccc
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# Left only breaks
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & aaaaaaaaaaaaaaaaaaaaaaaaaa:
|
||||
...
|
||||
|
||||
if (
|
||||
[
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]
|
||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
):
|
||||
...
|
||||
|
||||
# Right only can break
|
||||
if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
& [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Left or right can break
|
||||
if [2222, 333] & [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & [2222, 333]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] & [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]:
|
||||
...
|
||||
|
||||
if (
|
||||
# comment
|
||||
[
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]
|
||||
) & [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]:
|
||||
pass
|
||||
|
||||
...
|
||||
|
||||
# Nesting
|
||||
if (aaaa + b) & [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
] & (a + b):
|
||||
...
|
||||
|
||||
|
||||
if (
|
||||
[
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]
|
||||
&
|
||||
(
|
||||
# comment
|
||||
a
|
||||
+ b
|
||||
)
|
||||
):
|
||||
...
|
||||
|
||||
if (
|
||||
[
|
||||
fffffffffffffffff,
|
||||
gggggggggggggggggggg,
|
||||
hhhhhhhhhhhhhhhhhhhhh,
|
||||
iiiiiiiiiiiiiiii,
|
||||
jjjjjjjjjjjjj,
|
||||
]
|
||||
&
|
||||
# comment
|
||||
a
|
||||
+ b
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py
|
||||
for (
|
||||
user_id
|
||||
) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) - {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}:
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
if (
|
||||
self._proc
|
||||
# has the child process finished?
|
||||
and self._returncode
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and self._proc.poll()
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
self._proc
|
||||
and self._returncode
|
||||
and self._proc.poll()
|
||||
and self._proc
|
||||
and self._returncode
|
||||
and self._proc.poll()
|
||||
):
|
||||
...
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
|
||||
and aaaaaaaaaaaaaaaaa
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
if [2222, 333] and [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] and [2222, 333]:
|
||||
pass
|
||||
|
||||
# Break right only applies for boolean operations with a left and right side
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
and ccccccccccccccccc
|
||||
and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if (
|
||||
self._proc
|
||||
# has the child process finished?
|
||||
and self._returncode
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and NOT_IMPLEMENTED_call()
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
self._proc
|
||||
and self._returncode
|
||||
and NOT_IMPLEMENTED_call()
|
||||
and self._proc
|
||||
and self._returncode
|
||||
and NOT_IMPLEMENTED_call()
|
||||
):
|
||||
...
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
|
||||
and aaaaaaaaaaaaaaaaa
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
if [2222, 333] and [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
]:
|
||||
...
|
||||
|
||||
if [
|
||||
aaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbbbbbbb,
|
||||
cccccccccccccccccccc,
|
||||
dddddddddddddddddddd,
|
||||
eeeeeeeeee,
|
||||
] and [2222, 333]:
|
||||
pass
|
||||
|
||||
# Break right only applies for boolean operations with a left and right side
|
||||
if (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
and ccccccccccccccccc
|
||||
and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,189 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
a == b
|
||||
a != b
|
||||
a < b
|
||||
a <= b
|
||||
a > b
|
||||
a >= b
|
||||
a is b
|
||||
a is not b
|
||||
a in b
|
||||
a not in b
|
||||
|
||||
(a ==
|
||||
# comment
|
||||
b
|
||||
)
|
||||
|
||||
(a == # comment
|
||||
b
|
||||
)
|
||||
|
||||
a < b > c == d
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb > ccccccccccccccccccccccccccccc == ddddddddddddddddddddd
|
||||
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa < [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||
ff,
|
||||
] < [ccccccccccccccccccccccccccccc, dddd] < ddddddddddddddddddddddddddddddddddddddddddd
|
||||
|
||||
return 1 == 2 and (
|
||||
name,
|
||||
description,
|
||||
self_default,
|
||||
self_selected,
|
||||
self_auto_generated,
|
||||
self_parameters,
|
||||
self_meta_data,
|
||||
self_schedule,
|
||||
) == (
|
||||
name,
|
||||
description,
|
||||
othr_default,
|
||||
othr_selected,
|
||||
othr_auto_generated,
|
||||
othr_parameters,
|
||||
othr_meta_data,
|
||||
othr_schedule,
|
||||
)
|
||||
|
||||
(name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule)
|
||||
((name, description, self_default, self_selected, self_auto_generated, self_parameters, self_meta_data, self_schedule) == (name, description, other_default, othr_selected, othr_auto_generated, othr_parameters, othr_meta_data, othr_schedule))
|
||||
|
||||
[
|
||||
(
|
||||
a
|
||||
+ [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
]
|
||||
>= c
|
||||
)
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
a == b
|
||||
a != b
|
||||
a < b
|
||||
a <= b
|
||||
a > b
|
||||
a >= b
|
||||
a is b
|
||||
a is not b
|
||||
a in b
|
||||
a not in b
|
||||
|
||||
(
|
||||
a
|
||||
# comment
|
||||
== b
|
||||
)
|
||||
|
||||
(
|
||||
a # comment
|
||||
== b
|
||||
)
|
||||
|
||||
a < b > c == d
|
||||
|
||||
(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
> ccccccccccccccccccccccccccccc
|
||||
== ddddddddddddddddddddd
|
||||
)
|
||||
|
||||
(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
< [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ff]
|
||||
< [ccccccccccccccccccccccccccccc, dddd]
|
||||
< ddddddddddddddddddddddddddddddddddddddddddd
|
||||
)
|
||||
|
||||
return (
|
||||
1 == 2
|
||||
and (
|
||||
name,
|
||||
description,
|
||||
self_default,
|
||||
self_selected,
|
||||
self_auto_generated,
|
||||
self_parameters,
|
||||
self_meta_data,
|
||||
self_schedule,
|
||||
)
|
||||
== (
|
||||
name,
|
||||
description,
|
||||
othr_default,
|
||||
othr_selected,
|
||||
othr_auto_generated,
|
||||
othr_parameters,
|
||||
othr_meta_data,
|
||||
othr_schedule,
|
||||
)
|
||||
)
|
||||
|
||||
(
|
||||
name,
|
||||
description,
|
||||
self_default,
|
||||
self_selected,
|
||||
self_auto_generated,
|
||||
self_parameters,
|
||||
self_meta_data,
|
||||
self_schedule,
|
||||
) == (
|
||||
name,
|
||||
description,
|
||||
other_default,
|
||||
othr_selected,
|
||||
othr_auto_generated,
|
||||
othr_parameters,
|
||||
othr_meta_data,
|
||||
othr_schedule,
|
||||
)
|
||||
(
|
||||
(
|
||||
name,
|
||||
description,
|
||||
self_default,
|
||||
self_selected,
|
||||
self_auto_generated,
|
||||
self_parameters,
|
||||
self_meta_data,
|
||||
self_schedule,
|
||||
)
|
||||
== (
|
||||
name,
|
||||
description,
|
||||
other_default,
|
||||
othr_selected,
|
||||
othr_auto_generated,
|
||||
othr_parameters,
|
||||
othr_meta_data,
|
||||
othr_schedule,
|
||||
)
|
||||
)
|
||||
|
||||
[
|
||||
(
|
||||
a
|
||||
+ [
|
||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
|
||||
]
|
||||
>= c
|
||||
),
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,133 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# before
|
||||
{ # open
|
||||
key# key
|
||||
: # colon
|
||||
value# value
|
||||
} # close
|
||||
# after
|
||||
|
||||
|
||||
{**d}
|
||||
|
||||
{**a, # leading
|
||||
** # middle
|
||||
b # trailing
|
||||
}
|
||||
|
||||
{
|
||||
** # middle with single item
|
||||
b
|
||||
}
|
||||
|
||||
{
|
||||
# before
|
||||
** # between
|
||||
b,
|
||||
}
|
||||
|
||||
{
|
||||
**a # comment before preceeding node's comma
|
||||
,
|
||||
# before
|
||||
** # between
|
||||
b,
|
||||
}
|
||||
|
||||
{}
|
||||
|
||||
{1:2,}
|
||||
|
||||
{1:2,
|
||||
3:4,}
|
||||
|
||||
{asdfsadfalsdkjfhalsdkjfhalskdjfhlaksjdfhlaskjdfhlaskjdfhlaksdjfh: 1, adsfadsflasdflasdfasdfasdasdf: 2}
|
||||
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
|
||||
# Regression test for formatter panic with comment after parenthesized dict value
|
||||
# Originally found in https://github.com/bolucat/Firefox/blob/636a717ef025c16434997dc89e42351ef740ee6b/testing/marionette/client/marionette_driver/geckoinstance.py#L109
|
||||
a = {
|
||||
1: (2),
|
||||
# comment
|
||||
3: True,
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# before
|
||||
{
|
||||
# open
|
||||
key: value, # key # colon # value
|
||||
} # close
|
||||
# after
|
||||
|
||||
|
||||
{**d}
|
||||
|
||||
{
|
||||
**a, # leading
|
||||
**b, # middle # trailing
|
||||
}
|
||||
|
||||
{
|
||||
**b, # middle with single item
|
||||
}
|
||||
|
||||
{
|
||||
# before
|
||||
**b, # between
|
||||
}
|
||||
|
||||
{
|
||||
**a, # comment before preceeding node's comma
|
||||
# before
|
||||
**b, # between
|
||||
}
|
||||
|
||||
{}
|
||||
|
||||
{
|
||||
1: 2,
|
||||
}
|
||||
|
||||
{
|
||||
1: 2,
|
||||
3: 4,
|
||||
}
|
||||
|
||||
{
|
||||
asdfsadfalsdkjfhalsdkjfhalskdjfhlaksjdfhlaskjdfhlaskjdfhlaksdjfh: 1,
|
||||
adsfadsflasdflasdfasdfasdasdf: 2,
|
||||
}
|
||||
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
|
||||
# Regression test for formatter panic with comment after parenthesized dict value
|
||||
# Originally found in https://github.com/bolucat/Firefox/blob/636a717ef025c16434997dc89e42351ef740ee6b/testing/marionette/client/marionette_driver/geckoinstance.py#L109
|
||||
a = {
|
||||
1: (2),
|
||||
# comment
|
||||
3: True,
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# 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
|
||||
]
|
||||
a2 = [ # a
|
||||
# b
|
||||
]
|
||||
a3 = [
|
||||
# b
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# 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
|
||||
]
|
||||
a2 = [ # a
|
||||
# b
|
||||
]
|
||||
a3 = [
|
||||
# b
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# Handle comments both when lower and upper exist and when they don't
|
||||
a1 = "a"[
|
||||
# a
|
||||
1 # b
|
||||
: # c
|
||||
2 # d
|
||||
]
|
||||
a2 = "a"[
|
||||
# a
|
||||
# b
|
||||
: # c
|
||||
# d
|
||||
]
|
||||
|
||||
# Check all places where comments can exist
|
||||
b1 = "b"[ # a
|
||||
# b
|
||||
1 # c
|
||||
# d
|
||||
: # e
|
||||
# f
|
||||
2 # g
|
||||
# h
|
||||
: # i
|
||||
# j
|
||||
3 # k
|
||||
# l
|
||||
]
|
||||
|
||||
# Handle the spacing from the colon correctly with upper leading comments
|
||||
c1 = "c"[
|
||||
1
|
||||
: # e
|
||||
# f
|
||||
2
|
||||
]
|
||||
c2 = "c"[
|
||||
1
|
||||
: # e
|
||||
2
|
||||
]
|
||||
c3 = "c"[
|
||||
1
|
||||
:
|
||||
# f
|
||||
2
|
||||
]
|
||||
c4 = "c"[
|
||||
1
|
||||
: # f
|
||||
2
|
||||
]
|
||||
|
||||
# End of line comments
|
||||
d1 = "d"[ # comment
|
||||
:
|
||||
]
|
||||
d2 = "d"[ # comment
|
||||
1:
|
||||
]
|
||||
d3 = "d"[
|
||||
1 # comment
|
||||
:
|
||||
]
|
||||
|
||||
# Spacing around the colon(s)
|
||||
def a():
|
||||
...
|
||||
|
||||
e00 = "e"[:]
|
||||
e01 = "e"[:1]
|
||||
e02 = "e"[: a()]
|
||||
e10 = "e"[1:]
|
||||
e11 = "e"[1:1]
|
||||
e12 = "e"[1 : a()]
|
||||
e20 = "e"[a() :]
|
||||
e21 = "e"[a() : 1]
|
||||
e22 = "e"[a() : a()]
|
||||
e200 = "e"[a() :: ]
|
||||
e201 = "e"[a() :: 1]
|
||||
e202 = "e"[a() :: a()]
|
||||
e210 = "e"[a() : 1 :]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Handle comments both when lower and upper exist and when they don't
|
||||
a1 = "a"[
|
||||
# a
|
||||
1 # b
|
||||
: # c
|
||||
2 # d
|
||||
]
|
||||
a2 = "a"[
|
||||
# a
|
||||
# b
|
||||
: # c
|
||||
# d
|
||||
]
|
||||
|
||||
# Check all places where comments can exist
|
||||
b1 = "b"[ # a
|
||||
# b
|
||||
1 # c
|
||||
# d
|
||||
: # e
|
||||
# f
|
||||
2 # g
|
||||
# h
|
||||
: # i
|
||||
# j
|
||||
3 # k
|
||||
# l
|
||||
]
|
||||
|
||||
# Handle the spacing from the colon correctly with upper leading comments
|
||||
c1 = "c"[
|
||||
1: # e
|
||||
# f
|
||||
2
|
||||
]
|
||||
c2 = "c"[
|
||||
1: # e
|
||||
2
|
||||
]
|
||||
c3 = "c"[
|
||||
1:
|
||||
# f
|
||||
2
|
||||
]
|
||||
c4 = "c"[
|
||||
1: # f
|
||||
2
|
||||
]
|
||||
|
||||
# End of line comments
|
||||
d1 = "d"[ # comment
|
||||
:
|
||||
]
|
||||
d2 = "d"[ # comment
|
||||
1:
|
||||
]
|
||||
d3 = "d"[
|
||||
1 # comment
|
||||
:
|
||||
]
|
||||
|
||||
|
||||
# Spacing around the colon(s)
|
||||
def a():
|
||||
...
|
||||
|
||||
|
||||
e00 = "e"[:]
|
||||
e01 = "e"[:1]
|
||||
e02 = "e"[ : NOT_IMPLEMENTED_call()]
|
||||
e10 = "e"[1:]
|
||||
e11 = "e"[1:1]
|
||||
e12 = "e"[1 : NOT_IMPLEMENTED_call()]
|
||||
e20 = "e"[NOT_IMPLEMENTED_call() :]
|
||||
e21 = "e"[NOT_IMPLEMENTED_call() : 1]
|
||||
e22 = "e"[NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()]
|
||||
e200 = "e"[NOT_IMPLEMENTED_call() : :]
|
||||
e201 = "e"[NOT_IMPLEMENTED_call() :: 1]
|
||||
e202 = "e"[NOT_IMPLEMENTED_call() :: NOT_IMPLEMENTED_call()]
|
||||
e210 = "e"[NOT_IMPLEMENTED_call() : 1 :]
|
||||
```
|
||||
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
"\" test"
|
||||
'\' test'
|
||||
|
||||
# Prefer single quotes for string with more double quotes
|
||||
"' \" \" '' \" \" '"
|
||||
|
||||
# Prefer double quotes for string with more single quotes
|
||||
'\' " " \'\' " " \''
|
||||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
'" \' " " \'\''
|
||||
"' \" '' \" \" '"
|
||||
|
||||
"\\' \"\""
|
||||
'\\\' ""'
|
||||
|
||||
|
||||
u"Test"
|
||||
U"Test"
|
||||
|
||||
r"Test"
|
||||
R"Test"
|
||||
|
||||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
if True:
|
||||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
"""Multiline
|
||||
String \"
|
||||
"""
|
||||
|
||||
'''Multiline
|
||||
String \'
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String ""
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String """
|
||||
'''
|
||||
|
||||
'''Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
"' test"
|
||||
'" test'
|
||||
|
||||
'" test'
|
||||
"' test"
|
||||
|
||||
# Prefer single quotes for string with more double quotes
|
||||
"' \" \" '' \" \" '"
|
||||
|
||||
# Prefer double quotes for string with more single quotes
|
||||
"' \" \" '' \" \" '"
|
||||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
"\" ' \" \" ''"
|
||||
"' \" '' \" \" '"
|
||||
|
||||
'\\\' ""'
|
||||
'\\\' ""'
|
||||
|
||||
|
||||
"Test"
|
||||
"Test"
|
||||
|
||||
r"Test"
|
||||
R"Test"
|
||||
|
||||
"This string will not include \
|
||||
backslashes or newline characters."
|
||||
|
||||
if True:
|
||||
"This string will not include \
|
||||
backslashes or newline characters."
|
||||
|
||||
"""Multiline
|
||||
String \"
|
||||
"""
|
||||
|
||||
"""Multiline
|
||||
String \'
|
||||
"""
|
||||
|
||||
"""Multiline
|
||||
String ""
|
||||
"""
|
||||
|
||||
'''Multiline
|
||||
String """
|
||||
'''
|
||||
|
||||
"""Multiline
|
||||
String \"\"\"
|
||||
"""
|
||||
```
|
||||
|
||||
|
|
@ -1,266 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# Non-wrapping parentheses checks
|
||||
a1 = 1, 2
|
||||
a2 = (1, 2)
|
||||
a3 = (1, 2), 3
|
||||
a4 = ((1, 2), 3)
|
||||
|
||||
# Wrapping parentheses checks
|
||||
b1 = (("Michael", "Ende"), ("Der", "satanarchäolügenialkohöllische", "Wunschpunsch"), ("Beelzebub", "Irrwitzer"), ("Tyrannja", "Vamperl"),)
|
||||
b2 = ("akjdshflkjahdslkfjlasfdahjlfds", "ljklsadhflakfdajflahfdlajfhafldkjalfj", "ljklsadhflakfdajflahfdlajfhafldkjalf2",)
|
||||
b3 = ("The", "Night", "of", "Wishes:", "Or", "the", "Satanarchaeolidealcohellish", "Notion", "Potion",)
|
||||
|
||||
# Nested wrapping parentheses check
|
||||
c1 = (("cicero"), ("Qui", "autem,", "si", "maxime", "hoc", "placeat,", "moderatius", "tamen", "id", "uolunt", "fieri,", "difficilem", "quandam", "temperantiam", "postulant", "in", "eo,", "quod", "semel", "admissum", "coerceri", "reprimique", "non", "potest,", "ut", "propemodum", "iustioribus", "utamur", "illis,", "qui", "omnino", "auocent", "a", "philosophia,", "quam", "his,", "qui", "rebus", "infinitis", "modum", "constituant", "in", "reque", "eo", "meliore,", "quo", "maior", "sit,", "mediocritatem", "desiderent."), ("de", "finibus", "bonorum", "et", "malorum"))
|
||||
|
||||
# Deeply nested parentheses
|
||||
d1 = ((("3D",),),)
|
||||
d2 = (((((((((((((((((((((((((((("¯\_(ツ)_/¯",),),),),),),),),),),),),),),),),),),),),),),),),),),),)
|
||||
|
||||
# Join and magic trailing comma
|
||||
e1 = (
|
||||
1,
|
||||
2
|
||||
)
|
||||
e2 = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
e3 = (
|
||||
1,
|
||||
)
|
||||
e4 = (
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor",
|
||||
"incididunt"
|
||||
)
|
||||
|
||||
# Empty tuples and comments
|
||||
f1 = (
|
||||
# empty
|
||||
)
|
||||
f2 = ()
|
||||
|
||||
# Comments in other tuples
|
||||
g1 = ( # a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
) # e
|
||||
g2 = ( # a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
2, # e
|
||||
# f
|
||||
) # g
|
||||
|
||||
# Ensure the correct number of parentheses
|
||||
h1 = ((((1, 2))))
|
||||
h2 = ((((1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq"))))
|
||||
h3 = 1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Non-wrapping parentheses checks
|
||||
a1 = 1, 2
|
||||
a2 = (1, 2)
|
||||
a3 = (1, 2), 3
|
||||
a4 = ((1, 2), 3)
|
||||
|
||||
# Wrapping parentheses checks
|
||||
b1 = (
|
||||
("Michael", "Ende"),
|
||||
("Der", "satanarchäolügenialkohöllische", "Wunschpunsch"),
|
||||
("Beelzebub", "Irrwitzer"),
|
||||
("Tyrannja", "Vamperl"),
|
||||
)
|
||||
b2 = (
|
||||
"akjdshflkjahdslkfjlasfdahjlfds",
|
||||
"ljklsadhflakfdajflahfdlajfhafldkjalfj",
|
||||
"ljklsadhflakfdajflahfdlajfhafldkjalf2",
|
||||
)
|
||||
b3 = (
|
||||
"The",
|
||||
"Night",
|
||||
"of",
|
||||
"Wishes:",
|
||||
"Or",
|
||||
"the",
|
||||
"Satanarchaeolidealcohellish",
|
||||
"Notion",
|
||||
"Potion",
|
||||
)
|
||||
|
||||
# Nested wrapping parentheses check
|
||||
c1 = (
|
||||
("cicero"),
|
||||
(
|
||||
"Qui",
|
||||
"autem,",
|
||||
"si",
|
||||
"maxime",
|
||||
"hoc",
|
||||
"placeat,",
|
||||
"moderatius",
|
||||
"tamen",
|
||||
"id",
|
||||
"uolunt",
|
||||
"fieri,",
|
||||
"difficilem",
|
||||
"quandam",
|
||||
"temperantiam",
|
||||
"postulant",
|
||||
"in",
|
||||
"eo,",
|
||||
"quod",
|
||||
"semel",
|
||||
"admissum",
|
||||
"coerceri",
|
||||
"reprimique",
|
||||
"non",
|
||||
"potest,",
|
||||
"ut",
|
||||
"propemodum",
|
||||
"iustioribus",
|
||||
"utamur",
|
||||
"illis,",
|
||||
"qui",
|
||||
"omnino",
|
||||
"auocent",
|
||||
"a",
|
||||
"philosophia,",
|
||||
"quam",
|
||||
"his,",
|
||||
"qui",
|
||||
"rebus",
|
||||
"infinitis",
|
||||
"modum",
|
||||
"constituant",
|
||||
"in",
|
||||
"reque",
|
||||
"eo",
|
||||
"meliore,",
|
||||
"quo",
|
||||
"maior",
|
||||
"sit,",
|
||||
"mediocritatem",
|
||||
"desiderent.",
|
||||
),
|
||||
("de", "finibus", "bonorum", "et", "malorum"),
|
||||
)
|
||||
|
||||
# Deeply nested parentheses
|
||||
d1 = ((("3D",),),)
|
||||
d2 = (
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
"¯\_(ツ)_/¯",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
# Join and magic trailing comma
|
||||
e1 = (1, 2)
|
||||
e2 = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
e3 = (1,)
|
||||
e4 = (
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor",
|
||||
"incididunt",
|
||||
)
|
||||
|
||||
# Empty tuples and comments
|
||||
f1 = (
|
||||
# empty
|
||||
)
|
||||
f2 = ()
|
||||
|
||||
# Comments in other tuples
|
||||
g1 = (
|
||||
# a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
) # e
|
||||
g2 = (
|
||||
# a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
2, # e
|
||||
# f
|
||||
) # g
|
||||
|
||||
# Ensure the correct number of parentheses
|
||||
h1 = (1, 2)
|
||||
h2 = (
|
||||
1,
|
||||
"qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq",
|
||||
)
|
||||
h3 = (
|
||||
1,
|
||||
"qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq",
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -1,302 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
if not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb:
|
||||
pass
|
||||
|
||||
a = True
|
||||
not a
|
||||
|
||||
b = 10
|
||||
-b
|
||||
+b
|
||||
|
||||
## Leading operand comments
|
||||
|
||||
if not (
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if ~(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
if -(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
|
||||
if +(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
if (
|
||||
not
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
~
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
if (
|
||||
-
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
+
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb):
|
||||
pass
|
||||
|
||||
## Parentheses
|
||||
|
||||
if (
|
||||
# unary comment
|
||||
not
|
||||
# operand comment
|
||||
(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
):
|
||||
pass
|
||||
|
||||
if (not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
):
|
||||
pass
|
||||
|
||||
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
## Trailing operator comments
|
||||
|
||||
if (
|
||||
not # comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
~ # comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
- # comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
+ # comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
## Varia
|
||||
|
||||
if not \
|
||||
a:
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if (
|
||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
a = True
|
||||
not a
|
||||
|
||||
b = 10
|
||||
-b
|
||||
+b
|
||||
|
||||
## Leading operand comments
|
||||
|
||||
if not (
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if ~(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if -(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if +(
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
not
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
~
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
-
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
+
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
## Parentheses
|
||||
|
||||
if (
|
||||
# unary comment
|
||||
not (
|
||||
# operand comment
|
||||
# comment
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
):
|
||||
pass
|
||||
|
||||
if not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (
|
||||
not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
not (
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
)
|
||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
## Trailing operator comments
|
||||
|
||||
if (
|
||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # comment
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # comment
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
if (
|
||||
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # comment
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
if (
|
||||
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # comment
|
||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
## Varia
|
||||
|
||||
if not a:
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# break left hand side
|
||||
a1akjdshflkjahdslkfjlasfdahjlfds = bakjdshflkjahdslkfjlasfdahjlfds = cakjdshflkjahdslkfjlasfdahjlfds = kjaödkjaföjfahlfdalfhaöfaöfhaöfha = fkjaödkjaföjfahlfdalfhaöfaöfhaöfha = g = 3
|
||||
|
||||
# join left hand side
|
||||
a2 = (
|
||||
b2
|
||||
) = 2
|
||||
|
||||
# Break the last element
|
||||
a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = 1
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# break left hand side
|
||||
a1akjdshflkjahdslkfjlasfdahjlfds = bakjdshflkjahdslkfjlasfdahjlfds = cakjdshflkjahdslkfjlasfdahjlfds = kjaödkjaföjfahlfdalfhaöfaöfhaöfha = fkjaödkjaföjfahlfdalfhaöfaöfhaöfha = g = 3
|
||||
|
||||
# join left hand side
|
||||
a2 = (b2) = 2
|
||||
|
||||
# Break the last element
|
||||
a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = 1
|
||||
```
|
||||
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# leading comment
|
||||
while True: # block comment
|
||||
# inside comment
|
||||
break # break comment
|
||||
# post comment
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# leading comment
|
||||
while True: # block comment
|
||||
# inside comment
|
||||
break # break comment
|
||||
# post comment
|
||||
```
|
||||
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
class Test(
|
||||
Aaaaaaaaaaaaaaaaa,
|
||||
Bbbbbbbbbbbbbbbb,
|
||||
DDDDDDDDDDDDDDDD,
|
||||
EEEEEEEEEEEEEE,
|
||||
metaclass=meta,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class Test((Aaaaaaaaaaaaaaaaa), Bbbbbbbbbbbbbbbb, metaclass=meta):
|
||||
pass
|
||||
|
||||
class Test( # trailing class comment
|
||||
Aaaaaaaaaaaaaaaaa, # trailing comment
|
||||
|
||||
# in between comment
|
||||
|
||||
Bbbbbbbbbbbbbbbb,
|
||||
# another leading comment
|
||||
DDDDDDDDDDDDDDDD,
|
||||
EEEEEEEEEEEEEE,
|
||||
# meta comment
|
||||
metaclass=meta, # trailing meta comment
|
||||
):
|
||||
pass
|
||||
|
||||
class Test((Aaaa)):
|
||||
...
|
||||
|
||||
|
||||
class Test(aaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccccccccccc + dddddddddddddddddddddd + eeeeeeeee, ffffffffffffffffff, gggggggggggggggggg):
|
||||
pass
|
||||
|
||||
class Test(Aaaa): # trailing comment
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
class Test(
|
||||
Aaaaaaaaaaaaaaaaa,
|
||||
Bbbbbbbbbbbbbbbb,
|
||||
DDDDDDDDDDDDDDDD,
|
||||
EEEEEEEEEEEEEE,
|
||||
metaclass=meta,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class Test((Aaaaaaaaaaaaaaaaa), Bbbbbbbbbbbbbbbb, metaclass=meta):
|
||||
pass
|
||||
|
||||
|
||||
class Test(
|
||||
# trailing class comment
|
||||
Aaaaaaaaaaaaaaaaa, # trailing comment
|
||||
# in between comment
|
||||
Bbbbbbbbbbbbbbbb,
|
||||
# another leading comment
|
||||
DDDDDDDDDDDDDDDD,
|
||||
EEEEEEEEEEEEEE,
|
||||
# meta comment
|
||||
metaclass=meta, # trailing meta comment
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class Test((Aaaa)):
|
||||
...
|
||||
|
||||
|
||||
class Test(
|
||||
aaaaaaaaaaaaaaa
|
||||
+ bbbbbbbbbbbbbbbbbbbbbb
|
||||
+ cccccccccccccccccccccccc
|
||||
+ dddddddddddddddddddddd
|
||||
+ eeeeeeeee,
|
||||
ffffffffffffffffff,
|
||||
gggggggggggggggggg,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class Test(Aaaa): # trailing comment
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
for x in y: # trailing test comment
|
||||
pass # trailing last statement comment
|
||||
|
||||
# trailing for body comment
|
||||
|
||||
# leading else comment
|
||||
|
||||
else: # trailing else comment
|
||||
pass
|
||||
|
||||
# trailing else body comment
|
||||
|
||||
|
||||
for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn in anotherVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn: # trailing comment
|
||||
pass
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
for (
|
||||
x,
|
||||
y,
|
||||
) in z: # comment
|
||||
...
|
||||
|
||||
|
||||
# remove brackets around x,y but keep them around z,w
|
||||
for (x, y) in (z, w):
|
||||
...
|
||||
|
||||
|
||||
# type comment
|
||||
for x in (): # type: int
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
for x in y: # trailing test comment
|
||||
pass # trailing last statement comment
|
||||
|
||||
# trailing for body comment
|
||||
|
||||
# leading else comment
|
||||
|
||||
else: # trailing else comment
|
||||
pass
|
||||
|
||||
# trailing else body comment
|
||||
|
||||
|
||||
for (
|
||||
aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
|
||||
) in (
|
||||
anotherVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
|
||||
): # trailing comment
|
||||
pass
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
for (
|
||||
x,
|
||||
y,
|
||||
) in z: # comment
|
||||
...
|
||||
|
||||
|
||||
# remove brackets around x,y but keep them around z,w
|
||||
for x, y in (z, w):
|
||||
...
|
||||
|
||||
|
||||
# type comment
|
||||
for x in (): # type: int
|
||||
...
|
||||
```
|
||||
|
||||
|
|
@ -1,518 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
# Dangling comments
|
||||
def test(
|
||||
# comment
|
||||
|
||||
# another
|
||||
|
||||
): ...
|
||||
|
||||
|
||||
# Argument empty line spacing
|
||||
def test(
|
||||
# comment
|
||||
a,
|
||||
|
||||
# another
|
||||
|
||||
b,
|
||||
): ...
|
||||
|
||||
|
||||
### Different function argument wrappings
|
||||
|
||||
def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc):
|
||||
pass
|
||||
|
||||
def arguments_on_their_own_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee):
|
||||
pass
|
||||
|
||||
def argument_per_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff):
|
||||
pass
|
||||
|
||||
def last_pos_only_trailing_comma(a, b, /,):
|
||||
pass
|
||||
|
||||
def last_pos_no_trailing_comma(a, b, /):
|
||||
pass
|
||||
|
||||
|
||||
def varg_with_leading_comments(
|
||||
a, b,
|
||||
# comment
|
||||
*args
|
||||
): ...
|
||||
|
||||
def kwarg_with_leading_comments(
|
||||
a, b,
|
||||
# comment
|
||||
**kwargs
|
||||
): ...
|
||||
|
||||
def argument_with_long_default(
|
||||
a,
|
||||
b = ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + [
|
||||
dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff
|
||||
],
|
||||
h = []
|
||||
): ...
|
||||
|
||||
|
||||
def argument_with_long_type_annotation(
|
||||
a,
|
||||
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||
h = []
|
||||
): ...
|
||||
|
||||
|
||||
def test(): ...
|
||||
|
||||
# Comment
|
||||
def with_leading_comment(): ...
|
||||
|
||||
# Comment that could be mistaken for a trailing comment of the function declaration when
|
||||
# looking from the position of the if
|
||||
# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260
|
||||
if True:
|
||||
def f1():
|
||||
pass # a
|
||||
else:
|
||||
pass
|
||||
|
||||
# Here it's actually a trailing comment
|
||||
if True:
|
||||
def f2():
|
||||
pass
|
||||
# a
|
||||
else:
|
||||
pass
|
||||
|
||||
# Make sure the star is printed
|
||||
# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513
|
||||
def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2):
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/5176#issuecomment-1598171989
|
||||
def foo(
|
||||
b=3 + 2 # comment
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Comments on the slash or the star, both of which don't have a node
|
||||
def f11(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
def f12(
|
||||
a=1,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b=2,
|
||||
):
|
||||
pass
|
||||
|
||||
def f13(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
):
|
||||
pass
|
||||
|
||||
def f21(
|
||||
a=1,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
b=2,
|
||||
):
|
||||
pass
|
||||
|
||||
def f22(
|
||||
a,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
def f23(
|
||||
a,
|
||||
# keyword only comment, leading
|
||||
*args, # keyword only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
def f24(
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
a
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f31(
|
||||
a=1,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b=2,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c=3,
|
||||
):
|
||||
pass
|
||||
|
||||
def f32(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
def f33(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
# keyword only comment, leading
|
||||
*args, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f34(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
def f35(
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
# Multiple trailing comments
|
||||
def f41(
|
||||
a,
|
||||
/ # 1
|
||||
, # 2
|
||||
# 3
|
||||
* # 4
|
||||
, # 5
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
# Multiple trailing comments strangely places. The goal here is only stable formatting,
|
||||
# the comments are placed to strangely to keep their relative position intact
|
||||
def f42(
|
||||
a,
|
||||
/ # 1
|
||||
# 2
|
||||
, # 3
|
||||
# 4
|
||||
* # 5
|
||||
# 6
|
||||
, # 7
|
||||
c,
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Dangling comments
|
||||
def test(
|
||||
# comment
|
||||
# another
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Argument empty line spacing
|
||||
def test(
|
||||
# comment
|
||||
a,
|
||||
# another
|
||||
b,
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
### Different function argument wrappings
|
||||
|
||||
def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc):
|
||||
pass
|
||||
|
||||
|
||||
def arguments_on_their_own_line(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def argument_per_line(
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
||||
bbbbbbbbbbbbbbb,
|
||||
ccccccccccccccccc,
|
||||
ddddddddddddd,
|
||||
eeeeeeeeeeeeeeee,
|
||||
ffffffffffff,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def last_pos_only_trailing_comma(
|
||||
a,
|
||||
b,
|
||||
/,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def last_pos_no_trailing_comma(a, b, /):
|
||||
pass
|
||||
|
||||
|
||||
def varg_with_leading_comments(
|
||||
a,
|
||||
b,
|
||||
# comment
|
||||
*args,
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def kwarg_with_leading_comments(
|
||||
a,
|
||||
b,
|
||||
# comment
|
||||
**kwargs,
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def argument_with_long_default(
|
||||
a,
|
||||
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
||||
h=[],
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def argument_with_long_type_annotation(
|
||||
a,
|
||||
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||
h=[],
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
def test():
|
||||
...
|
||||
|
||||
|
||||
# Comment
|
||||
def with_leading_comment():
|
||||
...
|
||||
|
||||
|
||||
# Comment that could be mistaken for a trailing comment of the function declaration when
|
||||
# looking from the position of the if
|
||||
# Regression test for https://github.com/python/cpython/blob/ad56340b665c5d8ac1f318964f71697bba41acb7/Lib/logging/__init__.py#L253-L260
|
||||
if True:
|
||||
def f1():
|
||||
pass # a
|
||||
else:
|
||||
pass
|
||||
|
||||
# Here it's actually a trailing comment
|
||||
if True:
|
||||
def f2():
|
||||
pass
|
||||
# a
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
# Make sure the star is printed
|
||||
# Regression test for https://github.com/python/cpython/blob/7199584ac8632eab57612f595a7162ab8d2ebbc0/Lib/warnings.py#L513
|
||||
def f(arg1=1, *, kwonlyarg1, kwonlyarg2=2):
|
||||
pass
|
||||
|
||||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/5176#issuecomment-1598171989
|
||||
def foo(
|
||||
b=3 + 2, # comment
|
||||
):
|
||||
...
|
||||
|
||||
|
||||
# Comments on the slash or the star, both of which don't have a node
|
||||
def f11(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f12(
|
||||
a=1,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b=2,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f13(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f21(
|
||||
a=1,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
b=2,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f22(
|
||||
a,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f23(
|
||||
a,
|
||||
# keyword only comment, leading
|
||||
*args, # keyword only comment, trailing
|
||||
b,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f24(
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
a,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f31(
|
||||
a=1,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b=2,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c=3,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f32(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
b,
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f33(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
# keyword only comment, leading
|
||||
*args, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f34(
|
||||
a,
|
||||
# positional only comment, leading
|
||||
/, # positional only comment, trailing
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def f35(
|
||||
# keyword only comment, leading
|
||||
*, # keyword only comment, trailing
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# Multiple trailing comments
|
||||
def f41(
|
||||
a,
|
||||
/, # 1 # 2
|
||||
# 3
|
||||
*, # 4 # 5
|
||||
c,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
# Multiple trailing comments strangely places. The goal here is only stable formatting,
|
||||
# the comments are placed to strangely to keep their relative position intact
|
||||
def f42(
|
||||
a,
|
||||
/, # 1
|
||||
# 2
|
||||
# 3
|
||||
# 4
|
||||
*, # 5 # 7
|
||||
# 6
|
||||
c,
|
||||
):
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
if x == y: # trailing if condition
|
||||
pass # trailing `pass` comment
|
||||
# Root `if` trailing comment
|
||||
|
||||
# Leading elif comment
|
||||
elif x < y: # trailing elif condition
|
||||
pass
|
||||
# `elif` trailing comment
|
||||
|
||||
# Leading else comment
|
||||
else: # trailing else condition
|
||||
pass
|
||||
# `else` trailing comment
|
||||
|
||||
|
||||
if x == y:
|
||||
if y == z:
|
||||
...
|
||||
|
||||
if a == b:
|
||||
...
|
||||
else: # trailing comment
|
||||
...
|
||||
|
||||
# trailing else comment
|
||||
|
||||
# leading else if comment
|
||||
elif aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + [
|
||||
11111111111111111111111111,
|
||||
2222222222222222222222,
|
||||
3333333333
|
||||
]:
|
||||
...
|
||||
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
# Regression test: Don't drop the trailing comment by associating it with the elif
|
||||
# instead of the else.
|
||||
# Originally found in https://github.com/python/cpython/blob/ab3823a97bdeefb0266b3c8d493f7f6223ce3686/Lib/dataclasses.py#L539
|
||||
|
||||
if "if 1":
|
||||
pass
|
||||
elif "elif 1":
|
||||
pass
|
||||
# Don't drop this comment 1
|
||||
x = 1
|
||||
|
||||
if "if 2":
|
||||
pass
|
||||
elif "elif 2":
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
# Don't drop this comment 2
|
||||
x = 2
|
||||
|
||||
if "if 3":
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
# Don't drop this comment 3
|
||||
x = 3
|
||||
|
||||
# Regression test for a following if that could get confused for an elif
|
||||
# Originally found in https://github.com/gradio-app/gradio/blob/1570b94a02d23d051ae137e0063974fd8a48b34e/gradio/external.py#L478
|
||||
if True:
|
||||
pass
|
||||
else: # Comment
|
||||
if False:
|
||||
pass
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if x == y: # trailing if condition
|
||||
pass # trailing `pass` comment
|
||||
# Root `if` trailing comment
|
||||
|
||||
# Leading elif comment
|
||||
elif x < y: # trailing elif condition
|
||||
pass
|
||||
# `elif` trailing comment
|
||||
|
||||
# Leading else comment
|
||||
else: # trailing else condition
|
||||
pass
|
||||
# `else` trailing comment
|
||||
|
||||
|
||||
if x == y:
|
||||
if y == z:
|
||||
...
|
||||
|
||||
if a == b:
|
||||
...
|
||||
else: # trailing comment
|
||||
...
|
||||
|
||||
# trailing else comment
|
||||
|
||||
# leading else if comment
|
||||
elif aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + [
|
||||
11111111111111111111111111,
|
||||
2222222222222222222222,
|
||||
3333333333,
|
||||
]:
|
||||
...
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
# Regression test: Don't drop the trailing comment by associating it with the elif
|
||||
# instead of the else.
|
||||
# Originally found in https://github.com/python/cpython/blob/ab3823a97bdeefb0266b3c8d493f7f6223ce3686/Lib/dataclasses.py#L539
|
||||
|
||||
if "if 1":
|
||||
pass
|
||||
elif "elif 1":
|
||||
pass
|
||||
# Don't drop this comment 1
|
||||
x = 1
|
||||
|
||||
if "if 2":
|
||||
pass
|
||||
elif "elif 2":
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
# Don't drop this comment 2
|
||||
x = 2
|
||||
|
||||
if "if 3":
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
# Don't drop this comment 3
|
||||
x = 3
|
||||
|
||||
# Regression test for a following if that could get confused for an elif
|
||||
# Originally found in https://github.com/gradio-app/gradio/blob/1570b94a02d23d051ae137e0063974fd8a48b34e/gradio/external.py#L478
|
||||
if True:
|
||||
pass
|
||||
else: # Comment
|
||||
if False:
|
||||
pass
|
||||
pass
|
||||
```
|
||||
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
while 34: # trailing test comment
|
||||
pass # trailing last statement comment
|
||||
|
||||
# trailing while body comment
|
||||
|
||||
# leading else comment
|
||||
|
||||
else: # trailing else comment
|
||||
pass
|
||||
|
||||
# trailing else body comment
|
||||
|
||||
|
||||
while aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn: # trailing comment
|
||||
pass
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
while (
|
||||
some_condition(unformatted, args) and anotherCondition or aThirdCondition
|
||||
): # comment
|
||||
print("Do something")
|
||||
|
||||
|
||||
while (
|
||||
some_condition(unformatted, args) # trailing some condition
|
||||
and anotherCondition or aThirdCondition # trailing third condition
|
||||
): # comment
|
||||
print("Do something")
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
while 34: # trailing test comment
|
||||
pass # trailing last statement comment
|
||||
|
||||
# trailing while body comment
|
||||
|
||||
# leading else comment
|
||||
|
||||
else: # trailing else comment
|
||||
pass
|
||||
|
||||
# trailing else body comment
|
||||
|
||||
|
||||
while (
|
||||
aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
|
||||
): # trailing comment
|
||||
pass
|
||||
|
||||
else:
|
||||
...
|
||||
|
||||
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and anotherCondition or aThirdCondition: # comment
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
|
||||
|
||||
while (
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # trailing some condition
|
||||
and anotherCondition
|
||||
or aThirdCondition # trailing third condition
|
||||
): # comment
|
||||
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
|
||||
```
|
||||
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
|
||||
# Removes the line above
|
||||
|
||||
a = 10 # Keeps the line above
|
||||
|
||||
# Separated by one line from `a` and `b`
|
||||
|
||||
b = 20
|
||||
# Adds two lines after `b`
|
||||
class Test:
|
||||
def a(self):
|
||||
pass
|
||||
# trailing comment
|
||||
|
||||
# two lines before, one line after
|
||||
|
||||
c = 30
|
||||
|
||||
while a == 10:
|
||||
...
|
||||
|
||||
# trailing comment with one line before
|
||||
|
||||
# one line before this leading comment
|
||||
|
||||
d = 40
|
||||
|
||||
while b == 20:
|
||||
...
|
||||
# no empty line before
|
||||
|
||||
e = 50 # one empty line before
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Removes the line above
|
||||
|
||||
a = 10 # Keeps the line above
|
||||
|
||||
# Separated by one line from `a` and `b`
|
||||
|
||||
b = 20
|
||||
|
||||
|
||||
# Adds two lines after `b`
|
||||
class Test:
|
||||
def a(self):
|
||||
pass
|
||||
# trailing comment
|
||||
|
||||
|
||||
# two lines before, one line after
|
||||
|
||||
c = 30
|
||||
|
||||
while a == 10:
|
||||
...
|
||||
|
||||
# trailing comment with one line before
|
||||
|
||||
# one line before this leading comment
|
||||
|
||||
d = 40
|
||||
|
||||
while b == 20:
|
||||
...
|
||||
# no empty line before
|
||||
|
||||
e = 50 # one empty line before
|
||||
```
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue