Compare commits

..

1 Commits

Author SHA1 Message Date
Charlie Marsh
8fbec8e6a2 Update docs to match updated logo and color palette 2023-06-21 20:48:29 -04:00
106 changed files with 1017 additions and 1565 deletions

View File

@@ -491,16 +491,16 @@ jobs:
- name: "Publish to GitHub"
uses: softprops/action-gh-release@v1
with:
draft: true
draft: false
files: binaries/*
tag_name: v${{ inputs.tag }}
# After the release has been published, we update downstream repositories
# This is separate because if this fails the release is still fine, we just need to do some manual workflow triggers
update-dependents:
name: Update dependents
name: Release
runs-on: ubuntu-latest
needs: publish-release
needs: release
steps:
- name: "Update pre-commit mirror"
uses: actions/github-script@v6

18
Cargo.lock generated
View File

@@ -733,7 +733,7 @@ dependencies = [
[[package]]
name = "flake8-to-ruff"
version = "0.0.275"
version = "0.0.274"
dependencies = [
"anyhow",
"clap",
@@ -1793,7 +1793,7 @@ dependencies = [
[[package]]
name = "ruff"
version = "0.0.275"
version = "0.0.274"
dependencies = [
"annotate-snippets 0.9.1",
"anyhow",
@@ -1889,7 +1889,7 @@ dependencies = [
[[package]]
name = "ruff_cli"
version = "0.0.275"
version = "0.0.274"
dependencies = [
"annotate-snippets 0.9.1",
"anyhow",
@@ -2105,7 +2105,7 @@ dependencies = [
[[package]]
name = "ruff_text_size"
version = "0.0.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"schemars",
"serde",
@@ -2183,7 +2183,7 @@ dependencies = [
[[package]]
name = "rustpython-ast"
version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"is-macro",
"num-bigint",
@@ -2194,7 +2194,7 @@ dependencies = [
[[package]]
name = "rustpython-format"
version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"bitflags 2.3.1",
"itertools",
@@ -2206,7 +2206,7 @@ dependencies = [
[[package]]
name = "rustpython-literal"
version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"hexf-parse",
"is-macro",
@@ -2218,7 +2218,7 @@ dependencies = [
[[package]]
name = "rustpython-parser"
version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"anyhow",
"is-macro",
@@ -2241,7 +2241,7 @@ dependencies = [
[[package]]
name = "rustpython-parser-core"
version = "0.2.0"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=f60e204b73b95bdb6ce87ccd0de34081b4a17c11#f60e204b73b95bdb6ce87ccd0de34081b4a17c11"
source = "git+https://github.com/astral-sh/RustPython-Parser.git?rev=08ebbe40d7776cac6e3ba66277d435056f2b8dca#08ebbe40d7776cac6e3ba66277d435056f2b8dca"
dependencies = [
"is-macro",
"memchr",

View File

@@ -50,15 +50,15 @@ toml = { version = "0.7.2" }
# v0.0.1
libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "80e4c1399f95e5beb532fdd1e209ad2dbb470438" }
# v0.0.3
ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" }
ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "08ebbe40d7776cac6e3ba66277d435056f2b8dca" }
# v0.0.3
rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" , default-features = false, features = ["all-nodes-with-ranges", "num-bigint"]}
rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "08ebbe40d7776cac6e3ba66277d435056f2b8dca" , default-features = false, features = ["all-nodes-with-ranges", "num-bigint"]}
# v0.0.3
rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11", default-features = false, features = ["num-bigint"] }
rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "08ebbe40d7776cac6e3ba66277d435056f2b8dca", default-features = false, features = ["num-bigint"] }
# v0.0.3
rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11", default-features = false }
rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "08ebbe40d7776cac6e3ba66277d435056f2b8dca", default-features = false }
# v0.0.3
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "f60e204b73b95bdb6ce87ccd0de34081b4a17c11" , default-features = false, features = ["full-lexer", "all-nodes-with-ranges", "num-bigint"] }
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "08ebbe40d7776cac6e3ba66277d435056f2b8dca" , default-features = false, features = ["full-lexer", "all-nodes-with-ranges", "num-bigint"] }
[profile.release]
lto = "fat"

View File

@@ -139,7 +139,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com) hook:
```yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.275
rev: v0.0.274
hooks:
- id: ruff
```

View File

@@ -1,6 +1,6 @@
[package]
name = "flake8-to-ruff"
version = "0.0.275"
version = "0.0.274"
description = """
Convert Flake8 configuration files to Ruff configuration files.
"""

View File

@@ -1,6 +1,6 @@
[package]
name = "ruff"
version = "0.0.275"
version = "0.0.274"
publish = false
authors = { workspace = true }
edition = { workspace = true }

View File

@@ -48,12 +48,3 @@ if True: from collections import (
# OK
from a import b
# Ok: `typing_extensions` contains backported improvements.
from typing_extensions import SupportsIndex
# Ok: `typing_extensions` contains backported improvements.
from typing_extensions import NamedTuple
# Ok: `typing_extensions` supports `frozen_default` (backported from 3.12).
from typing_extensions import dataclass_transform

View File

@@ -445,7 +445,7 @@ impl Notebook {
}
#[cfg(test)]
mod tests {
mod test {
use std::path::Path;
use anyhow::Result;

View File

@@ -6,7 +6,7 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of comparators other than `<` and `>=` for
/// Checks for usages of comparators other than `<` and `>=` for
/// `sys.version_info` checks in `.pyi` files. All other comparators, such
/// as `>`, `<=`, and `==`, are banned.
///

View File

@@ -7,7 +7,7 @@ use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of the builtin `open()` function without an associated context
/// Checks for usages of the builtin `open()` function without an associated context
/// manager.
///
/// ## Why is this bad?

View File

@@ -108,7 +108,8 @@ pub(crate) fn invalid_escape_sequence(
let range = TextRange::at(location, next_char.text_len() + TextSize::from(1));
let mut diagnostic = Diagnostic::new(InvalidEscapeSequence(*next_char), range);
if autofix {
diagnostic.set_fix(Fix::automatic(Edit::insertion(
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
r"\".to_string(),
range.start() + TextSize::from(1),
)));

View File

@@ -92,7 +92,8 @@ pub(crate) fn missing_whitespace(
let mut diagnostic = Diagnostic::new(kind, token.range());
if autofix {
diagnostic.set_fix(Fix::automatic(Edit::insertion(
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
" ".to_string(),
token.end(),
)));

View File

@@ -65,7 +65,8 @@ pub(crate) fn whitespace_before_parameters(
let mut diagnostic = Diagnostic::new(kind, TextRange::new(start, end));
if autofix {
diagnostic.set_fix(Fix::automatic(Edit::deletion(start, end)));
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(start, end)));
}
context.push_diagnostic(diagnostic);
}

View File

@@ -55,7 +55,8 @@ pub(crate) fn no_newline_at_end_of_file(
let mut diagnostic = Diagnostic::new(MissingNewlineAtEndOfFile, range);
if autofix {
diagnostic.set_fix(Fix::automatic(Edit::insertion(
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
stylist.line_ending().to_string(),
range.start(),
)));

View File

@@ -11,7 +11,7 @@ E21.py:2:5: E211 [*] Whitespace before '('
|
= help: Removed whitespace before '('
Fix
Suggested fix
1 1 | #: E211
2 |-spam (1)
2 |+spam(1)
@@ -30,7 +30,7 @@ E21.py:4:5: E211 [*] Whitespace before '['
|
= help: Removed whitespace before '['
Fix
Suggested fix
1 1 | #: E211
2 2 | spam (1)
3 3 | #: E211 E211
@@ -51,7 +51,7 @@ E21.py:4:20: E211 [*] Whitespace before '['
|
= help: Removed whitespace before '['
Fix
Suggested fix
1 1 | #: E211
2 2 | spam (1)
3 3 | #: E211 E211
@@ -72,7 +72,7 @@ E21.py:6:12: E211 [*] Whitespace before '['
|
= help: Removed whitespace before '['
Fix
Suggested fix
3 3 | #: E211 E211
4 4 | dict ['key'] = list [index]
5 5 | #: E211

View File

@@ -11,7 +11,7 @@ E23.py:2:7: E231 [*] Missing whitespace after ','
|
= help: Added missing whitespace after ','
Fix
Suggested fix
1 1 | #: E231
2 |-a = (1,2)
2 |+a = (1, 2)
@@ -30,7 +30,7 @@ E23.py:4:5: E231 [*] Missing whitespace after ','
|
= help: Added missing whitespace after ','
Fix
Suggested fix
1 1 | #: E231
2 2 | a = (1,2)
3 3 | #: E231
@@ -51,7 +51,7 @@ E23.py:6:10: E231 [*] Missing whitespace after ':'
|
= help: Added missing whitespace after ':'
Fix
Suggested fix
3 3 | #: E231
4 4 | a[b1,:]
5 5 | #: E231
@@ -71,7 +71,7 @@ E23.py:19:10: E231 [*] Missing whitespace after ','
|
= help: Added missing whitespace after ','
Fix
Suggested fix
16 16 |
17 17 | def foo() -> None:
18 18 | #: E231
@@ -91,7 +91,7 @@ E23.py:29:20: E231 [*] Missing whitespace after ':'
|
= help: Added missing whitespace after ':'
Fix
Suggested fix
26 26 | #: E231:2:20
27 27 | mdtypes_template = {
28 28 | 'tag_full': [('mdtype', 'u4'), ('byte_count', 'u4')],

View File

@@ -9,7 +9,7 @@ W292_0.py:2:9: W292 [*] No newline at end of file
|
= help: Add trailing newline
Fix
Suggested fix
1 1 | def fn() -> None:
2 |- pass
2 |+ pass

View File

@@ -11,7 +11,7 @@ W605_0.py:2:10: W605 [*] Invalid escape sequence: `\.`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
1 1 | #: W605:1:10
2 |-regex = '\.png$'
2 |+regex = '\\.png$'
@@ -29,7 +29,7 @@ W605_0.py:6:1: W605 [*] Invalid escape sequence: `\.`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
3 3 |
4 4 | #: W605:2:1
5 5 | regex = '''
@@ -49,7 +49,7 @@ W605_0.py:11:6: W605 [*] Invalid escape sequence: `\_`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
8 8 |
9 9 | #: W605:2:6
10 10 | f(
@@ -70,7 +70,7 @@ W605_0.py:18:6: W605 [*] Invalid escape sequence: `\_`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
15 15 | """
16 16 | multi-line
17 17 | literal

View File

@@ -11,7 +11,7 @@ W605_1.py:2:10: W605 [*] Invalid escape sequence: `\.`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
1 1 | #: W605:1:10
2 |-regex = '\.png$'
2 |+regex = '\\.png$'
@@ -29,7 +29,7 @@ W605_1.py:6:1: W605 [*] Invalid escape sequence: `\.`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
3 3 |
4 4 | #: W605:2:1
5 5 | regex = '''
@@ -49,7 +49,7 @@ W605_1.py:11:6: W605 [*] Invalid escape sequence: `\_`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
8 8 |
9 9 | #: W605:2:6
10 10 | f(
@@ -70,7 +70,7 @@ W605_1.py:18:6: W605 [*] Invalid escape sequence: `\_`
|
= help: Add backslash to escape sequence
Fix
Suggested fix
15 15 | """
16 16 | multi-line
17 17 | literal

View File

@@ -8,7 +8,7 @@ W292_4.py:1:2: W292 [*] No newline at end of file
|
= help: Add trailing newline
Fix
Suggested fix
1 |-
1 |+

View File

@@ -6,7 +6,7 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of the builtin `eval()` function.
/// Checks for usages of the builtin `eval()` function.
///
/// ## Why is this bad?
/// The `eval()` function is insecure as it enables arbitrary code execution.

View File

@@ -6,7 +6,7 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of `await` outside of `async` functions.
/// Checks for usages of `await` outside of `async` functions.
///
/// ## Why is this bad?
/// Using `await` outside of an `async` function is a syntax error.

View File

@@ -7,7 +7,7 @@ use ruff_python_ast::source_code::OneIndexed;
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of names that are declared as `global` prior to the
/// Checks for usages of names that are declared as `global` prior to the
/// relevant `global` declaration.
///
/// ## Why is this bad?

View File

@@ -6,7 +6,7 @@ use ruff_macros::{derive_message_formats, violation};
use crate::checkers::ast::Checker;
/// ## What it does
/// Checks for uses of named expressions (e.g., `a := 42`) that can be
/// Checks for usages of named expressions (e.g., `a := 42`) that can be
/// replaced by regular assignment statements (e.g., `a = 42`).
///
/// ## Why is this bad?

View File

@@ -126,7 +126,7 @@ pub(crate) fn remove_import_members(contents: &str, members: &[&str]) -> String
}
#[cfg(test)]
mod tests {
mod test {
use crate::rules::pyupgrade::fixes::remove_import_members;
#[test]

View File

@@ -43,12 +43,6 @@ enum Deprecation {
/// Deprecated imports may be removed in future versions of Python, and
/// should be replaced with their new equivalents.
///
/// Note that, in some cases, it may be preferable to continue importing
/// members from `typing_extensions` even after they're added to the Python
/// standard library, as `typing_extensions` can backport bugfixes and
/// optimizations from later Python versions. This rule thus avoids flagging
/// imports from `typing_extensions` in such cases.
///
/// ## Example
/// ```python
/// from collections import Sequence
@@ -145,12 +139,10 @@ const TYPING_EXTENSIONS_TO_TYPING: &[&str] = &[
"ContextManager",
"Coroutine",
"DefaultDict",
"NewType",
"TYPE_CHECKING",
"Text",
"Type",
// Introduced in Python 3.5.2, but `typing_extensions` contains backported bugfixes and
// optimizations,
// "NewType",
];
// Python 3.7+
@@ -176,13 +168,11 @@ const MYPY_EXTENSIONS_TO_TYPING_38: &[&str] = &["TypedDict"];
// Members of `typing_extensions` that were moved to `typing`.
const TYPING_EXTENSIONS_TO_TYPING_38: &[&str] = &[
"Final",
"Literal",
"OrderedDict",
"Protocol",
"SupportsIndex",
"runtime_checkable",
// Introduced in Python 3.8, but `typing_extensions` contains backported bugfixes and
// optimizations.
// "Literal",
// "Protocol",
// "SupportsIndex",
];
// Python 3.9+
@@ -253,8 +243,6 @@ const TYPING_TO_COLLECTIONS_ABC_310: &[&str] = &["Callable"];
// Members of `typing_extensions` that were moved to `typing`.
const TYPING_EXTENSIONS_TO_TYPING_310: &[&str] = &[
"Concatenate",
"Literal",
"NewType",
"ParamSpecArgs",
"ParamSpecKwargs",
"TypeAlias",
@@ -270,19 +258,21 @@ const TYPING_EXTENSIONS_TO_TYPING_310: &[&str] = &[
const TYPING_EXTENSIONS_TO_TYPING_311: &[&str] = &[
"Any",
"LiteralString",
"NamedTuple",
"Never",
"NotRequired",
"Required",
"Self",
"TypedDict",
"Unpack",
"assert_never",
"assert_type",
"clear_overloads",
"dataclass_transform",
"final",
"get_overloads",
"overload",
"reveal_type",
// Introduced in Python 3.11, but `typing_extensions` backports the `frozen_default` argument.
// "dataclass_transform",
];
struct ImportReplacer<'a> {

View File

@@ -477,7 +477,7 @@ pub(crate) fn printf_string_formatting(
}
#[cfg(test)]
mod tests {
mod test {
use test_case::test_case;
use super::*;

View File

@@ -1,6 +1,6 @@
[package]
name = "ruff_cli"
version = "0.0.275"
version = "0.0.274"
publish = false
authors = { workspace = true }
edition = { workspace = true }

View File

@@ -299,7 +299,7 @@ pub(crate) fn init(path: &Path) -> Result<()> {
}
#[cfg(test)]
mod tests {
mod test {
use std::env::temp_dir;
use std::fs;
use std::io::{self, Write};

View File

@@ -346,7 +346,7 @@ pub(crate) fn lint_stdin(
}
#[cfg(test)]
mod tests {
mod test {
use std::path::Path;
use crate::diagnostics::{load_jupyter_notebook, Diagnostics};

View File

@@ -42,9 +42,6 @@ pub(crate) struct Args {
/// Print only the first error and exit, `-x` is same as pytest
#[arg(long, short = 'x')]
pub(crate) exit_first_error: bool,
/// Checks each project inside a directory
#[arg(long)]
pub(crate) multi_project: bool,
}
/// Generate ourself a `try_parse_from` impl for `CheckArgs`. This is a strange way to use clap but
@@ -57,35 +54,6 @@ struct WrapperArgs {
}
pub(crate) fn main(args: &Args) -> anyhow::Result<ExitCode> {
let all_success = if args.multi_project {
let mut all_success = true;
for base_dir in &args.files {
for dir in base_dir.read_dir()? {
let dir = dir?;
println!("Starting {}", dir.path().display());
let success = check_repo(&Args {
files: vec![dir.path().clone()],
..*args
});
println!("Finished {}: {:?}", dir.path().display(), success);
if !matches!(success, Ok(true)) {
all_success = false;
}
}
}
all_success
} else {
check_repo(args)?
};
if all_success {
Ok(ExitCode::SUCCESS)
} else {
Ok(ExitCode::FAILURE)
}
}
/// Returns whether the check was successful
pub(crate) fn check_repo(args: &Args) -> anyhow::Result<bool> {
let start = Instant::now();
// Find files to check (or in this case, format twice). Adapted from ruff_cli
@@ -109,20 +77,13 @@ pub(crate) fn check_repo(args: &Args) -> anyhow::Result<bool> {
let (paths, _resolver) = python_files_in_path(&cli.files, &pyproject_config, &overrides)?;
assert!(!paths.is_empty(), "no python files in {:?}", cli.files);
let mut formatted_counter = 0;
let errors = paths
.into_iter()
.map(|dir_entry| {
// Doesn't make sense to recover here in this test script
dir_entry.expect("Iterating the files in the repository failed")
})
.filter(|dir_entry| {
// For some reason it does not filter in the beginning
dir_entry.file_name() != "pyproject.toml"
})
.map(|dir_entry| {
let file = dir_entry.path().to_path_buf();
formatted_counter += 1;
let file = dir_entry
.expect("Iterating the files in the repository failed")
.into_path();
// Handle panics (mostly in `debug_assert!`)
let result = match catch_unwind(|| check_file(&file)) {
Ok(result) => result,
@@ -205,20 +166,20 @@ Formatted twice:
}
if args.exit_first_error {
return Ok(false);
return Ok(ExitCode::FAILURE);
}
}
let duration = start.elapsed();
println!(
"Formatting {} files twice took {:.2}s",
formatted_counter,
cli.files.len(),
duration.as_secs_f32()
);
if any_errors {
Ok(false)
Ok(ExitCode::FAILURE)
} else {
Ok(true)
Ok(ExitCode::SUCCESS)
}
}

View File

@@ -119,7 +119,7 @@ fn check_help_text() -> String {
}
#[cfg(test)]
mod tests {
mod test {
use anyhow::Result;
use crate::generate_all::Mode;

View File

@@ -53,7 +53,7 @@ pub(crate) fn main(args: &Args) -> Result<()> {
}
#[cfg(test)]
mod tests {
mod test {
use anyhow::Result;
use std::env;

View File

@@ -48,11 +48,3 @@ mapping = {
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,
}

View File

@@ -1,36 +0,0 @@
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

View File

@@ -582,12 +582,6 @@ fn handle_trailing_end_of_line_condition_comment<'a>(
.as_deref()
.map(AnyNodeRef::from)
.or_else(|| Some(AnyNodeRef::from(args.as_ref()))),
AnyNodeRef::StmtClassDef(StmtClassDef {
bases, keywords, ..
}) => keywords
.last()
.map(AnyNodeRef::from)
.or_else(|| bases.last().map(AnyNodeRef::from)),
_ => None,
};
@@ -628,13 +622,8 @@ fn handle_trailing_end_of_line_condition_comment<'a>(
TokenKind::RParen => {
// Skip over any closing parentheses
}
TokenKind::Comma => {
// Skip over any trailing comma
}
kind => {
unreachable!(
"Only ')' or ':' should follow the condition but encountered {kind:?}"
)
_ => {
unreachable!("Only ')' or ':' should follow the condition")
}
}
}
@@ -991,22 +980,14 @@ fn handle_dict_unpacking_comment<'a>(
.skip_trivia();
// we start from the preceding node but we skip its token
for token in tokens.by_ref() {
// Skip closing parentheses that are not part of the node range
if token.kind == TokenKind::RParen {
continue;
}
debug_assert!(
matches!(
token,
Token {
kind: TokenKind::LBrace | TokenKind::Comma | TokenKind::Colon,
..
}
),
"{token:?}",
);
break;
if let Some(first) = tokens.next() {
debug_assert!(matches!(
first,
Token {
kind: TokenKind::LBrace | TokenKind::Comma | TokenKind::Colon,
..
}
));
}
// if the remaining tokens from the previous node is exactly `**`,

View File

@@ -10,20 +10,11 @@ use rustpython_parser::ast::ExprCall;
pub struct FormatExprCall;
impl FormatNodeRule<ExprCall> for FormatExprCall {
fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> {
if item.args.is_empty() && item.keywords.is_empty() {
write!(
f,
[not_yet_implemented_custom_text("NOT_IMPLEMENTED_call()")]
)
} else {
write!(
f,
[not_yet_implemented_custom_text(
"NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)"
)]
)
}
fn fmt_fields(&self, _item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> {
write!(
f,
[not_yet_implemented_custom_text("NOT_IMPLEMENTED_call()")]
)
}
}

View File

@@ -26,8 +26,6 @@ pub(super) fn default_expression_needs_parentheses(
#[allow(clippy::if_same_then_else)]
if parenthesize.is_always() {
Parentheses::Always
} else if parenthesize.is_never() {
Parentheses::Never
}
// `Optional` or `Preserve` and expression has parentheses in source code.
else if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) {
@@ -60,11 +58,7 @@ pub enum Parenthesize {
/// Parenthesizes the expression only if it doesn't fit on a line.
IfBreaks,
/// Always adds parentheses
Always,
/// Never adds parentheses. Parentheses are handled by the caller.
Never,
}
impl Parenthesize {
@@ -72,10 +66,6 @@ impl Parenthesize {
matches!(self, Parenthesize::Always)
}
pub(crate) const fn is_never(self) -> bool {
matches!(self, Parenthesize::Never)
}
pub(crate) const fn is_if_breaks(self) -> bool {
matches!(self, Parenthesize::IfBreaks)
}

View File

@@ -247,12 +247,12 @@ mod tests {
let input = r#"
# preceding
if True:
pass
print( "hi" )
# trailing
"#;
let expected = r#"# preceding
if True:
pass
NOT_IMPLEMENTED_call()
# trailing
"#;
let actual = format_module(input)?.as_code().to_string();

View File

@@ -1,6 +1,5 @@
use crate::prelude::*;
use crate::FormatNodeRule;
use ruff_formatter::write;
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::Keyword;
#[derive(Default)]
@@ -8,15 +7,6 @@ pub struct FormatKeyword;
impl FormatNodeRule<Keyword> for FormatKeyword {
fn fmt_fields(&self, item: &Keyword, f: &mut PyFormatter) -> FormatResult<()> {
let Keyword {
range: _,
arg,
value,
} = item;
if let Some(argument) = arg {
write!(f, [argument.format(), text("=")])?;
}
value.format().fmt(f)
write!(f, [not_yet_implemented(item)])
}
}

View File

@@ -62,7 +62,7 @@ y = 100(no)
+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 = NOT_IMPLEMENTED_call()
+x = (0O777).real
@@ -74,7 +74,7 @@ y = 100(no)
y = 100[no]
-y = 100(no)
+y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+y = NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -90,7 +90,7 @@ 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 = NOT_IMPLEMENTED_call()
x = (0O777).real
@@ -101,7 +101,7 @@ if (10).real:
...
y = 100[no]
y = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
y = NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -22,13 +22,13 @@ print("hello, world")
+++ Ruff
@@ -1 +1 @@
-print("hello, world")
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
```
## Ruff Output
```py
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -0,0 +1,135 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py
---
## Input
```py
class SimpleClassWithBlankParentheses():
pass
class ClassWithSpaceParentheses ( ):
first_test_data = 90
second_test_data = 100
def test_func(self):
return None
class ClassWithEmptyFunc(object):
def func_with_blank_parentheses():
return 5
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
class InsideFunc():
pass
class NormalClass (
):
def func_for_testing(self, first, second):
sum = first + second
return sum
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,18 +1,10 @@
-class SimpleClassWithBlankParentheses:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithSpaceParentheses:
- first_test_data = 90
- second_test_data = 100
-
- def test_func(self):
- return None
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithEmptyFunc(object):
- def func_with_blank_parentheses():
- return 5
+NOT_YET_IMPLEMENTED_StmtClassDef
def public_func_with_blank_parentheses():
@@ -20,11 +12,7 @@
def class_under_the_func_with_blank_parentheses():
- class InsideFunc:
- pass
+ NOT_YET_IMPLEMENTED_StmtClassDef
-class NormalClass:
- def func_for_testing(self, first, second):
- sum = first + second
- return sum
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
NOT_YET_IMPLEMENTED_StmtClassDef
NOT_YET_IMPLEMENTED_StmtClassDef
NOT_YET_IMPLEMENTED_StmtClassDef
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
NOT_YET_IMPLEMENTED_StmtClassDef
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output
```py
class SimpleClassWithBlankParentheses:
pass
class ClassWithSpaceParentheses:
first_test_data = 90
second_test_data = 100
def test_func(self):
return None
class ClassWithEmptyFunc(object):
def func_with_blank_parentheses():
return 5
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
class InsideFunc:
pass
class NormalClass:
def func_for_testing(self, first, second):
sum = first + second
return sum
```

View File

@@ -113,257 +113,259 @@ class ClassWithDecoInitAndVarsAndDocstringWithInner2:
```diff
--- Black
+++ Ruff
@@ -7,7 +7,7 @@
@@ -1,165 +1,61 @@
-class ClassSimplest:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithJustTheDocstring:
-class ClassWithSingleField:
- a = 1
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithJustTheDocstring:
- """Just a docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInit:
@@ -16,7 +16,7 @@
-class ClassWithInit:
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithTheDocstringAndInit:
-class ClassWithTheDocstringAndInit:
- """Just a docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
+NOT_YET_IMPLEMENTED_StmtClassDef
def __init__(self):
pass
@@ -30,8 +30,7 @@
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithInitAndVars:
- cls_var = 100
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVarsAndDocstring:
-class ClassWithInitAndVarsAndDocstring:
- """Test class"""
-
+ "NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
+NOT_YET_IMPLEMENTED_StmtClassDef
def __init__(self):
@@ -53,8 +52,7 @@
- cls_var = 100
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsAndDocstring:
-class ClassWithDecoInit:
- @deco
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithDecoInitAndVars:
- cls_var = 100
+NOT_YET_IMPLEMENTED_StmtClassDef
- @deco
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithDecoInitAndVarsAndDocstring:
- """Test class"""
-
+ "NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
@deco
@@ -69,7 +67,7 @@
- cls_var = 100
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassSimplestWithInnerWithDocstring:
class Inner:
- @deco
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassSimplestWithInner:
- class Inner:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassSimplestWithInnerWithDocstring:
- class Inner:
- """Just a docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
def __init__(self):
pass
@@ -83,7 +81,7 @@
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithJustTheDocstringWithInner:
-class ClassWithSingleFieldWithInner:
- a = 1
+NOT_YET_IMPLEMENTED_StmtClassDef
- class Inner:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithJustTheDocstringWithInner:
- """Just a docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
class Inner:
pass
@@ -108,8 +106,7 @@
- class Inner:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVarsAndDocstringWithInner:
-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"""
-
+ "NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
class Inner:
@@ -140,8 +137,7 @@
- cls_var = 100
-
- class Inner:
- pass
-
- def __init__(self):
- pass
-
-
-class ClassWithDecoInitWithInner:
- class Inner:
- pass
-
- @deco
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsAndDocstringWithInner:
-class ClassWithDecoInitAndVarsWithInner:
- cls_var = 100
-
- class Inner:
- pass
-
- @deco
- def __init__(self):
- pass
-
-
-class ClassWithDecoInitAndVarsAndDocstringWithInner:
- """Test class"""
-
+ "NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
class Inner:
@@ -153,7 +149,7 @@
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
- cls_var = 100
-
- class Inner:
- pass
-
- @deco
- def __init__(self):
- pass
-
-
-class ClassWithDecoInitAndVarsAndDocstringWithInner2:
- """Test class"""
+ "NOT_YET_IMPLEMENTED_STRING"
class Inner:
pass
-
- class Inner:
- pass
-
- cls_var = 100
-
- @deco
- def __init__(self):
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
class ClassSimplest:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithSingleField:
a = 1
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithJustTheDocstring:
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInit:
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithTheDocstringAndInit:
"NOT_YET_IMPLEMENTED_STRING"
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVars:
cls_var = 100
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVarsAndDocstring:
"NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInit:
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVars:
cls_var = 100
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsAndDocstring:
"NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassSimplestWithInner:
class Inner:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassSimplestWithInnerWithDocstring:
class Inner:
"NOT_YET_IMPLEMENTED_STRING"
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithSingleFieldWithInner:
a = 1
class Inner:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithJustTheDocstringWithInner:
"NOT_YET_IMPLEMENTED_STRING"
class Inner:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitWithInner:
class Inner:
pass
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithInitAndVarsAndDocstringWithInner:
"NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
class Inner:
pass
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitWithInner:
class Inner:
pass
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsAndDocstringWithInner:
"NOT_YET_IMPLEMENTED_STRING"
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
"NOT_YET_IMPLEMENTED_STRING"
class Inner:
pass
cls_var = 100
@deco
def __init__(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -178,7 +178,7 @@ if True:
division_result_tuple = (6 / 2,)
-print("foo %r", (foo.bar,))
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
if True:
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
@@ -204,9 +204,9 @@ if True:
- "Delay": 5,
- },
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -259,7 +259,7 @@ for (x,) in (1,), (2,), (3,):
[1, 2, 3]
division_result_tuple = (6 / 2,)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
if True:
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
@@ -268,9 +268,9 @@ if True:
)
if True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -243,19 +243,19 @@ instruction()#comment with bad spacing
Cheese,
- Cheese("Wensleydale"),
- SubBytes(b"spam"),
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ NOT_IMPLEMENTED_call(),
+ NOT_IMPLEMENTED_call(),
]
-if "PYTHON" in os.environ:
- add_compiler(compiler_from_env())
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
else:
# for compiler in compilers.values():
# add_compiler(compiler)
- add_compiler(compilers[(7.0, 32)])
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# add_compiler(compilers[(7.1, 64)])
@@ -307,7 +307,7 @@ instruction()#comment with bad spacing
-""",
- arg3=True,
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
############################################################################
@@ -342,14 +342,14 @@ instruction()#comment with bad spacing
- # right
- if element is not None
- ]
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ lcomp = [i for i in []]
+ lcomp2 = [i for i in []]
+ lcomp3 = [i for i in []]
while True:
if False:
continue
@@ -141,24 +111,18 @@
@@ -141,25 +111,13 @@
# and round and round we go
# let's return
@@ -357,7 +357,7 @@ instruction()#comment with bad spacing
- syms.simple_stmt,
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
- )
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ return NOT_IMPLEMENTED_call()
-CONFIG_FILES = (
@@ -370,17 +370,15 @@ instruction()#comment with bad spacing
+CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
class Test:
def _init_host(self, parsed) -> None:
-class Test:
- def _init_host(self, parsed) -> None:
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
+ if (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # type: ignore
+ or not NOT_IMPLEMENTED_call()
+ ):
pass
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
@@ -167,7 +131,7 @@
#######################
@@ -167,7 +125,7 @@
#######################
@@ -436,16 +434,16 @@ not_shareables = [
"NOT_YET_IMPLEMENTED_STRING",
# user-defined types and objects
Cheese,
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
NOT_IMPLEMENTED_call(),
NOT_IMPLEMENTED_call(),
]
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
else:
# for compiler in compilers.values():
# add_compiler(compiler)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# add_compiler(compilers[(7.1, 64)])
@@ -491,11 +489,11 @@ def inline_comments_in_brackets_ruin_everything():
]
# no newline after
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
############################################################################
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
lcomp = [i for i in []]
lcomp2 = [i for i in []]
lcomp3 = [i for i in []]
@@ -507,19 +505,13 @@ def inline_comments_in_brackets_ruin_everything():
# and round and round we go
# let's return
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return NOT_IMPLEMENTED_call()
CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
class Test:
def _init_host(self, parsed) -> None:
if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # type: ignore
or not NOT_IMPLEMENTED_call()
):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
#######################

View File

@@ -80,7 +80,7 @@ def func():
+ 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):
+ if NOT_IMPLEMENTED_call():
embedded = []
for exc in exc_value.exceptions:
- if exc not in _seen:
@@ -98,7 +98,7 @@ def func():
- # This should be left alone (after)
- )
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# everything is fine if the expression isn't nested
- traceback.TracebackException.from_exception(
@@ -110,7 +110,7 @@ def func():
- # shared between sub-exceptions are not omitted
- _seen=set(_seen),
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# %%
@@ -127,14 +127,14 @@ def func():
x = "NOT_YET_IMPLEMENTED_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):
if NOT_IMPLEMENTED_call():
embedded = []
for exc in exc_value.exceptions:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# everything is fine if the expression isn't nested
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# %%

View File

@@ -107,7 +107,7 @@ def foo3(list_a, list_b):
```diff
--- Black
+++ Ruff
@@ -1,94 +1,28 @@
@@ -1,94 +1,22 @@
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
-)
@@ -118,7 +118,7 @@ def foo3(list_a, list_b):
+NOT_YET_IMPLEMENTED_StmtImportFrom
class C:
-class C:
- @pytest.mark.parametrize(
- ("post_data", "message"),
- [
@@ -161,14 +161,12 @@ def foo3(list_a, list_b):
- ),
- ],
- )
+ @NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
def test_fails_invalid_post_data(
self, pyramid_config, db_request, post_data, message
):
- 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)
+NOT_YET_IMPLEMENTED_StmtClassDef
def foo(list_a, list_b):
@@ -197,7 +195,7 @@ def foo3(list_a, list_b):
- )
- .filter(User.xyz.is_(None))
- )
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ return NOT_IMPLEMENTED_call()
def foo3(list_a, list_b):
@@ -208,7 +206,7 @@ def foo3(list_a, list_b):
- 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)
+ NOT_IMPLEMENTED_call()
)
```
@@ -219,13 +217,7 @@ 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)
NOT_YET_IMPLEMENTED_StmtClassDef
def foo(list_a, list_b):
@@ -235,13 +227,13 @@ def foo(list_a, list_b):
def foo2(list_a, list_b):
# Standalone comment reasonably placed.
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return NOT_IMPLEMENTED_call()
def foo3(list_a, list_b):
return (
# Standalone comment but weirdly placed.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
)
```

View File

@@ -99,7 +99,7 @@ if __name__ == "__main__":
# This one is properly standalone now.
-for i in range(100):
+for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+for i in NOT_IMPLEMENTED_call():
# first we do this
- if i % 33 == 0:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
@@ -107,7 +107,7 @@ if __name__ == "__main__":
# then we do this
- print(i)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# and finally we loop around
-with open(some_temp_file) as f:
@@ -132,7 +132,7 @@ if __name__ == "__main__":
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# leading 3
@deco3
def decorated1():
@@ -141,7 +141,7 @@ if __name__ == "__main__":
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# leading function comment
def decorated1():
...
@@ -168,13 +168,13 @@ while True:
# This one is properly standalone now.
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
for i in NOT_IMPLEMENTED_call():
# first we do this
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
break
# then we do this
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# and finally we loop around
NOT_YET_IMPLEMENTED_StmtWith
@@ -196,7 +196,7 @@ def wat():
# leading 1
@deco1
# leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# leading 3
@deco3
def decorated1():
@@ -206,7 +206,7 @@ def decorated1():
# leading 1
@deco1
# leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# leading function comment
def decorated1():
...

View File

@@ -169,12 +169,12 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
- 0.0789,
- a[-1], # type: ignore
- )
+ c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ c = NOT_IMPLEMENTED_call()
- c = call(
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
- )
+ c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ c = NOT_IMPLEMENTED_call()
-result = ( # aaa
@@ -194,10 +194,10 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
- foo,
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
+aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type]
+aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call() # type: ignore[arg-type]
```
## Ruff Output
@@ -292,9 +292,9 @@ def f(
def func(
a=some_list[0], # type: int
): # type: () -> int
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
c = NOT_IMPLEMENTED_call()
c = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
c = NOT_IMPLEMENTED_call()
result = "NOT_YET_IMPLEMENTED_STRING" # aaa
@@ -306,9 +306,9 @@ AAAAAAAAAAAAA = (
+ AAAAAAAAAAAAA
) # type: ignore
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # type: ignore[arg-type]
aaaaaaaaaaaaa, bbbbbbbbb = NOT_IMPLEMENTED_call() # type: ignore[arg-type]
```
## Black Output

View File

@@ -152,43 +152,65 @@ def bar():
```diff
--- Black
+++ Ruff
@@ -44,7 +44,7 @@
@@ -30,8 +30,7 @@
class ClassWithDocstring:
# This comment should be split from the statement above by two lines.
-class MyClass:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
some = statement
@@ -39,17 +38,14 @@
# This should be split from the above by two lines
-class MyClassWithComplexLeadingComments:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
-class ClassWithDocstring:
- """A docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
+NOT_YET_IMPLEMENTED_StmtClassDef
# Leading comment after a class with just a docstring
@@ -59,7 +59,7 @@
-class MyClassAfterAnotherClassWithDocstring:
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
some = statement
@@ -59,7 +55,7 @@
@deco1
# leading 2
# leading 2 extra
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# leading 3
@deco3
# leading 4
@@ -73,7 +73,7 @@
@@ -73,7 +69,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# leading 3 that already has an empty line
@deco3
@@ -88,7 +88,7 @@
@@ -88,7 +84,7 @@
# leading 1
@deco1
# leading 2
-@deco2(with_args=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# leading 3
@deco3
@@ -106,7 +106,6 @@
@@ -106,7 +102,6 @@
# Another leading comment
def another_inline():
pass
@@ -196,7 +218,7 @@ def bar():
else:
# More leading comments
def inline_after_else():
@@ -121,7 +120,6 @@
@@ -121,18 +116,13 @@
# Another leading comment
def another_top_level_quote_inline_inline():
pass
@@ -204,6 +226,18 @@ def bar():
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
+NOT_YET_IMPLEMENTED_StmtClassDef
# Regression test for https://github.com/psf/black/issues/3454.
```
## Ruff Output
@@ -241,8 +275,7 @@ some = statement
# This comment should be split from the statement above by two lines.
class MyClass:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
some = statement
@@ -250,17 +283,14 @@ some = statement
# This should be split from the above by two lines
class MyClassWithComplexLeadingComments:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
class ClassWithDocstring:
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtClassDef
# Leading comment after a class with just a docstring
class MyClassAfterAnotherClassWithDocstring:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
some = statement
@@ -270,7 +300,7 @@ some = statement
@deco1
# leading 2
# leading 2 extra
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# leading 3
@deco3
# leading 4
@@ -284,7 +314,7 @@ some = statement
# leading 1
@deco1
# leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# leading 3 that already has an empty line
@deco3
@@ -299,7 +329,7 @@ some = statement
# leading 1
@deco1
# leading 2
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# leading 3
@deco3
@@ -337,11 +367,7 @@ else:
pass
class MyClass:
# First method has no empty lines between bare class def.
# More comments.
def first_method(self):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
# Regression test for https://github.com/psf/black/issues/3454.

View File

@@ -47,7 +47,7 @@ def function(a:int=42):
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]
+square = NOT_IMPLEMENTED_call() #  type: Optional[Square]
def function(a: int = 42):
@@ -71,7 +71,7 @@ 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]
square = NOT_IMPLEMENTED_call() #  type: Optional[Square]
def function(a: int = 42):

View File

@@ -114,16 +114,16 @@ async def wat():
# Has many lines. Many, many lines.
# Many, many, many lines.
-"""Module docstring.
+"NOT_YET_IMPLEMENTED_STRING"
-
-Possibly also many, many lines.
-"""
+NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImport
+"NOT_YET_IMPLEMENTED_STRING"
-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
@@ -137,7 +137,7 @@ async def wat():
# Some comment before a function.
@@ -30,25 +24,26 @@
@@ -30,67 +24,50 @@
def function(default=None):
@@ -166,43 +166,42 @@ async def wat():
# Explains why we use global state.
-GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
+GLOBAL_STATE = {
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
+}
# Another comment!
@@ -56,7 +51,7 @@
# This time two lines.
class Foo:
-class Foo:
- """Docstring for class Foo. Example from Sphinx docs."""
+ "NOT_YET_IMPLEMENTED_STRING"
#: Doc comment for class attribute Foo.bar.
#: It can have multiple lines.
@@ -65,32 +60,31 @@
flox = 1.5 #: Doc comment for Foo.flox. One line only.
baz = 2
-
- #: 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."""
+ "NOT_YET_IMPLEMENTED_STRING"
def __init__(self):
#: Doc comment for instance attribute qux.
self.qux = 3
self.spam = 4
-
- def __init__(self):
- #: Doc comment for instance attribute qux.
- self.qux = 3
-
- self.spam = 4
- """Docstring for instance attribute spam."""
+ "NOT_YET_IMPLEMENTED_STRING"
+NOT_YET_IMPLEMENTED_StmtClassDef
#' <h1>This is pweave!</h1>
-@fast(really=True)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
async def wat():
# This comment, for some reason \
# contains a trailing backslash.
@@ -212,7 +211,7 @@ async def wat():
# Comment after ending a block.
if result:
- print("A OK", file=sys.stdout)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# Comment between things.
- print()
+ NOT_IMPLEMENTED_call()
@@ -270,9 +269,9 @@ def function(default=None):
# Explains why we use global state.
GLOBAL_STATE = {
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
}
@@ -280,37 +279,20 @@ GLOBAL_STATE = {
# This time two lines.
class Foo:
"NOT_YET_IMPLEMENTED_STRING"
#: 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
"NOT_YET_IMPLEMENTED_STRING"
def __init__(self):
#: Doc comment for instance attribute qux.
self.qux = 3
self.spam = 4
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtClassDef
#' <h1>This is pweave!</h1>
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
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)
NOT_IMPLEMENTED_call()
# Comment between things.
NOT_IMPLEMENTED_call()

View File

@@ -194,9 +194,9 @@ class C:
```diff
--- Black
+++ Ruff
@@ -1,181 +1,46 @@
class C:
def test(self) -> None:
@@ -1,181 +1 @@
-class C:
- def test(self) -> None:
- with patch("black.out", print):
- self.assertEqual(
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
@@ -239,38 +239,23 @@ class C:
- return (
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
- % (test.name, test.filename, lineno, lname, err)
+ NOT_YET_IMPLEMENTED_StmtWith
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ return "NOT_YET_IMPLEMENTED_STRING" % (
+ test.name,
+ test.filename,
+ lineno,
+ lname,
+ err,
)
def omitting_trailers(self) -> None:
- )
-
- 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
]
- 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:
-
- def easy_asserts(self) -> None:
- assert {
- key1: value1,
- key2: value2,
@@ -282,8 +267,7 @@ class C:
- key8: value8,
- key9: value9,
- } == expected, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -295,8 +279,7 @@ class C:
- key8: value8,
- key9: value9,
- }, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -308,9 +291,8 @@ class C:
- key8: value8,
- key9: value9,
- }
+ NOT_YET_IMPLEMENTED_StmtAssert
def tricky_asserts(self) -> None:
-
- def tricky_asserts(self) -> None:
- assert {
- key1: value1,
- key2: value2,
@@ -324,8 +306,7 @@ class C:
- } == 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,
@@ -339,8 +320,7 @@ class C:
- } == 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
- ) == {
@@ -354,8 +334,7 @@ class C:
- key8: value8,
- key9: value9,
- }, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -370,8 +349,7 @@ class C:
- "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 = """\
- %3d 0 LOAD_FAST 1 (x)
- 2 LOAD_CONST 1 (1)
@@ -382,11 +360,8 @@ class C:
- 12 RETURN_VALUE
- """ % (
- _C.__init__.__code__.co_firstlineno + 1,
+ dis_c_instance_method = "NOT_YET_IMPLEMENTED_STRING" % (
+ _C.__init__.__code__.co_firstlineno
+ + 1,
)
- )
-
- assert (
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
- == {
@@ -401,58 +376,13 @@ class C:
- key9: value9,
- }
- )
+ NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
class C:
def test(self) -> None:
NOT_YET_IMPLEMENTED_StmtWith
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return "NOT_YET_IMPLEMENTED_STRING" % (
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 = "NOT_YET_IMPLEMENTED_STRING" % (
_C.__init__.__code__.co_firstlineno
+ 1,
)
NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -194,9 +194,9 @@ class C:
```diff
--- Black
+++ Ruff
@@ -1,181 +1,46 @@
class C:
def test(self) -> None:
@@ -1,181 +1 @@
-class C:
- def test(self) -> None:
- with patch("black.out", print):
- self.assertEqual(
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
@@ -239,38 +239,23 @@ class C:
- return (
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
- % (test.name, test.filename, lineno, lname, err)
+ NOT_YET_IMPLEMENTED_StmtWith
+ xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ return "NOT_YET_IMPLEMENTED_STRING" % (
+ test.name,
+ test.filename,
+ lineno,
+ lname,
+ err,
)
def omitting_trailers(self) -> None:
- )
-
- 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
]
- 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:
-
- def easy_asserts(self) -> None:
- assert {
- key1: value1,
- key2: value2,
@@ -282,8 +267,7 @@ class C:
- key8: value8,
- key9: value9,
- } == expected, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -295,8 +279,7 @@ class C:
- key8: value8,
- key9: value9,
- }, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -308,9 +291,8 @@ class C:
- key8: value8,
- key9: value9,
- }
+ NOT_YET_IMPLEMENTED_StmtAssert
def tricky_asserts(self) -> None:
-
- def tricky_asserts(self) -> None:
- assert {
- key1: value1,
- key2: value2,
@@ -324,8 +306,7 @@ class C:
- } == 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,
@@ -339,8 +320,7 @@ class C:
- } == 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
- ) == {
@@ -354,8 +334,7 @@ class C:
- key8: value8,
- key9: value9,
- }, "Not what we expected"
+ NOT_YET_IMPLEMENTED_StmtAssert
-
- assert expected == {
- key1: value1,
- key2: value2,
@@ -370,8 +349,7 @@ class C:
- "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 = """\
- %3d 0 LOAD_FAST 1 (x)
- 2 LOAD_CONST 1 (1)
@@ -382,11 +360,8 @@ class C:
- 12 RETURN_VALUE
- """ % (
- _C.__init__.__code__.co_firstlineno + 1,
+ dis_c_instance_method = "NOT_YET_IMPLEMENTED_STRING" % (
+ _C.__init__.__code__.co_firstlineno
+ + 1,
)
- )
-
- assert (
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
- == {
@@ -401,58 +376,13 @@ class C:
- key9: value9,
- }
- )
+ NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
class C:
def test(self) -> None:
NOT_YET_IMPLEMENTED_StmtWith
xxxxxxxxxxxxxxxx = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return "NOT_YET_IMPLEMENTED_STRING" % (
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 = "NOT_YET_IMPLEMENTED_STRING" % (
_C.__init__.__code__.co_firstlineno
+ 1,
)
NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -17,12 +17,12 @@ class ClassWithDocstring:
```diff
--- Black
+++ Ruff
@@ -1,4 +1,4 @@
@@ -1,4 +1,3 @@
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
-class ClassWithDocstring:
- """A docstring."""
+ "NOT_YET_IMPLEMENTED_STRING"
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
@@ -30,8 +30,7 @@ class ClassWithDocstring:
```py
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -234,19 +234,18 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
```diff
--- Black
+++ Ruff
@@ -1,219 +1,154 @@
class MyClass:
@@ -1,219 +1,149 @@
-class MyClass:
- """Multiline
- class docstring
- """
+ "NOT_YET_IMPLEMENTED_STRING"
def method(self):
-
- def method(self):
- """Multiline
- method docstring
- """
+ "NOT_YET_IMPLEMENTED_STRING"
pass
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
def foo():
@@ -397,12 +396,12 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
- 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.
+ "NOT_YET_IMPLEMENTED_STRING"
-
- line ends with some tabs
- """
+ "NOT_YET_IMPLEMENTED_STRING"
-
def docstring_with_inline_tabs_and_tab_indentation():
- """hey
-
@@ -495,12 +494,7 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
## Ruff Output
```py
class MyClass:
"NOT_YET_IMPLEMENTED_STRING"
def method(self):
"NOT_YET_IMPLEMENTED_STRING"
pass
NOT_YET_IMPLEMENTED_StmtClassDef
def foo():

View File

@@ -137,7 +137,7 @@ def g():
if not prev:
- prevp = preceding_leaf(p)
- if not prevp or prevp.type in OPENING_BRACKETS:
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ prevp = NOT_IMPLEMENTED_call()
+ if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
return NO
@@ -199,7 +199,7 @@ def g():
prev = leaf.prev_sibling
if not prev:
- prevp = preceding_leaf(p)
+ prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ prevp = NOT_IMPLEMENTED_call()
- if not prevp or prevp.type in OPENING_BRACKETS:
+ if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
@@ -245,7 +245,7 @@ def f():
prev = leaf.prev_sibling
if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
prevp = NOT_IMPLEMENTED_call()
if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
return NO
@@ -283,7 +283,7 @@ def g():
prev = leaf.prev_sibling
if not prev:
prevp = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
prevp = NOT_IMPLEMENTED_call()
if not prevp or NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
# Start of the line or a bracketed expression.

View File

@@ -431,18 +431,18 @@ last_call()
+NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # note: no trailing comma pre-3.6
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call() # note: no trailing comma pre-3.6
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
lukasz.langa.pl
-call.me(maybe)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
(1).real
(1.0).real
....__class__
@@ -454,6 +454,9 @@ last_call()
- int,
- float,
- dict[str, int],
-]
-very_long_variable_name_filters: t.List[
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
+ (
+ str,
+ int,
@@ -461,9 +464,6 @@ last_call()
+ dict[str, int],
+ )
]
-very_long_variable_name_filters: t.List[
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
-]
-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
-)
@@ -494,7 +494,7 @@ last_call()
numpy[0, :]
numpy[:, i]
numpy[0, :2]
@@ -171,62 +158,59 @@
@@ -171,62 +158,58 @@
numpy[1 : c + 1, c]
numpy[-(c + 1) :, d]
numpy[:, l[-2]]
@@ -541,8 +541,7 @@ last_call()
+ "NOT_YET_IMPLEMENTED_STRING": "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING": "NOT_YET_IMPLEMENTED_STRING",
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call()
+ + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
+ "NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call(),
+ "NOT_YET_IMPLEMENTED_STRING": 1,
+ "NOT_YET_IMPLEMENTED_STRING": 1,
**kwargs,
@@ -556,19 +555,16 @@ last_call()
-g = 1, *"ten"
-what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
- vars_to_remove
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+e = NOT_IMPLEMENTED_call()
+f = 1, NOT_YET_IMPLEMENTED_ExprStarred
+g = 1, NOT_YET_IMPLEMENTED_ExprStarred
+what_is_up_with_those_new_coord_names = (
+ (coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ (coord_names + NOT_IMPLEMENTED_call())
+ + NOT_IMPLEMENTED_call()
)
-what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
- vars_to_remove
+what_is_up_with_those_new_coord_names = (
+ (coord_names | NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ - NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
)
-)
-result = (
- session.query(models.Customer.id)
- .filter(
@@ -586,7 +582,10 @@ last_call()
- models.Customer.id.asc(),
- )
- .all()
-)
+what_is_up_with_those_new_coord_names = (
+ (coord_names | NOT_IMPLEMENTED_call())
+ - NOT_IMPLEMENTED_call()
)
-Ø = set()
-authors.łukasz.say_thanks()
+result = NOT_IMPLEMENTED_call()
@@ -596,7 +595,7 @@ last_call()
mapping = {
A: 0.25 * (10.0 / 12),
B: 0.1 * (10.0 / 12),
@@ -236,31 +220,29 @@
@@ -236,31 +219,29 @@
def gen():
@@ -612,7 +611,7 @@ last_call()
async def f():
- await some.complicated[0].call(with_args=(True or (1 is not 1)))
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
-print(*[] or [1])
@@ -623,9 +622,9 @@ last_call()
- force=False
-), "Short message"
-assert parens is TooMany
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_IMPLEMENTED_call()
+NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtAssert
+NOT_YET_IMPLEMENTED_StmtAssert
@@ -641,12 +640,12 @@ last_call()
...
for j in 1 + (2 + 3):
...
@@ -272,28 +254,16 @@
@@ -272,28 +253,16 @@
addr_proto,
addr_canonname,
addr_sockaddr,
-) in socket.getaddrinfo("google.com", "http"):
+) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+) in NOT_IMPLEMENTED_call():
pass
-a = (
- aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
@@ -678,7 +677,7 @@ last_call()
):
return True
if (
@@ -327,13 +297,18 @@
@@ -327,13 +296,18 @@
):
return True
if (
@@ -700,7 +699,7 @@ last_call()
^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
):
return True
@@ -341,7 +316,8 @@
@@ -341,7 +315,8 @@
~aaaaaaaaaaaaaaaa.a
+ aaaaaaaaaaaaaaaa.b
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
@@ -710,7 +709,7 @@ last_call()
^ aaaaaaaaaaaaaaaa.i
<< aaaaaaaaaaaaaaaa.k
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
@@ -366,5 +342,5 @@
@@ -366,5 +341,5 @@
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
@@ -828,17 +827,17 @@ NOT_YET_IMPLEMENTED_ExprSetComp
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # note: no trailing comma pre-3.6
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call() # note: no trailing comma pre-3.6
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
lukasz.langa.pl
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
(1).real
(1.0).real
....__class__
@@ -910,8 +909,7 @@ SomeName
"NOT_YET_IMPLEMENTED_STRING": "NOT_YET_IMPLEMENTED_STRING",
"NOT_YET_IMPLEMENTED_STRING": "NOT_YET_IMPLEMENTED_STRING",
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call(),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg),
"NOT_YET_IMPLEMENTED_STRING": NOT_IMPLEMENTED_call() + NOT_IMPLEMENTED_call(),
"NOT_YET_IMPLEMENTED_STRING": 1,
"NOT_YET_IMPLEMENTED_STRING": 1,
**kwargs,
@@ -920,16 +918,16 @@ a = (1,)
b = (1,)
c = 1
d = (1,) + a + (2,)
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
e = NOT_IMPLEMENTED_call()
f = 1, NOT_YET_IMPLEMENTED_ExprStarred
g = 1, NOT_YET_IMPLEMENTED_ExprStarred
what_is_up_with_those_new_coord_names = (
(coord_names + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
(coord_names + NOT_IMPLEMENTED_call())
+ NOT_IMPLEMENTED_call()
)
what_is_up_with_those_new_coord_names = (
(coord_names | NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
- NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
(coord_names | NOT_IMPLEMENTED_call())
- NOT_IMPLEMENTED_call()
)
result = NOT_IMPLEMENTED_call()
result = NOT_IMPLEMENTED_call()
@@ -951,12 +949,12 @@ def gen():
async def f():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtAssert
NOT_YET_IMPLEMENTED_StmtAssert
@@ -978,7 +976,7 @@ for (
addr_proto,
addr_canonname,
addr_sockaddr,
) in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
) in NOT_IMPLEMENTED_call():
pass
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
a = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right

View File

@@ -73,7 +73,7 @@ def test_calculate_fades():
- ('stuff', 'in')
- ],
-])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
def test_fader(test):
pass
@@ -122,7 +122,7 @@ TmEx = 2
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
def test_fader(test):
pass

View File

@@ -32,7 +32,7 @@ def f(): pass
- 1, 2,
- 3, 4,
-])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
# fmt: on
def f():
pass
@@ -46,7 +46,7 @@ def f(): pass
- 4,
- ]
-)
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
def f():
pass
```
@@ -55,13 +55,13 @@ def f(): pass
```py
# fmt: off
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
# fmt: on
def f():
pass
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
def f():
pass
```

View File

@@ -109,7 +109,7 @@ elif unformatted:
- ] # Includes an formatted indentation.
- },
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
# Regression test for https://github.com/psf/black/issues/2015.
@@ -123,18 +123,18 @@ elif unformatted:
- + path,
- check=True,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
# 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):
+ if NOT_IMPLEMENTED_call():
return True
# yapf: enable
elif b:
@@ -39,12 +21,12 @@
@@ -39,49 +21,29 @@
# Regression test for https://github.com/psf/black/issues/2567.
if True:
# fmt: off
@@ -142,54 +142,50 @@ elif unformatted:
- # fmt: on
- print ( "This won't be formatted" )
- print ( "This won't be formatted either" )
+ for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ for _ in NOT_IMPLEMENTED_call():
+ # fmt: on
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
else:
- print("This will be formatted")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# Regression test for https://github.com/psf/black/issues/3184.
@@ -52,29 +34,27 @@
async def call(param):
if param:
# fmt: off
-class A:
- async def call(param):
- if param:
- # fmt: off
- if param[0:4] in (
- "ABCD", "EFGH"
- ) :
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
# fmt: on
- # 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" )
+ elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
-
- print("This will be formatted")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_YET_IMPLEMENTED_StmtClassDef
# Regression test for https://github.com/psf/black/issues/2985.
class Named(t.Protocol):
# fmt: off
@property
-class Named(t.Protocol):
- # fmt: off
- @property
- def this_wont_be_formatted ( self ) -> str: ...
+ def this_wont_be_formatted(self) -> str:
+ ...
+NOT_YET_IMPLEMENTED_StmtClassDef
class Factory(t.Protocol):
def this_will_be_formatted(self, **kwargs) -> Named:
...
-class Factory(t.Protocol):
- def this_will_be_formatted(self, **kwargs) -> Named:
- ...
-
# fmt: on
- # fmt: on
+NOT_YET_IMPLEMENTED_StmtClassDef
@@ -82,6 +62,6 @@
# Regression test for https://github.com/psf/black/issues/3436.
if x:
return x
# fmt: off
@@ -204,17 +200,17 @@ elif unformatted:
```py
# Regression test for https://github.com/psf/black/issues/3129.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Regression test for https://github.com/psf/black/issues/2015.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Regression test for https://github.com/psf/black/issues/3026.
def test_func():
# yapf: disable
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if NOT_IMPLEMENTED_call():
return True
# yapf: enable
elif b:
@@ -226,41 +222,23 @@ def test_func():
# Regression test for https://github.com/psf/black/issues/2567.
if True:
# fmt: off
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
for _ in NOT_IMPLEMENTED_call():
# fmt: on
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
else:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Regression test for https://github.com/psf/black/issues/3184.
class A:
async def call(param):
if param:
# fmt: off
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
# fmt: on
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_YET_IMPLEMENTED_StmtClassDef
# Regression test for https://github.com/psf/black/issues/2985.
class Named(t.Protocol):
# fmt: off
@property
def this_wont_be_formatted(self) -> str:
...
NOT_YET_IMPLEMENTED_StmtClassDef
class Factory(t.Protocol):
def this_will_be_formatted(self, **kwargs) -> Named:
...
# fmt: on
NOT_YET_IMPLEMENTED_StmtClassDef
# Regression test for https://github.com/psf/black/issues/3436.

View File

@@ -241,10 +241,10 @@ d={'a':1,
+ NOT_YET_IMPLEMENTED_StmtRaise
+ if False:
+ ...
+ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ for i in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call()
+ continue
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ return None
+
+
@@ -255,7 +255,7 @@ d={'a':1,
- await asyncio.sleep(1)
+ "NOT_YET_IMPLEMENTED_STRING"
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
+
+
@asyncio.coroutine
@@ -265,7 +265,7 @@ d={'a':1,
-)
-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)
+@NOT_IMPLEMENTED_call()
+def function_signature_stress_test(
+ number: int,
+ no_annotation=None,
@@ -292,7 +292,7 @@ d={'a':1,
+ h="NOT_YET_IMPLEMENTED_STRING",
+ i="NOT_YET_IMPLEMENTED_STRING",
+):
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ offset = NOT_IMPLEMENTED_call()
+ NOT_YET_IMPLEMENTED_StmtAssert
@@ -312,7 +312,7 @@ d={'a':1,
-def spaces2(result=_core.Value(None)):
+def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
+def spaces2(result=NOT_IMPLEMENTED_call()):
...
@@ -429,7 +429,7 @@ d={'a':1,
- implicit_default=True,
- )
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# fmt: off
- a = (
- unnecessary_bracket()
@@ -460,7 +460,7 @@ d={'a':1,
- re.MULTILINE|re.VERBOSE
- # fmt: on
- )
+ _type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ _type_comment_re = NOT_IMPLEMENTED_call()
def single_literal_yapf_disable():
@@ -496,7 +496,7 @@ d={'a':1,
- # fmt: on
- xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
# fmt: off
-yield 'hello'
+NOT_YET_IMPLEMENTED_ExprYield
@@ -536,21 +536,21 @@ def func_no_args():
NOT_YET_IMPLEMENTED_StmtRaise
if False:
...
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call()
continue
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
return None
async def coroutine(arg, exec=False):
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtAsyncWith
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
@asyncio.coroutine
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
def function_signature_stress_test(
number: int,
no_annotation=None,
@@ -574,7 +574,7 @@ def spaces(
h="NOT_YET_IMPLEMENTED_STRING",
i="NOT_YET_IMPLEMENTED_STRING",
):
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
offset = NOT_IMPLEMENTED_call()
NOT_YET_IMPLEMENTED_StmtAssert
@@ -592,7 +592,7 @@ def spaces_types(
...
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
def spaces2(result=NOT_IMPLEMENTED_call()):
...
@@ -674,11 +674,11 @@ def on_and_off_broken():
def long_lines():
if True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# fmt: off
a = NOT_IMPLEMENTED_call()
# fmt: on
_type_comment_re = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
_type_comment_re = NOT_IMPLEMENTED_call()
def single_literal_yapf_disable():
@@ -686,7 +686,7 @@ def single_literal_yapf_disable():
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# fmt: off
NOT_YET_IMPLEMENTED_ExprYield
# No formatting to the end of the file

View File

@@ -33,10 +33,10 @@ else:
+ and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
):
- print("I'm good!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
else:
- print("I'm bad")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -48,9 +48,9 @@ if (
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right # fmt: skip
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
else:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -18,23 +18,19 @@ class A:
```diff
--- Black
+++ Ruff
@@ -1,5 +1,5 @@
class A:
def f(self):
@@ -1,5 +1 @@
-class A:
- def f(self):
- for line in range(10):
+ for line in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if True:
pass # fmt: skip
- if True:
- pass # fmt: skip
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
class A:
def f(self):
for line in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if True:
pass # fmt: skip
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -75,12 +75,12 @@ async def test_async_with():
```diff
--- Black
+++ Ruff
@@ -1,62 +1,54 @@
@@ -1,62 +1,47 @@
# 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)
+ NOT_IMPLEMENTED_call()
return 0
# Make sure this comment is not removed.
@@ -90,53 +90,48 @@ async def test_async_with():
- 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)
+ NOT_IMPLEMENTED_call()
+ await NOT_IMPLEMENTED_call()
# 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
- return 0
+NOT_YET_IMPLEMENTED_StmtClassDef
- 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)
+if NOT_IMPLEMENTED_call(): # fmt: skip
+ NOT_IMPLEMENTED_call()
# 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)
+elif NOT_IMPLEMENTED_call(): # fmt: skip
+ NOT_IMPLEMENTED_call()
+else: # fmt: skip
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-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)
+while NOT_IMPLEMENTED_call(): # fmt: skip
+ NOT_IMPLEMENTED_call()
-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)
+for i in NOT_IMPLEMENTED_call(): # fmt: skip
+ NOT_IMPLEMENTED_call()
async def test_async_for():
@@ -170,44 +165,37 @@ async def test_async_with():
```py
# Make sure a leading comment is not removed.
def some_func(unformatted, args): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
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)
NOT_IMPLEMENTED_call()
await NOT_IMPLEMENTED_call()
# 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)
NOT_YET_IMPLEMENTED_StmtClassDef
# Make sure a leading comment is not removed.
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
if NOT_IMPLEMENTED_call(): # fmt: skip
NOT_IMPLEMENTED_call()
# Make sure this is not removed.
elif NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
elif NOT_IMPLEMENTED_call(): # fmt: skip
NOT_IMPLEMENTED_call()
else: # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
while NOT_IMPLEMENTED_call(): # fmt: skip
NOT_IMPLEMENTED_call()
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg): # fmt: skip
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call(): # fmt: skip
NOT_IMPLEMENTED_call()
async def test_async_for():

View File

@@ -66,7 +66,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
```diff
--- Black
+++ Ruff
@@ -2,64 +2,41 @@
@@ -2,64 +2,39 @@
a,
**kwargs,
) -> A:
@@ -82,8 +82,8 @@ with hmm_but_this_should_get_two_preceding_newlines():
- **kwargs,
- )
+ NOT_YET_IMPLEMENTED_StmtWith
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call() # negate top
+ return NOT_IMPLEMENTED_call()
def g():
@@ -94,7 +94,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
pass
- print("Inner defs should breathe a little.")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
def h():
@@ -102,7 +102,7 @@ with hmm_but_this_should_get_two_preceding_newlines():
pass
- print("Inner defs should breathe a little.")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-if os.name == "posix":
@@ -129,17 +129,17 @@ with hmm_but_this_should_get_two_preceding_newlines():
elif False:
-
class IHopeYouAreHavingALovelyDay:
def __call__(self):
- class IHopeYouAreHavingALovelyDay:
- def __call__(self):
- print("i_should_be_followed_by_only_one_newline")
-
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_YET_IMPLEMENTED_StmtClassDef
else:
-
def foo():
pass
-
-
-with hmm_but_this_should_get_two_preceding_newlines():
- pass
+NOT_YET_IMPLEMENTED_StmtWith
@@ -153,8 +153,8 @@ def f(
**kwargs,
) -> A:
NOT_YET_IMPLEMENTED_StmtWith
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # negate top
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call() # negate top
return NOT_IMPLEMENTED_call()
def g():
@@ -163,14 +163,14 @@ def g():
def inner():
pass
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
def h():
def inner():
pass
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
@@ -182,9 +182,7 @@ elif NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_YET_IMPLEMENTED_StmtTry
elif False:
class IHopeYouAreHavingALovelyDay:
def __call__(self):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_YET_IMPLEMENTED_StmtClassDef
else:
def foo():
pass

View File

@@ -136,11 +136,11 @@ def __await__(): return (yield)
...
- for i in range(10):
- print(i)
+ for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ for i in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call()
continue
- exec("new-style exec", {}, {})
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
return None
@@ -151,12 +151,12 @@ def __await__(): return (yield)
- await asyncio.sleep(1)
+ "NOT_YET_IMPLEMENTED_STRING"
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
@asyncio.coroutine
-@some_decorator(with_args=True, many_args=[1, 2, 3])
+@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+@NOT_IMPLEMENTED_call()
def function_signature_stress_test(
number: int,
no_annotation=None,
@@ -184,7 +184,7 @@ def __await__(): return (yield)
+ h="NOT_YET_IMPLEMENTED_STRING",
+ i="NOT_YET_IMPLEMENTED_STRING",
+):
+ offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ offset = NOT_IMPLEMENTED_call()
+ NOT_YET_IMPLEMENTED_StmtAssert
@@ -205,7 +205,7 @@ def __await__(): return (yield)
-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)):
+def spaces2(result=NOT_IMPLEMENTED_call()):
+ NOT_YET_IMPLEMENTED_StmtAssert
@@ -263,9 +263,9 @@ def __await__(): return (yield)
- """,
- 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)
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
+ _type_comment_re = NOT_IMPLEMENTED_call()
def trailing_comma():
@@ -309,21 +309,21 @@ def func_no_args():
NOT_YET_IMPLEMENTED_StmtRaise
if False:
...
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call()
continue
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
return None
async def coroutine(arg, exec=False):
"NOT_YET_IMPLEMENTED_STRING"
NOT_YET_IMPLEMENTED_StmtAsyncWith
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
@asyncio.coroutine
@NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
@NOT_IMPLEMENTED_call()
def function_signature_stress_test(
number: int,
no_annotation=None,
@@ -346,7 +346,7 @@ def spaces(
h="NOT_YET_IMPLEMENTED_STRING",
i="NOT_YET_IMPLEMENTED_STRING",
):
offset = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
offset = NOT_IMPLEMENTED_call()
NOT_YET_IMPLEMENTED_StmtAssert
@@ -364,7 +364,7 @@ def spaces_types(
...
def spaces2(result=NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)):
def spaces2(result=NOT_IMPLEMENTED_call()):
NOT_YET_IMPLEMENTED_StmtAssert
@@ -374,9 +374,9 @@ def example(session):
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)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
_type_comment_re = NOT_IMPLEMENTED_call()
def trailing_comma():

View File

@@ -106,8 +106,8 @@ some_module.some_function(
- call2(
- arg=[1, 2, 3],
- )
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ NOT_IMPLEMENTED_call()
x = {
- "a": 1,
- "b": 2,
@@ -161,7 +161,7 @@ some_module.some_function(
- this_shouldn_t_get_a_trailing_comma_too
- )
-):
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+def func() -> NOT_IMPLEMENTED_call():
pass
@@ -170,7 +170,7 @@ some_module.some_function(
- this_shouldn_t_get_a_trailing_comma_too
- )
-):
+def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
+def func() -> NOT_IMPLEMENTED_call():
pass
@@ -178,7 +178,7 @@ some_module.some_function(
-some_module.some_function(
- argument1, (one_element_tuple,), argument4, argument5, argument6
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
# Inner trailing comma causes outer to explode
-some_module.some_function(
@@ -191,7 +191,7 @@ some_module.some_function(
- argument5,
- argument6,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -223,8 +223,8 @@ def f2(
def f(
a: int = 1,
):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call()
x = {
"NOT_YET_IMPLEMENTED_STRING": 1,
"NOT_YET_IMPLEMENTED_STRING": 2,
@@ -257,19 +257,19 @@ def some_method_with_a_really_long_name(
pass
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
def func() -> NOT_IMPLEMENTED_call():
pass
def func() -> NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
def func() -> NOT_IMPLEMENTED_call():
pass
# Make sure inner one-element tuple won't explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Inner trailing comma causes outer to explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -87,7 +87,7 @@ return np.divide(
-e = lazy(lambda **kwargs: 5)
-f = f() ** 5
+d = 5 ** f["NOT_YET_IMPLEMENTED_STRING"]
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+e = NOT_IMPLEMENTED_call()
+f = NOT_IMPLEMENTED_call() ** 5
g = a.b**c.d
-h = 5 ** funcs.f()
@@ -106,7 +106,7 @@ return np.divide(
-p = {(k, k**2): v**2 for k, v in pairs}
-q = [10**i for i in range(6)]
+n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+o = NOT_IMPLEMENTED_call()
+p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+q = [i for i in []]
r = x**y
@@ -119,7 +119,7 @@ return np.divide(
-e = lazy(lambda **kwargs: 5)
-f = f() ** 5.0
+d = 5.0 ** f["NOT_YET_IMPLEMENTED_STRING"]
+e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+e = NOT_IMPLEMENTED_call()
+f = NOT_IMPLEMENTED_call() ** 5.0
g = a.b**c.d
-h = 5.0 ** funcs.f()
@@ -138,7 +138,7 @@ return np.divide(
-p = {(k, k**2): v**2.0 for k, v in pairs}
-q = [10.5**i for i in range(6)]
+n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+o = NOT_IMPLEMENTED_call()
+p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
+q = [i for i in []]
@@ -151,13 +151,13 @@ return np.divide(
- 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)
+if NOT_IMPLEMENTED_call():
+ return NOT_IMPLEMENTED_call()
-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)
+return NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -180,7 +180,7 @@ a = 5**~4
b = 5 ** NOT_IMPLEMENTED_call()
c = -(5**2)
d = 5 ** f["NOT_YET_IMPLEMENTED_STRING"]
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
e = NOT_IMPLEMENTED_call()
f = NOT_IMPLEMENTED_call() ** 5
g = a.b**c.d
h = 5 ** NOT_IMPLEMENTED_call()
@@ -190,7 +190,7 @@ k = [i for i in []]
l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
m = [([2**63], [1, 2**63])]
n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
o = NOT_IMPLEMENTED_call()
p = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
q = [i for i in []]
r = x**y
@@ -199,7 +199,7 @@ a = 5.0**~4.0
b = 5.0 ** NOT_IMPLEMENTED_call()
c = -(5.0**2.0)
d = 5.0 ** f["NOT_YET_IMPLEMENTED_STRING"]
e = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
e = NOT_IMPLEMENTED_call()
f = NOT_IMPLEMENTED_call() ** 5.0
g = a.b**c.d
h = 5.0 ** NOT_IMPLEMENTED_call()
@@ -209,16 +209,16 @@ k = [i for i in []]
l = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
m = [([2.0**63.0], [1.0, 2**63.0])]
n = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
o = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
o = NOT_IMPLEMENTED_call()
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)
if NOT_IMPLEMENTED_call():
return NOT_IMPLEMENTED_call()
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
return NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -25,7 +25,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
```diff
--- Black
+++ Ruff
@@ -9,13 +9,10 @@
@@ -9,13 +9,8 @@
m2,
),
third_value,
@@ -33,14 +33,14 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
- arg1,
- arg2,
-)
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+) = NOT_IMPLEMENTED_call()
# 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[
-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
-] = 1
+xxxxxxxxx_yyy_zzzzzzzz[NOT_IMPLEMENTED_call(), NOT_IMPLEMENTED_call()] = 1
```
## Ruff Output
@@ -57,13 +57,11 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
m2,
),
third_value,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
) = NOT_IMPLEMENTED_call()
# 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
xxxxxxxxx_yyy_zzzzzzzz[NOT_IMPLEMENTED_call(), NOT_IMPLEMENTED_call()] = 1
```
## Black Output

View File

@@ -102,23 +102,23 @@ async def main():
# Control example
async def main():
- await asyncio.sleep(1)
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
# Remove brackets for short coroutine/task
async def main():
- await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ await (NOT_IMPLEMENTED_call())
async def main():
- await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ await (NOT_IMPLEMENTED_call())
async def main():
- await asyncio.sleep(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ await (NOT_IMPLEMENTED_call())
# Check comments
@@ -126,7 +126,7 @@ async def main():
- await asyncio.sleep(1) # Hello
+ (
+ await # Hello
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
+ )
@@ -134,14 +134,14 @@ async def main():
- await asyncio.sleep(1) # Hello
+ (
+ await (
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello
+ NOT_IMPLEMENTED_call() # Hello
+ )
+ )
async def main():
- await asyncio.sleep(1) # Hello
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello
+ await (NOT_IMPLEMENTED_call()) # Hello
# Long lines
@@ -155,7 +155,7 @@ async def main():
- asyncio.sleep(1),
- asyncio.sleep(1),
- )
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
# Same as above but with magic trailing comma in function
@@ -169,13 +169,13 @@ async def main():
- asyncio.sleep(1),
- asyncio.sleep(1),
- )
+ await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ await NOT_IMPLEMENTED_call()
# Cr@zY Br@ck3Tz
async def main():
- await black(1)
+ await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ await (NOT_IMPLEMENTED_call())
# Keep brackets around non power operations and nested awaits
@@ -184,7 +184,7 @@ async def main():
async def main():
- await (await asyncio.sleep(1))
+ await (await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
+ await (await NOT_IMPLEMENTED_call())
# It's awaits all the way down...
@@ -198,12 +198,12 @@ async def main():
async def main():
- await (await asyncio.sleep(1))
+ await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))
+ await (await (NOT_IMPLEMENTED_call()))
async def main():
- await (await (await (await (await asyncio.sleep(1)))))
+ await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))))))
+ await (await (await (await (await (NOT_IMPLEMENTED_call())))))
async def main():
@@ -219,55 +219,55 @@ NOT_YET_IMPLEMENTED_StmtImport
# Control example
async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
# Remove brackets for short coroutine/task
async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
await (NOT_IMPLEMENTED_call())
async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
await (NOT_IMPLEMENTED_call())
async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
await (NOT_IMPLEMENTED_call())
# Check comments
async def main():
(
await # Hello
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
)
async def main():
(
await (
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # Hello
NOT_IMPLEMENTED_call() # Hello
)
)
async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)) # Hello
await (NOT_IMPLEMENTED_call()) # Hello
# Long lines
async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
# Same as above but with magic trailing comma in function
async def main():
await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
await NOT_IMPLEMENTED_call()
# Cr@zY Br@ck3Tz
async def main():
await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
await (NOT_IMPLEMENTED_call())
# Keep brackets around non power operations and nested awaits
@@ -276,7 +276,7 @@ async def main():
async def main():
await (await NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))
await (await NOT_IMPLEMENTED_call())
# It's awaits all the way down...
@@ -289,11 +289,11 @@ async def main():
async def main():
await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)))
await (await (NOT_IMPLEMENTED_call()))
async def main():
await (await (await (await (await (NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg))))))
await (await (await (await (await (NOT_IMPLEMENTED_call())))))
async def main():

View File

@@ -37,13 +37,13 @@ for (((((k, v))))) in d.items():
-for k, v in d.items():
- print(k, v)
+for k, v in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# 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):
+ if NOT_IMPLEMENTED_call():
+ module._verify_python3_env = lambda x: True
# Brackets remain for long for loop lines
@@ -53,7 +53,7 @@ for (((((k, v))))) in d.items():
-) in d.items():
- print(k, v)
+) in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-for (
- k,
@@ -63,13 +63,13 @@ for (((((k, v))))) in d.items():
-):
- print(k, v)
+for k, v in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
# 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)
+ NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -77,11 +77,11 @@ for (((((k, v))))) in d.items():
```py
# Only remove tuple brackets after `for`
for k, v in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Don't touch tuple brackets after `in`
for module in (core, _unicodefun):
if NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
if NOT_IMPLEMENTED_call():
module._verify_python3_env = lambda x: True
# Brackets remain for long for loop lines
@@ -89,14 +89,14 @@ 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)
NOT_IMPLEMENTED_call()
for k, v in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Test deeply nested brackets
for k, v in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -121,72 +121,72 @@ with open("/path/to/file.txt", mode="r") as read_file:
```diff
--- Black
+++ Ruff
@@ -1,78 +1,74 @@
@@ -1,78 +1,72 @@
-import random
+NOT_YET_IMPLEMENTED_StmtImport
def foo1():
- print("The newline above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
def foo2():
- print("All the newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
def foo3():
- print("No newline above me!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
- print("There is a newline above me, and that's OK!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
def foo4():
# There is a comment here
- print("The newline above me should not be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
class Foo:
def bar(self):
-class Foo:
- def bar(self):
- print("The newline above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_YET_IMPLEMENTED_StmtClassDef
-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 NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call()
-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 NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call()
-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)
+for i in NOT_IMPLEMENTED_call():
+ for j in NOT_IMPLEMENTED_call():
+ NOT_IMPLEMENTED_call()
-if random.randint(0, 3) == 0:
- print("The new line above me is about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-if random.randint(0, 3) == 0:
- print("The new lines above me is about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-if random.randint(0, 3) == 0:
@@ -194,23 +194,23 @@ with open("/path/to/file.txt", mode="r") as read_file:
- print("Two lines above me are about to be removed!")
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
while True:
- print("The newline above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
while True:
- print("The newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
while True:
while False:
- print("The newlines above me should be deleted!")
+ NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+ NOT_IMPLEMENTED_call()
-with open("/path/to/file.txt", mode="w") as file:
@@ -236,67 +236,65 @@ NOT_YET_IMPLEMENTED_StmtImport
def foo1():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
def foo2():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
def foo3():
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
def foo4():
# There is a comment here
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
class Foo:
def bar(self):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_YET_IMPLEMENTED_StmtClassDef
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call()
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call()
for i in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
for j in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
for i in NOT_IMPLEMENTED_call():
for j in NOT_IMPLEMENTED_call():
NOT_IMPLEMENTED_call()
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
while True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
while True:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
while True:
while False:
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_YET_IMPLEMENTED_StmtWith

View File

@@ -91,10 +91,10 @@ func(
# Trailing commas in multiple chained non-nested parens.
-zero(one).two(three).four(five)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
-func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
-(a, b, c, d) = func1(arg1) and func2(arg2)
+(
@@ -102,10 +102,10 @@ func(
+ b,
+ c,
+ d,
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+) = NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
-func(argument1, (one, two), argument4, argument5, argument6)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
```
## Ruff Output
@@ -134,18 +134,18 @@ set_of_types = {tuple[(int,)]}
small_tuple = (1,)
# Trailing commas in multiple chained non-nested parens.
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
(
a,
b,
c,
d,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
) = NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```
## Black Output

View File

@@ -76,7 +76,7 @@ x[
```diff
--- Black
+++ Ruff
@@ -4,30 +4,35 @@
@@ -4,30 +4,30 @@
slice[d::d]
slice[0]
slice[-1]
@@ -113,16 +113,11 @@ x[
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[ : NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()], ham[ :: NOT_IMPLEMENTED_call()]
ham[lower + offset : upper + offset]
slice[::, ::]
@@ -50,10 +55,14 @@
@@ -50,10 +50,14 @@
slice[
# A
1
@@ -174,12 +169,7 @@ async def f():
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[ : NOT_IMPLEMENTED_call() : NOT_IMPLEMENTED_call()], ham[ :: NOT_IMPLEMENTED_call()]
ham[lower + offset : upper + offset]
slice[::, ::]

View File

@@ -42,7 +42,7 @@ assert (
```diff
--- Black
+++ Ruff
@@ -2,20 +2,10 @@
@@ -2,57 +2,24 @@
(
()
<< 0
@@ -65,16 +65,16 @@ assert (
importA
0
@@ -24,35 +14,15 @@
0 ^ 0 #
class A:
def foo(self):
-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)
+NOT_YET_IMPLEMENTED_StmtClassDef
def test(self, othr):
@@ -126,10 +126,7 @@ importA
0 ^ 0 #
class A:
def foo(self):
for _ in NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg):
aaaaaaaaaaaaaaaaaaa = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_YET_IMPLEMENTED_StmtClassDef
def test(self, othr):

View File

@@ -38,15 +38,12 @@ class A:
```diff
--- Black
+++ Ruff
@@ -1,34 +1,25 @@
@@ -1,34 +1,12 @@
-if e1234123412341234.winerror not in (
- _winapi.ERROR_SEM_TIMEOUT,
- _winapi.ERROR_PIPE_BUSY,
-) or _check_timeout(t):
+if (
+ NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+ or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+):
+if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right or NOT_IMPLEMENTED_call():
pass
if x:
@@ -58,63 +55,45 @@ class A:
- )
- + 1
- )
+ new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1
+ new_id = NOT_IMPLEMENTED_call() + 1
class X:
def get_help_text(self):
-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) % {
+ "NOT_YET_IMPLEMENTED_STRING": self.min_length,
+ }
+NOT_YET_IMPLEMENTED_StmtClassDef
class A:
def b(self):
-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 NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
+ ):
pass
- pass
+NOT_YET_IMPLEMENTED_StmtClassDef
```
## Ruff Output
```py
if (
NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
or NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
):
if NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right or NOT_IMPLEMENTED_call():
pass
if x:
if y:
new_id = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) + 1
new_id = NOT_IMPLEMENTED_call() + 1
class X:
def get_help_text(self):
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
"NOT_YET_IMPLEMENTED_STRING": self.min_length,
}
NOT_YET_IMPLEMENTED_StmtClassDef
class A:
def b(self):
if (
self.connection.mysql_is_mariadb
and NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
):
pass
NOT_YET_IMPLEMENTED_StmtClassDef
```
## Black Output

View File

@@ -30,7 +30,7 @@ if True:
- + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
- "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
- ) % {"reported_username": reported_username, "report_reason": report_reason}
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
+ return NOT_IMPLEMENTED_call() % {
+ "NOT_YET_IMPLEMENTED_STRING": reported_username,
+ "NOT_YET_IMPLEMENTED_STRING": report_reason,
+ }
@@ -42,7 +42,7 @@ if True:
if True:
if True:
if True:
return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) % {
return NOT_IMPLEMENTED_call() % {
"NOT_YET_IMPLEMENTED_STRING": reported_username,
"NOT_YET_IMPLEMENTED_STRING": report_reason,
}

View File

@@ -54,18 +54,18 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
-).four(
- five,
-)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
-func1(arg1).func2(
- arg2,
-).func3(arg3).func4(
- arg4,
-).func5(arg5)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
# Inner one-element tuple shouldn't explode
-func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
+NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+NOT_IMPLEMENTED_call()
(
a,
@@ -75,7 +75,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
-) = func1(
- arg1
-) and func2(arg2)
+) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
+) = NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
# Example from https://github.com/psf/black/issues/3229
@@ -86,7 +86,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
- },
- api_key=api_key,
- )["extensions"]["sdk"]["token"]
+ return NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)["NOT_YET_IMPLEMENTED_STRING"][
+ return NOT_IMPLEMENTED_call()["NOT_YET_IMPLEMENTED_STRING"][
+ "NOT_YET_IMPLEMENTED_STRING"
+ ][
+ "NOT_YET_IMPLEMENTED_STRING"
@@ -113,24 +113,24 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
## Ruff Output
```py
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
# Inner one-element tuple shouldn't explode
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
(
a,
b,
c,
d,
) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
) = NOT_IMPLEMENTED_call() and NOT_IMPLEMENTED_call()
# 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)["NOT_YET_IMPLEMENTED_STRING"][
return NOT_IMPLEMENTED_call()["NOT_YET_IMPLEMENTED_STRING"][
"NOT_YET_IMPLEMENTED_STRING"
][
"NOT_YET_IMPLEMENTED_STRING"

View File

@@ -29,7 +29,7 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
# 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)
+(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call()
-(a,) = call()
+(a,) = NOT_IMPLEMENTED_call()
@@ -47,7 +47,7 @@ this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
) = 1, 2, 3
# This is as well.
(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
(this_will_be_wrapped_in_parens,) = NOT_IMPLEMENTED_call()
(a,) = NOT_IMPLEMENTED_call()
```

View File

@@ -214,7 +214,7 @@ if (
# Black breaks the right side first for the following expressions:
aaaaaaaaaaaaaa + NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
aaaaaaaaaaaaaa + NOT_IMPLEMENTED_call()
aaaaaaaaaaaaaa + [
bbbbbbbbbbbbbbbbbbbbbb,
ccccccccccccccccccccc,

View File

@@ -54,14 +54,6 @@ mapping = {
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,
}
```
@@ -120,14 +112,6 @@ mapping = {
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,
}
```

View File

@@ -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
```

View File

@@ -61,16 +61,16 @@ while (
else:
...
while NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) and anotherCondition or aThirdCondition: # comment
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
while NOT_IMPLEMENTED_call() and anotherCondition or aThirdCondition: # comment
NOT_IMPLEMENTED_call()
while (
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg) # trailing some condition
NOT_IMPLEMENTED_call() # trailing some condition
and anotherCondition
or aThirdCondition # trailing third condition
): # comment
NOT_IMPLEMENTED_call(NOT_IMPLEMENTED_arg)
NOT_IMPLEMENTED_call()
```

View File

@@ -52,10 +52,7 @@ b = 20
# Adds two lines after `b`
class Test:
def a(self):
pass
# trailing comment
NOT_YET_IMPLEMENTED_StmtClassDef
# two lines before, one line after

View File

@@ -1,138 +1,12 @@
use crate::comments::trailing_comments;
use crate::expression::parentheses::Parenthesize;
use crate::prelude::*;
use crate::trivia::{first_non_trivia_token, SimpleTokenizer, Token, TokenKind};
use crate::USE_MAGIC_TRAILING_COMMA;
use ruff_formatter::{format_args, write};
use ruff_text_size::TextRange;
use rustpython_parser::ast::{Expr, Keyword, Ranged, StmtClassDef};
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
use ruff_formatter::{write, Buffer, FormatResult};
use rustpython_parser::ast::StmtClassDef;
#[derive(Default)]
pub struct FormatStmtClassDef;
impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
fn fmt_fields(&self, item: &StmtClassDef, f: &mut PyFormatter) -> FormatResult<()> {
let StmtClassDef {
range: _,
name,
bases,
keywords,
body,
decorator_list,
} = item;
f.join_with(hard_line_break())
.entries(decorator_list.iter().formatted())
.finish()?;
if !decorator_list.is_empty() {
hard_line_break().fmt(f)?;
}
write!(f, [text("class"), space(), name.format()])?;
if !(bases.is_empty() && keywords.is_empty()) {
write!(
f,
[group(&format_args![
text("("),
soft_block_indent(&FormatInheritanceClause {
class_definition: item
}),
text(")")
])]
)?;
}
let comments = f.context().comments().clone();
let trailing_head_comments = comments.dangling_comments(item);
write!(
f,
[
text(":"),
trailing_comments(trailing_head_comments),
block_indent(&body.format())
]
)
}
fn fmt_dangling_comments(
&self,
_node: &StmtClassDef,
_f: &mut PyFormatter,
) -> FormatResult<()> {
// handled in fmt_fields
Ok(())
}
}
struct FormatInheritanceClause<'a> {
class_definition: &'a StmtClassDef,
}
impl Format<PyFormatContext<'_>> for FormatInheritanceClause<'_> {
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
let StmtClassDef {
bases,
keywords,
name,
..
} = self.class_definition;
let separator = format_with(|f| write!(f, [text(","), soft_line_break_or_space()]));
let source = f.context().contents();
let mut joiner = f.join_with(&separator);
if let Some((first, rest)) = bases.split_first() {
// Manually handle parentheses for the first expression because the logic in `FormatExpr`
// doesn't know that it should disregard the parentheses of the inheritance clause.
// ```python
// class Test(A) # A is not parenthesized, the parentheses belong to the inheritance clause
// class Test((A)) # A is parenthesized
// ```
// parentheses from the inheritance clause belong to the expression.
let tokenizer = SimpleTokenizer::new(source, TextRange::new(name.end(), first.start()))
.skip_trivia();
let left_paren_count = tokenizer
.take_while(|token| token.kind() == TokenKind::LParen)
.count();
// Ignore the first parentheses count
let parenthesize = if left_paren_count > 1 {
Parenthesize::Always
} else {
Parenthesize::Never
};
joiner.entry(&first.format().with_options(parenthesize));
joiner.entries(rest.iter().formatted());
}
joiner.entries(keywords.iter().formatted()).finish()?;
if_group_breaks(&text(",")).fmt(f)?;
if USE_MAGIC_TRAILING_COMMA {
let last_end = keywords
.last()
.map(Keyword::end)
.or_else(|| bases.last().map(Expr::end))
.unwrap();
if matches!(
first_non_trivia_token(last_end, f.context().contents()),
Some(Token {
kind: TokenKind::Comma,
..
})
) {
hard_line_break().fmt(f)?;
}
}
Ok(())
write!(f, [not_yet_implemented(item)])
}
}

View File

@@ -252,8 +252,7 @@ one_leading_newline = 10
no_leading_newline = 30
class InTheMiddle:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
trailing_statement = 1
@@ -284,8 +283,7 @@ two_leading_newlines = 20
one_leading_newline = 10
no_leading_newline = 30
class InTheMiddle:
pass
NOT_YET_IMPLEMENTED_StmtClassDef
trailing_statement = 1

View File

@@ -22,45 +22,15 @@
--crater: #f0dfdf;
}
[data-md-color-scheme="astral-light"] {
[data-md-color-scheme="ruff"] {
--md-default-bg-color--dark: var(--black);
--md-primary-fg-color: var(--galaxy);
--md-typeset-a-color: var(--flare);
--md-accent-fg-color: var(--cosmic);
}
[data-md-color-scheme="astral-dark"] {
--md-default-bg-color: var(--galaxy);
--md-default-fg-color: var(--white);
--md-default-fg-color--light: var(--white);
--md-default-fg-color--lighter: var(--white);
--md-primary-fg-color: var(--space);
--md-primary-bg-color: var(--white);
--md-accent-fg-color: var(--radiate);
--md-typeset-color: var(--white);
--md-typeset-a-color: var(--radiate);
--md-typeset-mark-color: var(--sun);
--md-code-fg-color: var(--white);
--md-code-bg-color: var(--space);
--md-code-hl-comment-color: var(--asteroid);
--md-code-hl-punctuation-color: var(--asteroid);
--md-code-hl-generic-color: var(--supernova);
--md-code-hl-variable-color: var(--starlight);
--md-code-hl-string-color: var(--radiate);
--md-code-hl-keyword-color: var(--supernova);
--md-code-hl-operator-color: var(--supernova);
--md-code-hl-number-color: var(--electron);
--md-code-hl-special-color: var(--electron);
--md-code-hl-function-color: var(--neutron);
--md-code-hl-constant-color: var(--radiate);
--md-code-hl-name-color: var(--md-code-fg-color);
--md-typeset-del-color: hsla(6, 90%, 60%, 0.15);
--md-typeset-ins-color: hsla(150, 90%, 44%, 0.15);
--md-typeset-table-color: hsla(0, 0%, 100%, 0.12);
--md-typeset-table-color--light: hsla(0, 0%, 100%, 0.035);
}
/*[data-md-color-scheme="slate"] {*/
/* --md-primary-fg-color: var(--galaxy);*/
/* --md-typeset-a-color: var(--cosmic);*/
/* --md-accent-fg-color: var(--white);*/
/*}*/

View File

@@ -26,7 +26,7 @@ def sum_even_numbers(numbers: List[int]) -> int:
return sum(num for num in numbers if num % 2 == 0)
```
To start, we'll install Ruff through PyPI (or with your [preferred package manager](installation.md)):
To start, we'll install Ruff through PyPI (or with our [preferred package manager](installation.md)):
```shell
> pip install ruff
@@ -242,7 +242,7 @@ This tutorial has focused on Ruff's command-line interface, but Ruff can also be
```yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.275
rev: v0.0.274
hooks:
- id: ruff
```

View File

@@ -22,7 +22,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com) hook:
```yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.275
rev: v0.0.274
hooks:
- id: ruff
```
@@ -32,7 +32,7 @@ Or, to enable autofix:
```yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.275
rev: v0.0.274
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

View File

@@ -14,12 +14,14 @@ theme:
- content.code.copy
palette:
- media: "(prefers-color-scheme: light)"
scheme: astral-light
scheme: ruff
primary: red
toggle:
icon: material/weather-sunny
name: Switch to dark mode
- media: "(prefers-color-scheme: dark)"
scheme: astral-dark
scheme: slate
primary: deep-purple
toggle:
icon: material/weather-night
name: Switch to light mode

View File

@@ -5,7 +5,7 @@ build-backend = "maturin"
[project]
name = "ruff"
version = "0.0.275"
version = "0.0.274"
description = "An extremely fast Python linter, written in Rust."
authors = [{ name = "Charlie Marsh", email = "charlie.r.marsh@gmail.com" }]
maintainers = [{ name = "Charlie Marsh", email = "charlie.r.marsh@gmail.com" }]

View File

@@ -1,5 +1,3 @@
from __future__ import annotations
import re
from pathlib import Path

View File

@@ -8,7 +8,6 @@ Example usage:
--url https://pypi.org/project/flake8-pie/
--prefix PIE
"""
from __future__ import annotations
import argparse

View File

@@ -9,7 +9,6 @@ Example usage:
--code 807 \
--linter flake8-pie
"""
from __future__ import annotations
import argparse
import subprocess

View File

@@ -1,22 +1,17 @@
#!/usr/bin/env python3
"""Check code snippets in docs are formatted by black."""
from __future__ import annotations
import argparse
import os
import re
import textwrap
from collections.abc import Sequence
from pathlib import Path
from re import Match
from typing import TYPE_CHECKING
import black
from black.mode import Mode, TargetVersion
from black.parsing import InvalidInput
if TYPE_CHECKING:
from collections.abc import Sequence
TARGET_VERSIONS = ["py37", "py38", "py39", "py310", "py311"]
SNIPPED_RE = re.compile(
r"(?P<before>^(?P<indent> *)```\s*python\n)"

View File

@@ -44,11 +44,11 @@ class Repository(NamedTuple):
async def clone(self: Self, checkout_dir: Path) -> AsyncIterator[Path]:
"""Shallow clone this repository to a temporary directory."""
if checkout_dir.exists():
logger.debug(f"Reusing {self.org}:{self.repo}")
logger.debug(f"Reusing {self.org}/{self.repo}")
yield Path(checkout_dir)
return
logger.debug(f"Cloning {self.org}:{self.repo}")
logger.debug(f"Cloning {self.org}/{self.repo}")
git_command = [
"git",
"clone",
@@ -177,17 +177,18 @@ async def compare(
"""Check a specific repository against two versions of ruff."""
removed, added = set(), set()
# By the default, the git clone are transient, but if the user provides a
# directory for permanent storage we keep it there
# Allows to keep the checkouts locations
if checkouts:
location_context = nullcontext(checkouts)
checkout_parent = checkouts.joinpath(repo.org)
# Don't create the repodir itself, we need that for checking for existing
# clones
checkout_parent.mkdir(exist_ok=True, parents=True)
location_context = nullcontext(checkout_parent)
else:
location_context = tempfile.TemporaryDirectory()
with location_context as checkout_parent:
assert ":" not in repo.org
assert ":" not in repo.repo
checkout_dir = Path(checkout_parent).joinpath(f"{repo.org}:{repo.repo}")
checkout_dir = Path(checkout_parent).joinpath(repo.repo)
async with repo.clone(checkout_dir) as path:
try:
async with asyncio.TaskGroup() as tg:
@@ -283,19 +284,8 @@ async def main(
logger.debug(f"Checking {len(repositories)} projects")
# https://stackoverflow.com/a/61478547/3549270
# Otherwise doing 3k repositories can take >8GB RAM
semaphore = asyncio.Semaphore(50)
async def limited_parallelism(coroutine): # noqa: ANN
async with semaphore:
return await coroutine
results = await asyncio.gather(
*[
limited_parallelism(compare(ruff1, ruff2, repo, checkouts))
for repo in repositories.values()
],
*[compare(ruff1, ruff2, repo, checkouts) for repo in repositories.values()],
return_exceptions=True,
)
@@ -443,8 +433,6 @@ if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
if args.checkouts:
args.checkouts.mkdir(exist_ok=True, parents=True)
main_task = asyncio.ensure_future(
main(
ruff1=args.ruff1,

View File

@@ -3,14 +3,13 @@ panics, autofix errors and similar problems.
It's a less elaborate, more hacky version of check_ecosystem.py
"""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
from subprocess import CalledProcessError
from typing import NamedTuple
from typing import NamedTuple, Optional
from tqdm import tqdm
@@ -20,7 +19,7 @@ class Repository(NamedTuple):
org: str
repo: str
ref: str | None
ref: Optional[str]
def main() -> None:

Some files were not shown because too many files have changed in this diff Show More