mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Format Function definitions (#4951)
This commit is contained in:
parent
07cc4bcb0f
commit
68969240c5
79 changed files with 2601 additions and 1223 deletions
|
@ -112,3 +112,22 @@ impl<'a> From<&'a StmtAsyncFunctionDef> for AnyFunctionDefinition<'a> {
|
||||||
Self::AsyncFunctionDefinition(value)
|
Self::AsyncFunctionDefinition(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<AnyFunctionDefinition<'a>> for AnyNodeRef<'a> {
|
||||||
|
fn from(value: AnyFunctionDefinition<'a>) -> Self {
|
||||||
|
match value {
|
||||||
|
AnyFunctionDefinition::FunctionDefinition(function_def) => {
|
||||||
|
AnyNodeRef::StmtFunctionDef(function_def)
|
||||||
|
}
|
||||||
|
AnyFunctionDefinition::AsyncFunctionDefinition(async_def) => {
|
||||||
|
AnyNodeRef::StmtAsyncFunctionDef(async_def)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a AnyFunctionDefinition<'a>> for AnyNodeRef<'a> {
|
||||||
|
fn from(value: &'a AnyFunctionDefinition<'a>) -> Self {
|
||||||
|
(*value).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,11 @@ for group, group_nodes in nodes_grouped.items():
|
||||||
# )
|
# )
|
||||||
# src.joinpath(groups[group]).joinpath("mod.rs").write_text(rustfmt(mod_section))
|
# src.joinpath(groups[group]).joinpath("mod.rs").write_text(rustfmt(mod_section))
|
||||||
for node in group_nodes:
|
for node in group_nodes:
|
||||||
|
node_path = src.joinpath(groups[group]).joinpath(f"{to_camel_case(node)}.rs")
|
||||||
|
# Don't override existing manual implementations
|
||||||
|
if node_path.exists():
|
||||||
|
continue
|
||||||
|
|
||||||
code = f"""
|
code = f"""
|
||||||
use crate::{{verbatim_text, FormatNodeRule, PyFormatter}};
|
use crate::{{verbatim_text, FormatNodeRule, PyFormatter}};
|
||||||
use ruff_formatter::{{write, Buffer, FormatResult}};
|
use ruff_formatter::{{write, Buffer, FormatResult}};
|
||||||
|
@ -91,9 +96,8 @@ for group, group_nodes in nodes_grouped.items():
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
""".strip() # noqa: E501
|
""".strip() # noqa: E501
|
||||||
src.joinpath(groups[group]).joinpath(f"{to_camel_case(node)}.rs").write_text(
|
|
||||||
rustfmt(code)
|
node_path.write_text(rustfmt(code))
|
||||||
)
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
# Generate `FormatRule`, `AsFormat` and `IntoFormat`
|
# Generate `FormatRule`, `AsFormat` and `IntoFormat`
|
||||||
|
|
70
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py
vendored
Normal file
70
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py
vendored
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# Dangling comments
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# another
|
||||||
|
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# Argument empty line spacing
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
|
||||||
|
# another
|
||||||
|
|
||||||
|
b,
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
### Different function argument wrappings
|
||||||
|
|
||||||
|
def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def arguments_on_their_own_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def argument_per_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def last_pos_only_trailing_comma(a, b, /,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def last_pos_no_trailing_comma(a, b, /):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def varg_with_leading_comments(
|
||||||
|
a, b,
|
||||||
|
# comment
|
||||||
|
*args
|
||||||
|
): ...
|
||||||
|
|
||||||
|
def kwarg_with_leading_comments(
|
||||||
|
a, b,
|
||||||
|
# comment
|
||||||
|
**kwargs
|
||||||
|
): ...
|
||||||
|
|
||||||
|
def argument_with_long_default(
|
||||||
|
a,
|
||||||
|
b = ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + [
|
||||||
|
dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff
|
||||||
|
],
|
||||||
|
h = []
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
def argument_with_long_type_annotation(
|
||||||
|
a,
|
||||||
|
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||||
|
h = []
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
def test(): ...
|
||||||
|
|
||||||
|
# Comment
|
||||||
|
def with_leading_comment(): ...
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::comments::SourceComment;
|
use crate::comments::SourceComment;
|
||||||
use crate::context::NodeLevel;
|
use crate::context::NodeLevel;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::trivia::{lines_after, lines_before};
|
use crate::trivia::{lines_after, lines_before, skip_trailing_trivia};
|
||||||
use ruff_formatter::{format_args, write, FormatError, SourceCode};
|
use ruff_formatter::{format_args, write, FormatError, SourceCode};
|
||||||
use ruff_python_ast::node::AnyNodeRef;
|
use ruff_python_ast::node::AnyNodeRef;
|
||||||
use ruff_python_ast::prelude::AstNode;
|
use ruff_python_ast::prelude::AstNode;
|
||||||
|
@ -86,9 +86,10 @@ impl Format<PyFormatContext<'_>> for FormatLeadingAlternateBranchComments<'_> {
|
||||||
|
|
||||||
write!(f, [leading_comments(self.comments)])?;
|
write!(f, [leading_comments(self.comments)])?;
|
||||||
} else if let Some(last_preceding) = self.last_node {
|
} else if let Some(last_preceding) = self.last_node {
|
||||||
|
let full_end = skip_trailing_trivia(last_preceding.end(), f.context().contents());
|
||||||
// The leading comments formatting ensures that it preserves the right amount of lines after
|
// The leading comments formatting ensures that it preserves the right amount of lines after
|
||||||
// We need to take care of this ourselves, if there's no leading `else` comment.
|
// We need to take care of this ourselves, if there's no leading `else` comment.
|
||||||
if lines_after(last_preceding.end(), f.context().contents()) > 1 {
|
if lines_after(full_end, f.context().contents()) > 1 {
|
||||||
write!(f, [empty_line()])?;
|
write!(f, [empty_line()])?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ use crate::comments::map::MultiMap;
|
||||||
use crate::comments::node_key::NodeRefEqualityKey;
|
use crate::comments::node_key::NodeRefEqualityKey;
|
||||||
use crate::comments::visitor::CommentsVisitor;
|
use crate::comments::visitor::CommentsVisitor;
|
||||||
pub(crate) use format::{
|
pub(crate) use format::{
|
||||||
dangling_comments, dangling_node_comments, leading_alternate_branch_comments,
|
dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
|
||||||
leading_node_comments, trailing_comments, trailing_node_comments,
|
leading_node_comments, trailing_comments, trailing_node_comments,
|
||||||
};
|
};
|
||||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
||||||
|
@ -295,6 +295,14 @@ impl<'a> Comments<'a> {
|
||||||
!self.trailing_comments(node).is_empty()
|
!self.trailing_comments(node).is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the given `node` has any [trailing own line comments](self#trailing-comments).
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn has_trailing_own_line_comments(&self, node: AnyNodeRef) -> bool {
|
||||||
|
self.trailing_comments(node)
|
||||||
|
.iter()
|
||||||
|
.any(|comment| comment.position().is_own_line())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the [leading](self#leading-comments) and [trailing comments](self#trailing-comments) of `node`.
|
/// Returns an iterator over the [leading](self#leading-comments) and [trailing comments](self#trailing-comments) of `node`.
|
||||||
pub(crate) fn leading_trailing_comments(
|
pub(crate) fn leading_trailing_comments(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub(super) fn place_comment<'a>(
|
||||||
.or_else(|comment| {
|
.or_else(|comment| {
|
||||||
handle_trailing_binary_expression_left_or_operator_comment(comment, locator)
|
handle_trailing_binary_expression_left_or_operator_comment(comment, locator)
|
||||||
})
|
})
|
||||||
|
.or_else(handle_leading_function_with_decorators_comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles leading comments in front of a match case or a trailing comment of the `match` statement.
|
/// Handles leading comments in front of a match case or a trailing comment of the `match` statement.
|
||||||
|
@ -103,9 +104,8 @@ fn handle_match_comment<'a>(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Comment after the last statement in a match case...
|
// Comment after the last statement in a match case...
|
||||||
let match_stmt_indentation = whitespace::indentation(locator, match_stmt)
|
let match_stmt_indentation =
|
||||||
.unwrap_or_default()
|
whitespace::indentation(locator, match_stmt).map_or(usize::MAX, str::len);
|
||||||
.len();
|
|
||||||
|
|
||||||
if comment_indentation <= match_case_indentation
|
if comment_indentation <= match_case_indentation
|
||||||
&& comment_indentation > match_stmt_indentation
|
&& comment_indentation > match_stmt_indentation
|
||||||
|
@ -379,9 +379,8 @@ fn handle_trailing_body_comment<'a>(
|
||||||
let mut grand_parent_body = None;
|
let mut grand_parent_body = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let child_indentation = whitespace::indentation(locator, ¤t_child)
|
let child_indentation =
|
||||||
.map(str::len)
|
whitespace::indentation(locator, ¤t_child).map_or(usize::MAX, str::len);
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
match comment_indentation_len.cmp(&child_indentation) {
|
match comment_indentation_len.cmp(&child_indentation) {
|
||||||
Ordering::Less => {
|
Ordering::Less => {
|
||||||
|
@ -511,6 +510,11 @@ fn handle_trailing_end_of_line_condition_comment<'a>(
|
||||||
| AnyNodeRef::StmtAsyncWith(StmtAsyncWith { items, .. }) => {
|
| AnyNodeRef::StmtAsyncWith(StmtAsyncWith { items, .. }) => {
|
||||||
items.last().map(AnyNodeRef::from)
|
items.last().map(AnyNodeRef::from)
|
||||||
}
|
}
|
||||||
|
AnyNodeRef::StmtFunctionDef(StmtFunctionDef { returns, args, .. })
|
||||||
|
| AnyNodeRef::StmtAsyncFunctionDef(StmtAsyncFunctionDef { returns, args, .. }) => returns
|
||||||
|
.as_deref()
|
||||||
|
.map(AnyNodeRef::from)
|
||||||
|
.or_else(|| Some(AnyNodeRef::from(args.as_ref()))),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -820,6 +824,32 @@ fn find_pos_only_slash_offset(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handles own line comments between the last function decorator and the *header* of the function.
|
||||||
|
/// It attaches these comments as dangling comments to the function instead of making them
|
||||||
|
/// leading argument comments.
|
||||||
|
///
|
||||||
|
/// ```python
|
||||||
|
/// @decorator
|
||||||
|
/// # leading function comment
|
||||||
|
/// def test():
|
||||||
|
/// ...
|
||||||
|
/// ```
|
||||||
|
fn handle_leading_function_with_decorators_comment(comment: DecoratedComment) -> CommentPlacement {
|
||||||
|
let is_preceding_decorator = comment
|
||||||
|
.preceding_node()
|
||||||
|
.map_or(false, |node| node.is_decorator());
|
||||||
|
|
||||||
|
let is_following_arguments = comment
|
||||||
|
.following_node()
|
||||||
|
.map_or(false, |node| node.is_arguments());
|
||||||
|
|
||||||
|
if comment.text_position().is_own_line() && is_preceding_decorator && is_following_arguments {
|
||||||
|
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||||
|
} else {
|
||||||
|
CommentPlacement::Default(comment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if `right` is `Some` and `left` and `right` are referentially equal.
|
/// Returns `true` if `right` is `Some` and `left` and `right` are referentially equal.
|
||||||
fn are_same_optional<'a, T>(left: AnyNodeRef, right: Option<T>) -> bool
|
fn are_same_optional<'a, T>(left: AnyNodeRef, right: Option<T>) -> bool
|
||||||
where
|
where
|
||||||
|
|
|
@ -4,18 +4,18 @@ expression: comments.debug(test_case.source_code)
|
||||||
---
|
---
|
||||||
{
|
{
|
||||||
Node {
|
Node {
|
||||||
kind: StmtPass,
|
kind: StmtExpr,
|
||||||
range: 12..16,
|
range: 29..42,
|
||||||
source: `pass`,
|
source: `print("test")`,
|
||||||
}: {
|
}: {
|
||||||
"leading": [],
|
"leading": [
|
||||||
"dangling": [],
|
|
||||||
"trailing": [
|
|
||||||
SourceComment {
|
SourceComment {
|
||||||
text: "# Test",
|
text: "# Test",
|
||||||
position: OwnLine,
|
position: OwnLine,
|
||||||
formatted: false,
|
formatted: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"dangling": [],
|
||||||
|
"trailing": [],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,13 @@ impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {
|
||||||
self.finish_node(expr);
|
self.finish_node(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_decorator(&mut self, decorator: &'ast Decorator) {
|
||||||
|
if self.start_node(decorator).is_traverse() {
|
||||||
|
walk_decorator(self, decorator);
|
||||||
|
}
|
||||||
|
self.finish_node(decorator);
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'ast Expr) {
|
fn visit_expr(&mut self, expr: &'ast Expr) {
|
||||||
if self.start_node(expr).is_traverse() {
|
if self.start_node(expr).is_traverse() {
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -39,7 +40,12 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprAttribute {
|
impl NeedsParentheses for ExprAttribute {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -17,7 +18,12 @@ impl FormatNodeRule<ExprAwait> for FormatExprAwait {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprAwait {
|
impl NeedsParentheses for ExprAwait {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::comments::trailing_comments;
|
use crate::comments::{trailing_comments, Comments};
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -171,8 +171,13 @@ impl FormatRule<Operator, PyFormatContext<'_>> for FormatOperator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprBinOp {
|
impl NeedsParentheses for ExprBinOp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => {
|
Parentheses::Optional => {
|
||||||
if should_binary_break_right_side_first(self) {
|
if should_binary_break_right_side_first(self) {
|
||||||
Parentheses::Custom
|
Parentheses::Custom
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -20,7 +21,12 @@ impl FormatNodeRule<ExprBoolOp> for FormatExprBoolOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprBoolOp {
|
impl NeedsParentheses for ExprBoolOp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -18,8 +19,13 @@ impl FormatNodeRule<ExprCall> for FormatExprCall {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprCall {
|
impl NeedsParentheses for ExprCall {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::expression::parentheses::{
|
||||||
};
|
};
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
||||||
|
|
||||||
|
use crate::comments::Comments;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::{write, Buffer, FormatResult};
|
||||||
use rustpython_parser::ast::ExprCompare;
|
use rustpython_parser::ast::ExprCompare;
|
||||||
|
|
||||||
|
@ -21,7 +22,12 @@ impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprCompare {
|
impl NeedsParentheses for ExprCompare {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -41,7 +42,15 @@ impl FormatNodeRule<ExprConstant> for FormatExprConstant {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprConstant {
|
impl NeedsParentheses for ExprConstant {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
|
Parentheses::Optional => Parentheses::Never,
|
||||||
|
parentheses => parentheses,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -20,8 +21,13 @@ impl FormatNodeRule<ExprDict> for FormatExprDict {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprDict {
|
impl NeedsParentheses for ExprDict {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -20,8 +21,13 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprDictComp {
|
impl NeedsParentheses for ExprDictComp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprFormattedValue> for FormatExprFormattedValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprFormattedValue {
|
impl NeedsParentheses for ExprFormattedValue {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,8 +16,13 @@ impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprGeneratorExp {
|
impl NeedsParentheses for ExprGeneratorExp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -20,7 +21,12 @@ impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprIfExp {
|
impl NeedsParentheses for ExprIfExp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprJoinedStr> for FormatExprJoinedStr {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprJoinedStr {
|
impl NeedsParentheses for ExprJoinedStr {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprLambda {
|
impl NeedsParentheses for ExprLambda {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::comments::dangling_comments;
|
use crate::comments::{dangling_comments, Comments};
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -57,8 +57,13 @@ impl FormatNodeRule<ExprList> for FormatExprList {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprList {
|
impl NeedsParentheses for ExprList {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,8 +16,13 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprListComp {
|
impl NeedsParentheses for ExprListComp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -26,8 +27,13 @@ impl FormatNodeRule<ExprName> for FormatExprName {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprName {
|
impl NeedsParentheses for ExprName {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprNamedExpr {
|
impl NeedsParentheses for ExprNamedExpr {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -34,8 +35,13 @@ impl FormatNodeRule<ExprSet> for FormatExprSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSet {
|
impl NeedsParentheses for ExprSet {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,8 +16,13 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSetComp {
|
impl NeedsParentheses for ExprSetComp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::expression::parentheses::{
|
||||||
};
|
};
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
||||||
|
|
||||||
|
use crate::comments::Comments;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::{write, Buffer, FormatResult};
|
||||||
use rustpython_parser::ast::ExprSlice;
|
use rustpython_parser::ast::ExprSlice;
|
||||||
|
|
||||||
|
@ -21,7 +22,12 @@ impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSlice {
|
impl NeedsParentheses for ExprSlice {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprStarred {
|
impl NeedsParentheses for ExprStarred {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::expression::parentheses::{
|
||||||
};
|
};
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
||||||
|
|
||||||
|
use crate::comments::Comments;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::{write, Buffer, FormatResult};
|
||||||
use rustpython_parser::ast::ExprSubscript;
|
use rustpython_parser::ast::ExprSubscript;
|
||||||
|
|
||||||
|
@ -21,7 +22,12 @@ impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSubscript {
|
impl NeedsParentheses for ExprSubscript {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,8 +16,13 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprTuple {
|
impl NeedsParentheses for ExprTuple {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
match default_expression_needs_parentheses(self.into(), parenthesize, source) {
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
match default_expression_needs_parentheses(self.into(), parenthesize, source, comments) {
|
||||||
Parentheses::Optional => Parentheses::Never,
|
Parentheses::Optional => Parentheses::Never,
|
||||||
parentheses => parentheses,
|
parentheses => parentheses,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprUnaryOp> for FormatExprUnaryOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprUnaryOp {
|
impl NeedsParentheses for ExprUnaryOp {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprYield> for FormatExprYield {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprYield {
|
impl NeedsParentheses for ExprYield {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
|
@ -15,7 +16,12 @@ impl FormatNodeRule<ExprYieldFrom> for FormatExprYieldFrom {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprYieldFrom {
|
impl NeedsParentheses for ExprYieldFrom {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
default_expression_needs_parentheses(self.into(), parenthesize, source)
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
|
default_expression_needs_parentheses(self.into(), parenthesize, source, comments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::context::NodeLevel;
|
use crate::context::NodeLevel;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, Parentheses, Parenthesize};
|
use crate::expression::parentheses::{NeedsParentheses, Parentheses, Parenthesize};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -51,7 +52,11 @@ impl FormatRuleWithOptions<Expr, PyFormatContext<'_>> for FormatExpr {
|
||||||
|
|
||||||
impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
|
impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
|
||||||
fn fmt(&self, item: &Expr, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt(&self, item: &Expr, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
let parentheses = item.needs_parentheses(self.parenthesize, f.context().contents());
|
let parentheses = item.needs_parentheses(
|
||||||
|
self.parenthesize,
|
||||||
|
f.context().contents(),
|
||||||
|
f.context().comments(),
|
||||||
|
);
|
||||||
|
|
||||||
let format_expr = format_with(|f| match item {
|
let format_expr = format_with(|f| match item {
|
||||||
Expr::BoolOp(expr) => expr.format().fmt(f),
|
Expr::BoolOp(expr) => expr.format().fmt(f),
|
||||||
|
@ -118,35 +123,40 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for Expr {
|
impl NeedsParentheses for Expr {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses {
|
fn needs_parentheses(
|
||||||
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses {
|
||||||
match self {
|
match self {
|
||||||
Expr::BoolOp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::BoolOp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::NamedExpr(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::NamedExpr(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::BinOp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::BinOp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::UnaryOp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::UnaryOp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Lambda(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Lambda(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::IfExp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::IfExp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Dict(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Dict(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Set(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Set(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::ListComp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::ListComp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::SetComp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::SetComp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::DictComp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::DictComp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::GeneratorExp(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::GeneratorExp(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Await(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Await(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Yield(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Yield(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::YieldFrom(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::YieldFrom(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Compare(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Compare(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Call(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Call(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::FormattedValue(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::FormattedValue(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::JoinedStr(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::JoinedStr(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Constant(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Constant(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Attribute(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Attribute(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Subscript(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Subscript(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Starred(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Starred(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Name(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Name(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::List(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::List(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Tuple(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Tuple(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
Expr::Slice(expr) => expr.needs_parentheses(parenthesize, source),
|
Expr::Slice(expr) => expr.needs_parentheses(parenthesize, source, comments),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
|
use crate::comments::Comments;
|
||||||
use crate::trivia::{first_non_trivia_token, first_non_trivia_token_rev, Token, TokenKind};
|
use crate::trivia::{first_non_trivia_token, first_non_trivia_token_rev, Token, TokenKind};
|
||||||
use ruff_python_ast::node::AnyNodeRef;
|
use ruff_python_ast::node::AnyNodeRef;
|
||||||
use rustpython_parser::ast::Ranged;
|
use rustpython_parser::ast::Ranged;
|
||||||
|
|
||||||
pub(crate) trait NeedsParentheses {
|
pub(crate) trait NeedsParentheses {
|
||||||
fn needs_parentheses(&self, parenthesize: Parenthesize, source: &str) -> Parentheses;
|
fn needs_parentheses(
|
||||||
|
&self,
|
||||||
|
parenthesize: Parenthesize,
|
||||||
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
|
) -> Parentheses;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn default_expression_needs_parentheses(
|
pub(super) fn default_expression_needs_parentheses(
|
||||||
node: AnyNodeRef,
|
node: AnyNodeRef,
|
||||||
parenthesize: Parenthesize,
|
parenthesize: Parenthesize,
|
||||||
source: &str,
|
source: &str,
|
||||||
|
comments: &Comments,
|
||||||
) -> Parentheses {
|
) -> Parentheses {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
node.is_expression(),
|
node.is_expression(),
|
||||||
|
@ -20,9 +27,14 @@ pub(super) fn default_expression_needs_parentheses(
|
||||||
if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) {
|
if !parenthesize.is_if_breaks() && is_expression_parenthesized(node, source) {
|
||||||
Parentheses::Always
|
Parentheses::Always
|
||||||
}
|
}
|
||||||
// `Optional` or `IfBreaks`: Add parentheses if the expression doesn't fit on a line
|
// `Optional` or `IfBreaks`: Add parentheses if the expression doesn't fit on a line but enforce
|
||||||
|
// parentheses if the expression has leading comments
|
||||||
else if !parenthesize.is_preserve() {
|
else if !parenthesize.is_preserve() {
|
||||||
Parentheses::Optional
|
if comments.has_leading_comments(node) {
|
||||||
|
Parentheses::Always
|
||||||
|
} else {
|
||||||
|
Parentheses::Optional
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//`Preserve` and expression has no parentheses in the source code
|
//`Preserve` and expression has no parentheses in the source code
|
||||||
Parentheses::Never
|
Parentheses::Never
|
||||||
|
|
|
@ -2858,3 +2858,35 @@ impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::MatchCase {
|
||||||
FormatOwnedWithRule::new(self, crate::other::match_case::FormatMatchCase::default())
|
FormatOwnedWithRule::new(self, crate::other::match_case::FormatMatchCase::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FormatRule<ast::Decorator, PyFormatContext<'_>> for crate::other::decorator::FormatDecorator {
|
||||||
|
#[inline]
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
node: &ast::Decorator,
|
||||||
|
f: &mut Formatter<PyFormatContext<'_>>,
|
||||||
|
) -> FormatResult<()> {
|
||||||
|
FormatNodeRule::<ast::Decorator>::fmt(self, node, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'ast> AsFormat<PyFormatContext<'ast>> for ast::Decorator {
|
||||||
|
type Format<'a> = FormatRefWithRule<
|
||||||
|
'a,
|
||||||
|
ast::Decorator,
|
||||||
|
crate::other::decorator::FormatDecorator,
|
||||||
|
PyFormatContext<'ast>,
|
||||||
|
>;
|
||||||
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
FormatRefWithRule::new(self, crate::other::decorator::FormatDecorator::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'ast> IntoFormat<PyFormatContext<'ast>> for ast::Decorator {
|
||||||
|
type Format = FormatOwnedWithRule<
|
||||||
|
ast::Decorator,
|
||||||
|
crate::other::decorator::FormatDecorator,
|
||||||
|
PyFormatContext<'ast>,
|
||||||
|
>;
|
||||||
|
fn into_format(self) -> Self::Format {
|
||||||
|
FormatOwnedWithRule::new(self, crate::other::decorator::FormatDecorator::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -225,18 +225,16 @@ impl Format<PyFormatContext<'_>> for VerbatimText {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fmt::{Formatter, Write};
|
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
|
use ruff_python_ast::source_code::CommentRangesBuilder;
|
||||||
|
use ruff_testing_macros::fixture;
|
||||||
use rustpython_parser::lexer::lex;
|
use rustpython_parser::lexer::lex;
|
||||||
use rustpython_parser::{parse_tokens, Mode};
|
use rustpython_parser::{parse_tokens, Mode};
|
||||||
use similar::TextDiff;
|
use similar::TextDiff;
|
||||||
|
use std::fmt::{Formatter, Write};
|
||||||
use ruff_python_ast::source_code::CommentRangesBuilder;
|
use std::fs;
|
||||||
use ruff_testing_macros::fixture;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{format_module, format_node};
|
use crate::{format_module, format_node};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,66 @@
|
||||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
use crate::comments::leading_node_comments;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::prelude::*;
|
||||||
|
use crate::FormatNodeRule;
|
||||||
|
use ruff_formatter::{write, FormatRuleWithOptions};
|
||||||
|
use ruff_text_size::{TextLen, TextRange};
|
||||||
use rustpython_parser::ast::Arg;
|
use rustpython_parser::ast::Arg;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatArg;
|
pub struct FormatArg {
|
||||||
|
kind: ArgumentKind,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
|
pub enum ArgumentKind {
|
||||||
|
/// Positional only, regular argument, or a keyword only argument.
|
||||||
|
#[default]
|
||||||
|
Normal,
|
||||||
|
/// A `*args` arguments
|
||||||
|
Varg,
|
||||||
|
/// A `**kwargs` argument
|
||||||
|
Kwarg,
|
||||||
|
}
|
||||||
|
|
||||||
impl FormatNodeRule<Arg> for FormatArg {
|
impl FormatNodeRule<Arg> for FormatArg {
|
||||||
fn fmt_fields(&self, item: &Arg, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &Arg, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented(item)])
|
let Arg {
|
||||||
|
range,
|
||||||
|
arg,
|
||||||
|
annotation,
|
||||||
|
type_comment: _,
|
||||||
|
} = item;
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
// The name of the argument
|
||||||
|
source_text_slice(
|
||||||
|
TextRange::at(range.start(), arg.text_len()),
|
||||||
|
ContainsNewlines::No
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if let Some(annotation) = annotation {
|
||||||
|
write!(f, [text(":"), space(), annotation.format()])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fmt_leading_comments(&self, node: &Arg, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
|
match self.kind {
|
||||||
|
ArgumentKind::Normal => leading_node_comments(node).fmt(f),
|
||||||
|
// Formatted as part of the `Arguments` to avoid emitting leading comments between the `*` and the argument.
|
||||||
|
ArgumentKind::Kwarg | ArgumentKind::Varg => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FormatRuleWithOptions<Arg, PyFormatContext<'_>> for FormatArg {
|
||||||
|
type Options = ArgumentKind;
|
||||||
|
|
||||||
|
fn with_options(mut self, options: Self::Options) -> Self {
|
||||||
|
self.kind = options;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,189 @@
|
||||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
use crate::comments::{dangling_node_comments, leading_node_comments};
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::context::NodeLevel;
|
||||||
use rustpython_parser::ast::Arguments;
|
use crate::other::arg::ArgumentKind;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::trivia::{first_non_trivia_token, SimpleTokenizer, Token, TokenKind};
|
||||||
|
use crate::FormatNodeRule;
|
||||||
|
use ruff_formatter::{format_args, write, FormatError};
|
||||||
|
use ruff_python_ast::node::{AnyNodeRef, AstNode};
|
||||||
|
use rustpython_parser::ast::{Arg, Arguments, Expr, Ranged};
|
||||||
|
use std::usize;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatArguments;
|
pub struct FormatArguments;
|
||||||
|
|
||||||
impl FormatNodeRule<Arguments> for FormatArguments {
|
impl FormatNodeRule<Arguments> for FormatArguments {
|
||||||
fn fmt_fields(&self, item: &Arguments, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &Arguments, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented(item)])
|
let Arguments {
|
||||||
|
range: _,
|
||||||
|
posonlyargs,
|
||||||
|
args,
|
||||||
|
defaults,
|
||||||
|
vararg,
|
||||||
|
kwonlyargs,
|
||||||
|
kw_defaults,
|
||||||
|
kwarg,
|
||||||
|
} = item;
|
||||||
|
|
||||||
|
let saved_level = f.context().node_level();
|
||||||
|
f.context_mut().set_node_level(NodeLevel::Expression);
|
||||||
|
|
||||||
|
let format_inner = format_with(|f: &mut PyFormatter| {
|
||||||
|
let separator = format_with(|f| write!(f, [text(","), soft_line_break_or_space()]));
|
||||||
|
let mut joiner = f.join_with(separator);
|
||||||
|
let mut last_node: Option<AnyNodeRef> = None;
|
||||||
|
|
||||||
|
let mut defaults = std::iter::repeat(None)
|
||||||
|
.take(posonlyargs.len() + args.len() - defaults.len())
|
||||||
|
.chain(defaults.iter().map(Some));
|
||||||
|
|
||||||
|
for positional in posonlyargs {
|
||||||
|
let default = defaults.next().ok_or(FormatError::SyntaxError)?;
|
||||||
|
joiner.entry(&ArgumentWithDefault {
|
||||||
|
argument: positional,
|
||||||
|
default,
|
||||||
|
});
|
||||||
|
|
||||||
|
last_node = Some(default.map_or_else(|| positional.into(), AnyNodeRef::from));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !posonlyargs.is_empty() {
|
||||||
|
joiner.entry(&text("/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for argument in args {
|
||||||
|
let default = defaults.next().ok_or(FormatError::SyntaxError)?;
|
||||||
|
|
||||||
|
joiner.entry(&ArgumentWithDefault { argument, default });
|
||||||
|
|
||||||
|
last_node = Some(default.map_or_else(|| argument.into(), AnyNodeRef::from));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(vararg) = vararg {
|
||||||
|
joiner.entry(&format_args![
|
||||||
|
leading_node_comments(vararg.as_ref()),
|
||||||
|
text("*"),
|
||||||
|
vararg.format().with_options(ArgumentKind::Varg)
|
||||||
|
]);
|
||||||
|
last_node = Some(vararg.as_any_node_ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_assert!(defaults.next().is_none());
|
||||||
|
|
||||||
|
let mut defaults = std::iter::repeat(None)
|
||||||
|
.take(kwonlyargs.len() - kw_defaults.len())
|
||||||
|
.chain(kw_defaults.iter().map(Some));
|
||||||
|
|
||||||
|
for keyword_argument in kwonlyargs {
|
||||||
|
let default = defaults.next().ok_or(FormatError::SyntaxError)?;
|
||||||
|
joiner.entry(&ArgumentWithDefault {
|
||||||
|
argument: keyword_argument,
|
||||||
|
default,
|
||||||
|
});
|
||||||
|
|
||||||
|
last_node = Some(default.map_or_else(|| keyword_argument.into(), AnyNodeRef::from));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_assert!(defaults.next().is_none());
|
||||||
|
|
||||||
|
if let Some(kwarg) = kwarg {
|
||||||
|
joiner.entry(&format_args![
|
||||||
|
leading_node_comments(kwarg.as_ref()),
|
||||||
|
text("**"),
|
||||||
|
kwarg.format().with_options(ArgumentKind::Kwarg)
|
||||||
|
]);
|
||||||
|
last_node = Some(kwarg.as_any_node_ref());
|
||||||
|
}
|
||||||
|
|
||||||
|
joiner.finish()?;
|
||||||
|
|
||||||
|
write!(f, [if_group_breaks(&text(","))])?;
|
||||||
|
|
||||||
|
// Expand the group if the source has a trailing *magic* comma.
|
||||||
|
if let Some(last_node) = last_node {
|
||||||
|
let ends_with_pos_only_argument_separator = !posonlyargs.is_empty()
|
||||||
|
&& args.is_empty()
|
||||||
|
&& vararg.is_none()
|
||||||
|
&& kwonlyargs.is_empty()
|
||||||
|
&& kwarg.is_none();
|
||||||
|
|
||||||
|
let maybe_comma_token = if ends_with_pos_only_argument_separator {
|
||||||
|
// `def a(b, c, /): ... `
|
||||||
|
let mut tokens =
|
||||||
|
SimpleTokenizer::starts_at(last_node.end(), f.context().contents())
|
||||||
|
.skip_trivia();
|
||||||
|
|
||||||
|
let comma = tokens.next();
|
||||||
|
assert!(matches!(comma, Some(Token { kind: TokenKind::Comma, .. })), "The last positional only argument must be separated by a `,` from the positional only arguments separator `/` but found '{comma:?}'.");
|
||||||
|
|
||||||
|
let slash = tokens.next();
|
||||||
|
assert!(matches!(slash, Some(Token { kind: TokenKind::Slash, .. })), "The positional argument separator must be present for a function that has positional only arguments but found '{slash:?}'.");
|
||||||
|
|
||||||
|
tokens.next()
|
||||||
|
} else {
|
||||||
|
first_non_trivia_token(last_node.end(), f.context().contents())
|
||||||
|
};
|
||||||
|
|
||||||
|
if maybe_comma_token.map_or(false, |token| token.kind() == TokenKind::Comma) {
|
||||||
|
write!(f, [hard_line_break()])?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
let num_arguments = posonlyargs.len()
|
||||||
|
+ args.len()
|
||||||
|
+ usize::from(vararg.is_some())
|
||||||
|
+ kwonlyargs.len()
|
||||||
|
+ usize::from(kwarg.is_some());
|
||||||
|
|
||||||
|
if num_arguments == 0 {
|
||||||
|
// No arguments, format any dangling comments between `()`
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
text("("),
|
||||||
|
block_indent(&dangling_node_comments(item)),
|
||||||
|
text(")")
|
||||||
|
]
|
||||||
|
)?;
|
||||||
|
} else {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[group(&format_args!(
|
||||||
|
text("("),
|
||||||
|
soft_block_indent(&group(&format_inner)),
|
||||||
|
text(")")
|
||||||
|
))]
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
f.context_mut().set_node_level(saved_level);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fmt_dangling_comments(&self, _node: &Arguments, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
|
// Handled in `fmt_fields`
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ArgumentWithDefault<'a> {
|
||||||
|
argument: &'a Arg,
|
||||||
|
default: Option<&'a Expr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Format<PyFormatContext<'_>> for ArgumentWithDefault<'_> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
||||||
|
write!(f, [self.argument.format()])?;
|
||||||
|
|
||||||
|
if let Some(default) = self.default {
|
||||||
|
let space = self.argument.annotation.is_some().then_some(space());
|
||||||
|
write!(f, [space, text("="), space, default.format()])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
crates/ruff_python_formatter/src/other/decorator.rs
Normal file
25
crates/ruff_python_formatter/src/other/decorator.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use crate::expression::parentheses::Parenthesize;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::FormatNodeRule;
|
||||||
|
use ruff_formatter::write;
|
||||||
|
use rustpython_parser::ast::Decorator;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct FormatDecorator;
|
||||||
|
|
||||||
|
impl FormatNodeRule<Decorator> for FormatDecorator {
|
||||||
|
fn fmt_fields(&self, item: &Decorator, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
|
let Decorator {
|
||||||
|
expression,
|
||||||
|
range: _,
|
||||||
|
} = item;
|
||||||
|
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
text("@"),
|
||||||
|
expression.format().with_options(Parenthesize::Optional)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ pub(crate) mod alias;
|
||||||
pub(crate) mod arg;
|
pub(crate) mod arg;
|
||||||
pub(crate) mod arguments;
|
pub(crate) mod arguments;
|
||||||
pub(crate) mod comprehension;
|
pub(crate) mod comprehension;
|
||||||
|
pub(crate) mod decorator;
|
||||||
pub(crate) mod excepthandler_except_handler;
|
pub(crate) mod excepthandler_except_handler;
|
||||||
pub(crate) mod keyword;
|
pub(crate) mod keyword;
|
||||||
pub(crate) mod match_case;
|
pub(crate) mod match_case;
|
||||||
|
|
|
@ -36,16 +36,16 @@ class NormalClass (
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,30 +1,16 @@
|
@@ -1,18 +1,10 @@
|
||||||
-class SimpleClassWithBlankParentheses:
|
-class SimpleClassWithBlankParentheses:
|
||||||
- pass
|
- pass
|
||||||
-
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-class ClassWithSpaceParentheses:
|
-class ClassWithSpaceParentheses:
|
||||||
- first_test_data = 90
|
- first_test_data = 90
|
||||||
- second_test_data = 100
|
- second_test_data = 100
|
||||||
|
-
|
||||||
- def test_func(self):
|
- def test_func(self):
|
||||||
- return None
|
- return None
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
@ -57,15 +57,14 @@ class NormalClass (
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-def public_func_with_blank_parentheses():
|
def public_func_with_blank_parentheses():
|
||||||
- return None
|
@@ -20,11 +12,7 @@
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def class_under_the_func_with_blank_parentheses():
|
def class_under_the_func_with_blank_parentheses():
|
||||||
- class InsideFunc:
|
- class InsideFunc:
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-class NormalClass:
|
-class NormalClass:
|
||||||
|
@ -87,10 +86,12 @@ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def public_func_with_blank_parentheses():
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def class_under_the_func_with_blank_parentheses():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
|
@ -22,24 +22,30 @@ def bobtwo(): \
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,6 +1,4 @@
|
@@ -1,6 +1,8 @@
|
||||||
-def bob(): # pylint: disable=W9016
|
-def bob(): # pylint: disable=W9016
|
||||||
- pass
|
+def bob():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ # pylint: disable=W9016
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def bobtwo(): # some comment here
|
-def bobtwo(): # some comment here
|
||||||
- pass
|
+def bobtwo():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ # some comment here
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def bob():
|
||||||
|
# pylint: disable=W9016
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def bobtwo():
|
||||||
|
# some comment here
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -227,7 +227,7 @@ instruction()#comment with bad spacing
|
||||||
]
|
]
|
||||||
|
|
||||||
not_shareables = [
|
not_shareables = [
|
||||||
@@ -37,129 +33,28 @@
|
@@ -37,51 +33,24 @@
|
||||||
# builtin types and objects
|
# builtin types and objects
|
||||||
type,
|
type,
|
||||||
object,
|
object,
|
||||||
|
@ -258,7 +258,7 @@ instruction()#comment with bad spacing
|
||||||
|
|
||||||
|
|
||||||
# Comment before function.
|
# Comment before function.
|
||||||
-def inline_comments_in_brackets_ruin_everything():
|
def inline_comments_in_brackets_ruin_everything():
|
||||||
- if typedargslist:
|
- if typedargslist:
|
||||||
- parameters.children = [children[0], body, children[-1]] # (1 # )1
|
- parameters.children = [children[0], body, children[-1]] # (1 # )1
|
||||||
- parameters.children = [
|
- parameters.children = [
|
||||||
|
@ -282,15 +282,15 @@ instruction()#comment with bad spacing
|
||||||
- and self._proc.poll() is None
|
- and self._proc.poll() is None
|
||||||
- ):
|
- ):
|
||||||
- pass
|
- pass
|
||||||
- # no newline before or after
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
- short = [
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
- # one
|
# no newline before or after
|
||||||
- 1,
|
short = [
|
||||||
- # two
|
# one
|
||||||
- 2,
|
@@ -91,75 +60,26 @@
|
||||||
- ]
|
]
|
||||||
-
|
|
||||||
- # no newline after
|
# no newline after
|
||||||
- call(
|
- call(
|
||||||
- arg1,
|
- arg1,
|
||||||
- arg2,
|
- arg2,
|
||||||
|
@ -299,9 +299,10 @@ instruction()#comment with bad spacing
|
||||||
-""",
|
-""",
|
||||||
- arg3=True,
|
- arg3=True,
|
||||||
- )
|
- )
|
||||||
-
|
+ NOT_IMPLEMENTED_call()
|
||||||
- ############################################################################
|
|
||||||
-
|
############################################################################
|
||||||
|
|
||||||
- call2(
|
- call2(
|
||||||
- # short
|
- # short
|
||||||
- arg1,
|
- arg1,
|
||||||
|
@ -333,19 +334,24 @@ instruction()#comment with bad spacing
|
||||||
- # right
|
- # right
|
||||||
- if element is not None
|
- if element is not None
|
||||||
- ]
|
- ]
|
||||||
- while True:
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ lcomp = [i for i in []]
|
||||||
|
+ lcomp2 = [i for i in []]
|
||||||
|
+ lcomp3 = [i for i in []]
|
||||||
|
while True:
|
||||||
- if False:
|
- if False:
|
||||||
- continue
|
- continue
|
||||||
-
|
-
|
||||||
- # and round and round we go
|
- # and round and round we go
|
||||||
- # and round and round we go
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
-
|
# and round and round we go
|
||||||
- # let's return
|
|
||||||
|
# let's return
|
||||||
- return Node(
|
- return Node(
|
||||||
- syms.simple_stmt,
|
- syms.simple_stmt,
|
||||||
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
|
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-CONFIG_FILES = (
|
-CONFIG_FILES = (
|
||||||
|
@ -366,7 +372,7 @@ instruction()#comment with bad spacing
|
||||||
|
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
@@ -167,7 +62,7 @@
|
@@ -167,7 +87,7 @@
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,7 +436,32 @@ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
# Comment before function.
|
# Comment before function.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def inline_comments_in_brackets_ruin_everything():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
# no newline before or after
|
||||||
|
short = [
|
||||||
|
# one
|
||||||
|
1,
|
||||||
|
# two
|
||||||
|
2,
|
||||||
|
]
|
||||||
|
|
||||||
|
# no newline after
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
lcomp = [i for i in []]
|
||||||
|
lcomp2 = [i for i in []]
|
||||||
|
lcomp3 = [i for i in []]
|
||||||
|
while True:
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
# and round and round we go
|
||||||
|
|
||||||
|
# let's return
|
||||||
|
return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||||
|
|
|
@ -61,11 +61,10 @@ def func():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -2,47 +2,7 @@
|
@@ -3,46 +3,13 @@
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
-def func():
|
def func():
|
||||||
- x = """
|
- x = """
|
||||||
- a really long string
|
- a really long string
|
||||||
- """
|
- """
|
||||||
|
@ -77,7 +76,9 @@ def func():
|
||||||
- # right
|
- # right
|
||||||
- if element is not None
|
- if element is not None
|
||||||
- ]
|
- ]
|
||||||
- # Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
+ 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 isinstance(exc_value, MultiError):
|
- if isinstance(exc_value, MultiError):
|
||||||
- embedded = []
|
- embedded = []
|
||||||
- for exc in exc_value.exceptions:
|
- for exc in exc_value.exceptions:
|
||||||
|
@ -95,8 +96,9 @@ def func():
|
||||||
- )
|
- )
|
||||||
- # This should be left alone (after)
|
- # This should be left alone (after)
|
||||||
- )
|
- )
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
- # everything is fine if the expression isn't nested
|
|
||||||
|
# everything is fine if the expression isn't nested
|
||||||
- traceback.TracebackException.from_exception(
|
- traceback.TracebackException.from_exception(
|
||||||
- exc,
|
- exc,
|
||||||
- limit=limit,
|
- limit=limit,
|
||||||
|
@ -106,7 +108,7 @@ def func():
|
||||||
- # shared between sub-exceptions are not omitted
|
- # shared between sub-exceptions are not omitted
|
||||||
- _seen=set(_seen),
|
- _seen=set(_seen),
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
@ -119,7 +121,14 @@ def func():
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
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
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
# everything is fine if the expression isn't nested
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
|
|
@ -107,7 +107,7 @@ def foo3(list_a, list_b):
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,94 +1,14 @@
|
@@ -1,94 +1,22 @@
|
||||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||||
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||||
-)
|
-)
|
||||||
|
@ -169,7 +169,7 @@ def foo3(list_a, list_b):
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-def foo(list_a, list_b):
|
def foo(list_a, list_b):
|
||||||
- results = (
|
- results = (
|
||||||
- User.query.filter(User.foo == "bar")
|
- User.query.filter(User.foo == "bar")
|
||||||
- .filter( # Because foo.
|
- .filter( # Because foo.
|
||||||
|
@ -182,12 +182,12 @@ def foo3(list_a, list_b):
|
||||||
- .with_for_update(key_share=True)
|
- .with_for_update(key_share=True)
|
||||||
- .all()
|
- .all()
|
||||||
- )
|
- )
|
||||||
- return results
|
+ results = NOT_IMPLEMENTED_call()
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
return results
|
||||||
|
|
||||||
|
|
||||||
-def foo2(list_a, list_b):
|
def foo2(list_a, list_b):
|
||||||
- # Standalone comment reasonably placed.
|
# Standalone comment reasonably placed.
|
||||||
- return (
|
- return (
|
||||||
- User.query.filter(User.foo == "bar")
|
- User.query.filter(User.foo == "bar")
|
||||||
- .filter(
|
- .filter(
|
||||||
|
@ -195,19 +195,19 @@ def foo3(list_a, list_b):
|
||||||
- )
|
- )
|
||||||
- .filter(User.xyz.is_(None))
|
- .filter(User.xyz.is_(None))
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def foo3(list_a, list_b):
|
def foo3(list_a, list_b):
|
||||||
- return (
|
return (
|
||||||
- # Standalone comment but weirdly placed.
|
# Standalone comment but weirdly placed.
|
||||||
- User.query.filter(User.foo == "bar")
|
- User.query.filter(User.foo == "bar")
|
||||||
- .filter(
|
- .filter(
|
||||||
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||||
- )
|
- )
|
||||||
- .filter(User.xyz.is_(None))
|
- .filter(User.xyz.is_(None))
|
||||||
- )
|
+ NOT_IMPLEMENTED_call()
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -220,13 +220,21 @@ NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo(list_a, list_b):
|
||||||
|
results = NOT_IMPLEMENTED_call()
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo2(list_a, list_b):
|
||||||
|
# Standalone comment reasonably placed.
|
||||||
|
return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo3(list_a, list_b):
|
||||||
|
return (
|
||||||
|
# Standalone comment but weirdly placed.
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -86,7 +86,7 @@ if __name__ == "__main__":
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,61 +1,33 @@
|
@@ -1,33 +1,18 @@
|
||||||
while True:
|
while True:
|
||||||
- if something.changed:
|
- if something.changed:
|
||||||
- do.stuff() # trailing comment
|
- do.stuff() # trailing comment
|
||||||
|
@ -97,72 +97,54 @@ if __name__ == "__main__":
|
||||||
# Should this one, too? I guess so.
|
# Should this one, too? I guess so.
|
||||||
|
|
||||||
# This one is properly standalone now.
|
# This one is properly standalone now.
|
||||||
-
|
|
||||||
-for i in range(100):
|
-for i in range(100):
|
||||||
- # first we do this
|
- # first we do this
|
||||||
- if i % 33 == 0:
|
- if i % 33 == 0:
|
||||||
- break
|
- break
|
||||||
-
|
+NOT_YET_IMPLEMENTED_StmtFor
|
||||||
|
|
||||||
- # then we do this
|
- # then we do this
|
||||||
- print(i)
|
- print(i)
|
||||||
- # and finally we loop around
|
- # and finally we loop around
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtWith
|
||||||
|
|
||||||
-with open(some_temp_file) as f:
|
-with open(some_temp_file) as f:
|
||||||
- data = f.read()
|
- data = f.read()
|
||||||
+NOT_YET_IMPLEMENTED_StmtFor
|
+NOT_YET_IMPLEMENTED_StmtTry
|
||||||
|
|
||||||
-try:
|
-try:
|
||||||
- with open(some_other_file) as w:
|
- with open(some_other_file) as w:
|
||||||
- w.write(data)
|
- w.write(data)
|
||||||
+NOT_YET_IMPLEMENTED_StmtWith
|
-
|
||||||
|
|
||||||
-except OSError:
|
-except OSError:
|
||||||
- print("problems")
|
- print("problems")
|
||||||
+NOT_YET_IMPLEMENTED_StmtTry
|
-
|
||||||
|
|
||||||
-import sys
|
-import sys
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
# leading function comment
|
# leading function comment
|
||||||
-def wat():
|
@@ -42,7 +27,7 @@
|
||||||
- ...
|
|
||||||
- # trailing function comment
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# SECTION COMMENT
|
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
-@deco1
|
@deco1
|
||||||
-# leading 2
|
# leading 2
|
||||||
-@deco2(with_args=True)
|
-@deco2(with_args=True)
|
||||||
-# leading 3
|
+@NOT_IMPLEMENTED_call()
|
||||||
-@deco3
|
# leading 3
|
||||||
-def decorated1():
|
@deco3
|
||||||
- ...
|
def decorated1():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@@ -52,7 +37,7 @@
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
-@deco1
|
@deco1
|
||||||
-# leading 2
|
# leading 2
|
||||||
-@deco2(with_args=True)
|
-@deco2(with_args=True)
|
||||||
-# leading function comment
|
+@NOT_IMPLEMENTED_call()
|
||||||
-def decorated1():
|
# leading function comment
|
||||||
- ...
|
def decorated1():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
...
|
||||||
|
@@ -69,5 +54,4 @@
|
||||||
|
...
|
||||||
# Note: this is fixed in
|
|
||||||
@@ -65,9 +37,7 @@
|
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
|
||||||
-def g():
|
|
||||||
- ...
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-if __name__ == "__main__":
|
-if __name__ == "__main__":
|
||||||
|
@ -191,18 +173,31 @@ NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
# leading function comment
|
# leading function comment
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def wat():
|
||||||
|
...
|
||||||
|
# trailing function comment
|
||||||
|
|
||||||
|
|
||||||
# SECTION COMMENT
|
# SECTION COMMENT
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
def decorated1():
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
# leading function comment
|
||||||
|
def decorated1():
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
# Note: this is fixed in
|
# Note: this is fixed in
|
||||||
|
@ -212,7 +207,8 @@ some_instruction
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def g():
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtIf
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
|
@ -131,103 +131,38 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,118 +1,40 @@
|
@@ -1,4 +1,4 @@
|
||||||
-from typing import Any, Tuple
|
-from typing import Any, Tuple
|
||||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
def f(
|
||||||
- a, # type: int
|
@@ -49,15 +49,10 @@
|
||||||
-):
|
element = 0 # type: int
|
||||||
- pass
|
another_element = 1 # type: float
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
another_element_with_long_name = 2 # type: int
|
||||||
|
|
||||||
|
|
||||||
# test type comments
|
|
||||||
-def f(a, b, c, d, e, f, g, h, i):
|
|
||||||
- # type: (int, int, int, int, int, int, int, int, int) -> None
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
|
||||||
- a, # type: int
|
|
||||||
- b, # type: int
|
|
||||||
- c, # type: int
|
|
||||||
- d, # type: int
|
|
||||||
- e, # type: int
|
|
||||||
- f, # type: int
|
|
||||||
- g, # type: int
|
|
||||||
- h, # type: int
|
|
||||||
- i, # type: int
|
|
||||||
-):
|
|
||||||
- # type: (...) -> None
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
|
||||||
- arg, # type: int
|
|
||||||
- *args, # type: *Any
|
|
||||||
- default=False, # type: bool
|
|
||||||
- **kwargs, # type: **Any
|
|
||||||
-):
|
|
||||||
- # type: (...) -> None
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
|
||||||
- a, # type: int
|
|
||||||
- b, # type: int
|
|
||||||
- c, # type: int
|
|
||||||
- d, # type: int
|
|
||||||
-):
|
|
||||||
- # type: (...) -> None
|
|
||||||
-
|
|
||||||
- element = 0 # type: int
|
|
||||||
- another_element = 1 # type: float
|
|
||||||
- another_element_with_long_name = 2 # type: int
|
|
||||||
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = (
|
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = (
|
||||||
- 3
|
- 3
|
||||||
- ) # type: int
|
- ) # type: int
|
||||||
- an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
- an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int
|
||||||
|
+ an_element_with_a_long_value = NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 # type: bool
|
||||||
|
|
||||||
- tup = (
|
- tup = (
|
||||||
- another_element,
|
- another_element,
|
||||||
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||||
- ) # type: Tuple[int, int]
|
- ) # type: Tuple[int, int]
|
||||||
|
+ tup = (1, 2) # type: Tuple[int, int]
|
||||||
|
|
||||||
- a = (
|
a = (
|
||||||
- element
|
element
|
||||||
- + another_element
|
@@ -84,35 +79,22 @@
|
||||||
- + another_element_with_long_name
|
|
||||||
- + element
|
|
||||||
- + another_element
|
|
||||||
- + another_element_with_long_name
|
|
||||||
- ) # type: int
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
def func(
|
||||||
- x, # not a type comment
|
|
||||||
- y, # type: int
|
|
||||||
-):
|
|
||||||
- # type: (...) -> None
|
|
||||||
- pass
|
|
||||||
-
|
|
||||||
-
|
|
||||||
-def f(
|
|
||||||
- x, # not a type comment
|
|
||||||
-): # type: (int) -> None
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def func(
|
|
||||||
- a=some_list[0], # type: int
|
- a=some_list[0], # type: int
|
||||||
-): # type: () -> int
|
+ a=NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: int
|
||||||
|
): # type: () -> int
|
||||||
- c = call(
|
- c = call(
|
||||||
- 0.0123,
|
- 0.0123,
|
||||||
- 0.0456,
|
- 0.0456,
|
||||||
|
@ -240,17 +175,20 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||||
- 0.0789,
|
- 0.0789,
|
||||||
- a[-1], # type: ignore
|
- a[-1], # type: ignore
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ c = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
- c = call(
|
- c = call(
|
||||||
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||||
- )
|
- )
|
||||||
|
+ c = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
+result = "NOT_YET_IMPLEMENTED_STRING" # aaa
|
|
||||||
|
|
||||||
-result = ( # aaa
|
-result = ( # aaa
|
||||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
-)
|
-)
|
||||||
|
+result = "NOT_YET_IMPLEMENTED_STRING" # aaa
|
||||||
|
|
||||||
|
-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||||
+AAAAAAAAAAAAA = (
|
+AAAAAAAAAAAAA = (
|
||||||
+ [AAAAAAAAAAAAA]
|
+ [AAAAAAAAAAAAA]
|
||||||
+ + SHARED_AAAAAAAAAAAAA
|
+ + SHARED_AAAAAAAAAAAAA
|
||||||
|
@ -258,14 +196,12 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||||
+ + AAAAAAAAAAAAA
|
+ + AAAAAAAAAAAAA
|
||||||
+) # type: ignore
|
+) # type: ignore
|
||||||
|
|
||||||
-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
|
||||||
+NOT_IMPLEMENTED_call()
|
|
||||||
|
|
||||||
-call_to_some_function_asdf(
|
-call_to_some_function_asdf(
|
||||||
- foo,
|
- foo,
|
||||||
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||||
-)
|
-)
|
||||||
-
|
+NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||||
+(1, 2) = NOT_IMPLEMENTED_call() # type: ignore[arg-type]
|
+(1, 2) = NOT_IMPLEMENTED_call() # type: ignore[arg-type]
|
||||||
```
|
```
|
||||||
|
@ -276,29 +212,89 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a, # type: int
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# test type comments
|
# test type comments
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(a, b, c, d, e, f, g, h, i):
|
||||||
|
# type: (int, int, int, int, int, int, int, int, int) -> None
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a, # type: int
|
||||||
|
b, # type: int
|
||||||
|
c, # type: int
|
||||||
|
d, # type: int
|
||||||
|
e, # type: int
|
||||||
|
f, # type: int
|
||||||
|
g, # type: int
|
||||||
|
h, # type: int
|
||||||
|
i, # type: int
|
||||||
|
):
|
||||||
|
# type: (...) -> None
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
arg, # type: int
|
||||||
|
*args, # type: *Any
|
||||||
|
default=False, # type: bool
|
||||||
|
**kwargs, # type: **Any
|
||||||
|
):
|
||||||
|
# type: (...) -> None
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a, # type: int
|
||||||
|
b, # type: int
|
||||||
|
c, # type: int
|
||||||
|
d, # type: int
|
||||||
|
):
|
||||||
|
# type: (...) -> None
|
||||||
|
|
||||||
|
element = 0 # type: int
|
||||||
|
another_element = 1 # type: float
|
||||||
|
another_element_with_long_name = 2 # type: int
|
||||||
|
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = 3 # type: int
|
||||||
|
an_element_with_a_long_value = NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2 # type: bool
|
||||||
|
|
||||||
|
tup = (1, 2) # type: Tuple[int, int]
|
||||||
|
|
||||||
|
a = (
|
||||||
|
element
|
||||||
|
+ another_element
|
||||||
|
+ another_element_with_long_name
|
||||||
|
+ element
|
||||||
|
+ another_element
|
||||||
|
+ another_element_with_long_name
|
||||||
|
) # type: int
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
x, # not a type comment
|
||||||
|
y, # type: int
|
||||||
|
):
|
||||||
|
# type: (...) -> None
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
x, # not a type comment
|
||||||
|
): # type: (int) -> None
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func(
|
||||||
|
a=NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key], # type: int
|
||||||
|
): # type: () -> int
|
||||||
|
c = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
c = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
result = "NOT_YET_IMPLEMENTED_STRING" # aaa
|
result = "NOT_YET_IMPLEMENTED_STRING" # aaa
|
||||||
|
|
|
@ -152,35 +152,7 @@ def bar():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -4,8 +4,7 @@
|
@@ -30,8 +30,7 @@
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from the statement above by two lines.
|
|
||||||
-def function():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
|
||||||
@@ -14,24 +13,21 @@
|
|
||||||
# This multiline comments section
|
|
||||||
# should be split from the statement
|
|
||||||
# above by two lines.
|
|
||||||
-def function():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from the statement above by two lines.
|
|
||||||
-async def async_function():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from the statement above by two lines.
|
# This comment should be split from the statement above by two lines.
|
||||||
|
@ -190,7 +162,7 @@ def bar():
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
@@ -39,123 +35,55 @@
|
@@ -39,17 +38,14 @@
|
||||||
|
|
||||||
|
|
||||||
# This should be split from the above by two lines
|
# This should be split from the above by two lines
|
||||||
|
@ -211,54 +183,37 @@ def bar():
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
@@ -59,7 +55,7 @@
|
||||||
|
@deco1
|
||||||
# leading 1
|
# leading 2
|
||||||
-@deco1
|
# leading 2 extra
|
||||||
-# leading 2
|
|
||||||
-# leading 2 extra
|
|
||||||
-@deco2(with_args=True)
|
-@deco2(with_args=True)
|
||||||
-# leading 3
|
+@NOT_IMPLEMENTED_call()
|
||||||
-@deco3
|
# leading 3
|
||||||
-# leading 4
|
@deco3
|
||||||
-def decorated():
|
# leading 4
|
||||||
- pass
|
@@ -73,7 +69,7 @@
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
-@deco1
|
@deco1
|
||||||
-# leading 2
|
# leading 2
|
||||||
-@deco2(with_args=True)
|
-@deco2(with_args=True)
|
||||||
-
|
+@NOT_IMPLEMENTED_call()
|
||||||
-# leading 3 that already has an empty line
|
|
||||||
-@deco3
|
|
||||||
-# leading 4
|
|
||||||
-def decorated_with_split_leading_comments():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
|
||||||
|
|
||||||
|
|
||||||
|
# leading 3 that already has an empty line
|
||||||
|
@deco3
|
||||||
|
@@ -88,7 +84,7 @@
|
||||||
# leading 1
|
# leading 1
|
||||||
-@deco1
|
@deco1
|
||||||
-# leading 2
|
# leading 2
|
||||||
-@deco2(with_args=True)
|
-@deco2(with_args=True)
|
||||||
-# leading 3
|
+@NOT_IMPLEMENTED_call()
|
||||||
-@deco3
|
# leading 3
|
||||||
-
|
@deco3
|
||||||
-# leading 4 that already has an empty line
|
|
||||||
-def decorated_with_split_leading_comments():
|
@@ -98,41 +94,13 @@
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def main():
|
def main():
|
||||||
- if a:
|
- if a:
|
||||||
- # Leading comment before inline function
|
- # Leading comment before inline function
|
||||||
- def inline():
|
- def inline():
|
||||||
|
@ -267,19 +222,20 @@ def bar():
|
||||||
- # Another leading comment
|
- # Another leading comment
|
||||||
- def another_inline():
|
- def another_inline():
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
- else:
|
- else:
|
||||||
- # More leading comments
|
- # More leading comments
|
||||||
- def inline_after_else():
|
- def inline_after_else():
|
||||||
- pass
|
- pass
|
||||||
-
|
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
-if a:
|
-if a:
|
||||||
- # Leading comment before "top-level inline" function
|
- # Leading comment before "top-level inline" function
|
||||||
- def top_level_quote_inline():
|
- def top_level_quote_inline():
|
||||||
- pass
|
- pass
|
||||||
-
|
|
||||||
- # Another leading comment
|
- # Another leading comment
|
||||||
- def another_top_level_quote_inline_inline():
|
- def another_top_level_quote_inline_inline():
|
||||||
- pass
|
- pass
|
||||||
|
@ -288,9 +244,8 @@ def bar():
|
||||||
- # More leading comments
|
- # More leading comments
|
||||||
- def top_level_quote_inline_after_else():
|
- def top_level_quote_inline_after_else():
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtIf
|
-
|
||||||
|
-
|
||||||
|
|
||||||
-class MyClass:
|
-class MyClass:
|
||||||
- # First method has no empty lines between bare class def.
|
- # First method has no empty lines between bare class def.
|
||||||
- # More comments.
|
- # More comments.
|
||||||
|
@ -300,33 +255,6 @@ def bar():
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3454.
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
-def foo():
|
|
||||||
- pass
|
|
||||||
- # Trailing comment that belongs to this function
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-@decorator1
|
|
||||||
-@decorator2 # fmt: skip
|
|
||||||
-def bar():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3454.
|
|
||||||
-def foo():
|
|
||||||
- pass
|
|
||||||
- # Trailing comment that belongs to this function.
|
|
||||||
- # NOTE this comment only has one empty line below, and the formatter
|
|
||||||
- # should enforce two blank lines.
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-@decorator1
|
|
||||||
-# A standalone comment
|
|
||||||
-def bar():
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -338,7 +266,8 @@ some = statement
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from the statement above by two lines.
|
# This comment should be split from the statement above by two lines.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
@ -347,14 +276,16 @@ some = statement
|
||||||
# This multiline comments section
|
# This multiline comments section
|
||||||
# should be split from the statement
|
# should be split from the statement
|
||||||
# above by two lines.
|
# above by two lines.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from the statement above by two lines.
|
# This comment should be split from the statement above by two lines.
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def async_function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
@ -383,24 +314,49 @@ some = statement
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
# leading 2 extra
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
# leading 3 that already has an empty line
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
some = statement
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
# leading 1
|
# leading 1
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
|
||||||
|
# leading 4 that already has an empty line
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def main():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtIf
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
@ -410,17 +366,29 @@ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3454.
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@decorator1
|
||||||
|
@decorator2 # fmt: skip
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3454.
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function.
|
||||||
|
# NOTE this comment only has one empty line below, and the formatter
|
||||||
|
# should enforce two blank lines.
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@decorator1
|
||||||
|
# A standalone comment
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -32,7 +32,7 @@ def function(a:int=42):
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,23 +1,11 @@
|
@@ -1,23 +1,15 @@
|
||||||
-from .config import (
|
-from .config import (
|
||||||
- ConfigTypeAttributes,
|
- ConfigTypeAttributes,
|
||||||
- Int,
|
- Int,
|
||||||
|
@ -51,15 +51,15 @@ def function(a:int=42):
|
||||||
+square = NOT_IMPLEMENTED_call() # type: Optional[Square]
|
+square = NOT_IMPLEMENTED_call() # type: Optional[Square]
|
||||||
|
|
||||||
|
|
||||||
-def function(a: int = 42):
|
def function(a: int = 42):
|
||||||
- """This docstring is already formatted
|
- """This docstring is already formatted
|
||||||
- a
|
- a
|
||||||
- b
|
- b
|
||||||
- """
|
- """
|
||||||
- # There's a NBSP + 3 spaces before
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
- # And 4 spaces on the next line
|
# There's a NBSP + 3 spaces before
|
||||||
- pass
|
# And 4 spaces on the next line
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -75,7 +75,11 @@ result = 1 # This comment is talking about type: ignore
|
||||||
square = NOT_IMPLEMENTED_call() # type: Optional[Square]
|
square = NOT_IMPLEMENTED_call() # type: Optional[Square]
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function(a: int = 42):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# There's a NBSP + 3 spaces before
|
||||||
|
# And 4 spaces on the next line
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -109,7 +109,7 @@ async def wat():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -4,93 +4,42 @@
|
@@ -4,24 +4,15 @@
|
||||||
#
|
#
|
||||||
# Has many lines. Many, many lines.
|
# Has many lines. Many, many lines.
|
||||||
# Many, many, many lines.
|
# Many, many, many lines.
|
||||||
|
@ -117,50 +117,51 @@ async def wat():
|
||||||
-
|
-
|
||||||
-Possibly also many, many lines.
|
-Possibly also many, many lines.
|
||||||
-"""
|
-"""
|
||||||
-
|
+"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
-import os.path
|
-import os.path
|
||||||
-import sys
|
-import sys
|
||||||
-
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
-import a
|
-import a
|
||||||
-from b.c import X # some noqa comment
|
-from b.c import X # some noqa comment
|
||||||
+"NOT_YET_IMPLEMENTED_STRING"
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
||||||
|
|
||||||
-try:
|
-try:
|
||||||
- import fast
|
- import fast
|
||||||
-except ImportError:
|
-except ImportError:
|
||||||
- import slow as fast
|
- import slow as fast
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
-
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
-
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
|
||||||
|
|
||||||
-# Some comment before a function.
|
-# Some comment before a function.
|
||||||
+NOT_YET_IMPLEMENTED_StmtTry
|
+NOT_YET_IMPLEMENTED_StmtTry
|
||||||
y = 1
|
y = 1
|
||||||
(
|
(
|
||||||
# some strings
|
# some strings
|
||||||
y # type: ignore
|
@@ -30,67 +21,39 @@
|
||||||
)
|
|
||||||
-
|
|
||||||
-
|
def function(default=None):
|
||||||
-def function(default=None):
|
|
||||||
- """Docstring comes first.
|
- """Docstring comes first.
|
||||||
-
|
-
|
||||||
- Possibly many lines.
|
- Possibly many lines.
|
||||||
- """
|
- """
|
||||||
- # FIXME: Some comment about why this function is crap but still in production.
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# FIXME: Some comment about why this function is crap but still in production.
|
||||||
- import inner_imports
|
- import inner_imports
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
- if inner_imports.are_evil():
|
- if inner_imports.are_evil():
|
||||||
- # Explains why we have this if.
|
- # Explains why we have this if.
|
||||||
- # In great detail indeed.
|
- # In great detail indeed.
|
||||||
- x = X()
|
- x = X()
|
||||||
- return x.method1() # type: ignore
|
- return x.method1() # type: ignore
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
- # This return is also commented for some reason.
|
# This return is also commented for some reason.
|
||||||
- return default
|
return default
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Explains why we use global state.
|
# Explains why we use global state.
|
||||||
|
@ -170,7 +171,7 @@ async def wat():
|
||||||
|
|
||||||
# Another comment!
|
# Another comment!
|
||||||
# This time two lines.
|
# This time two lines.
|
||||||
|
-
|
||||||
|
|
||||||
-class Foo:
|
-class Foo:
|
||||||
- """Docstring for class Foo. Example from Sphinx docs."""
|
- """Docstring for class Foo. Example from Sphinx docs."""
|
||||||
|
@ -178,7 +179,7 @@ async def wat():
|
||||||
- #: Doc comment for class attribute Foo.bar.
|
- #: Doc comment for class attribute Foo.bar.
|
||||||
- #: It can have multiple lines.
|
- #: It can have multiple lines.
|
||||||
- bar = 1
|
- bar = 1
|
||||||
-
|
|
||||||
- flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
- flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||||
-
|
-
|
||||||
- baz = 2
|
- baz = 2
|
||||||
|
@ -187,27 +188,29 @@ async def wat():
|
||||||
- def __init__(self):
|
- def __init__(self):
|
||||||
- #: Doc comment for instance attribute qux.
|
- #: Doc comment for instance attribute qux.
|
||||||
- self.qux = 3
|
- self.qux = 3
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
-
|
||||||
|
|
||||||
- self.spam = 4
|
- self.spam = 4
|
||||||
- """Docstring for instance attribute spam."""
|
- """Docstring for instance attribute spam."""
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-
|
|
||||||
#' <h1>This is pweave!</h1>
|
#' <h1>This is pweave!</h1>
|
||||||
|
|
||||||
|
|
||||||
-@fast(really=True)
|
-@fast(really=True)
|
||||||
-async def wat():
|
+@NOT_IMPLEMENTED_call()
|
||||||
- # This comment, for some reason \
|
async def wat():
|
||||||
- # contains a trailing backslash.
|
# This comment, for some reason \
|
||||||
|
# contains a trailing backslash.
|
||||||
- async with X.open_async() as x: # Some more comments
|
- async with X.open_async() as x: # Some more comments
|
||||||
- result = await x.method1()
|
- result = await x.method1()
|
||||||
- # Comment after ending a block.
|
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
|
||||||
|
# Comment after ending a block.
|
||||||
- if result:
|
- if result:
|
||||||
- print("A OK", file=sys.stdout)
|
- print("A OK", file=sys.stdout)
|
||||||
- # Comment between things.
|
- # Comment between things.
|
||||||
- print()
|
- print()
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
# Some closing comments.
|
# Some closing comments.
|
||||||
|
@ -242,7 +245,15 @@ y = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function(default=None):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# FIXME: Some comment about why this function is crap but still in production.
|
||||||
|
NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
# This return is also commented for some reason.
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
# Explains why we use global state.
|
# Explains why we use global state.
|
||||||
|
@ -259,7 +270,13 @@ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
#' <h1>This is pweave!</h1>
|
#' <h1>This is pweave!</h1>
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
@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.
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
# Some closing comments.
|
# Some closing comments.
|
||||||
|
|
|
@ -63,98 +63,108 @@ def single_quote_docstring_over_line_limit2():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,48 +1,28 @@
|
@@ -1,48 +1,38 @@
|
||||||
-def docstring_almost_at_line_limit():
|
def docstring_almost_at_line_limit():
|
||||||
- """long docstring................................................................."""
|
- """long docstring................................................................."""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def docstring_almost_at_line_limit_with_prefix():
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
- f"""long docstring................................................................"""
|
- f"""long docstring................................................................"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
-def mulitline_docstring_almost_at_line_limit():
|
def mulitline_docstring_almost_at_line_limit():
|
||||||
- """long docstring.................................................................
|
- """long docstring.................................................................
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
-
|
||||||
|
|
||||||
- ..................................................................................
|
- ..................................................................................
|
||||||
- """
|
- """
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def mulitline_docstring_almost_at_line_limit_with_prefix():
|
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||||
- f"""long docstring................................................................
|
- f"""long docstring................................................................
|
||||||
|
-
|
||||||
- ..................................................................................
|
- ..................................................................................
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
-def docstring_at_line_limit():
|
def docstring_at_line_limit():
|
||||||
- """long docstring................................................................"""
|
- """long docstring................................................................"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def docstring_at_line_limit_with_prefix():
|
def docstring_at_line_limit_with_prefix():
|
||||||
- f"""long docstring..............................................................."""
|
- f"""long docstring..............................................................."""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
-def multiline_docstring_at_line_limit():
|
def multiline_docstring_at_line_limit():
|
||||||
- """first line-----------------------------------------------------------------------
|
- """first line-----------------------------------------------------------------------
|
||||||
-
|
-
|
||||||
- second line----------------------------------------------------------------------"""
|
- second line----------------------------------------------------------------------"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def multiline_docstring_at_line_limit_with_prefix():
|
def multiline_docstring_at_line_limit_with_prefix():
|
||||||
- f"""first line----------------------------------------------------------------------
|
- f"""first line----------------------------------------------------------------------
|
||||||
-
|
-
|
||||||
- second line----------------------------------------------------------------------"""
|
- second line----------------------------------------------------------------------"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
-def single_quote_docstring_over_line_limit():
|
def single_quote_docstring_over_line_limit():
|
||||||
- "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
- "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
-
|
|
||||||
-def single_quote_docstring_over_line_limit2():
|
|
||||||
|
def single_quote_docstring_over_line_limit2():
|
||||||
- "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
- "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_almost_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
|
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def mulitline_docstring_almost_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||||
|
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_at_line_limit_with_prefix():
|
||||||
|
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_docstring_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_docstring_at_line_limit_with_prefix():
|
||||||
|
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_quote_docstring_over_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_quote_docstring_over_line_limit2():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -234,65 +234,64 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,219 +1,105 @@
|
@@ -1,219 +1,149 @@
|
||||||
-class MyClass:
|
-class MyClass:
|
||||||
- """Multiline
|
- """Multiline
|
||||||
- class docstring
|
- class docstring
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
-
|
||||||
|
|
||||||
- def method(self):
|
- def method(self):
|
||||||
- """Multiline
|
- """Multiline
|
||||||
- method docstring
|
- method docstring
|
||||||
- """
|
- """
|
||||||
- pass
|
- pass
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def foo():
|
def foo():
|
||||||
- """This is a docstring with
|
- """This is a docstring with
|
||||||
- some lines of text here
|
- some lines of text here
|
||||||
- """
|
- """
|
||||||
- return
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def bar():
|
def bar():
|
||||||
- """This is another docstring
|
- """This is another docstring
|
||||||
- with more lines of text
|
- with more lines of text
|
||||||
- """
|
- """
|
||||||
- return
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def baz():
|
def baz():
|
||||||
- '''"This" is a string with some
|
- '''"This" is a string with some
|
||||||
- embedded "quotes"'''
|
- embedded "quotes"'''
|
||||||
- return
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def troz():
|
def troz():
|
||||||
- """Indentation with tabs
|
- """Indentation with tabs
|
||||||
- is just as OK
|
- is just as OK
|
||||||
- """
|
- """
|
||||||
- return
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def zort():
|
def zort():
|
||||||
- """Another
|
- """Another
|
||||||
- multiline
|
- multiline
|
||||||
- docstring
|
- docstring
|
||||||
- """
|
- """
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def poit():
|
def poit():
|
||||||
- """
|
- """
|
||||||
- Lorem ipsum dolor sit amet.
|
- Lorem ipsum dolor sit amet.
|
||||||
|
-
|
||||||
- Consectetur adipiscing elit:
|
- Consectetur adipiscing elit:
|
||||||
- - sed do eiusmod tempor incididunt ut labore
|
- - sed do eiusmod tempor incididunt ut labore
|
||||||
- - dolore magna aliqua
|
- - dolore magna aliqua
|
||||||
|
@ -300,99 +299,99 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
- - quis nostrud exercitation ullamco laboris nisi
|
- - quis nostrud exercitation ullamco laboris nisi
|
||||||
- - aliquip ex ea commodo consequat
|
- - aliquip ex ea commodo consequat
|
||||||
- """
|
- """
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def under_indent():
|
def under_indent():
|
||||||
- """
|
- """
|
||||||
- These lines are indented in a way that does not
|
- These lines are indented in a way that does not
|
||||||
- make sense.
|
- make sense.
|
||||||
- """
|
- """
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def over_indent():
|
def over_indent():
|
||||||
- """
|
- """
|
||||||
- This has a shallow indent
|
- This has a shallow indent
|
||||||
- - But some lines are deeper
|
- - But some lines are deeper
|
||||||
- - And the closing quote is too deep
|
- - And the closing quote is too deep
|
||||||
- """
|
- """
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def single_line():
|
def single_line():
|
||||||
- """But with a newline after it!"""
|
- """But with a newline after it!"""
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def this():
|
def this():
|
||||||
- r"""
|
- r"""
|
||||||
- 'hey ho'
|
- 'hey ho'
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def that():
|
def that():
|
||||||
- """ "hey yah" """
|
- """ "hey yah" """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def and_that():
|
def and_that():
|
||||||
- """
|
- """
|
||||||
- "hey yah" """
|
- "hey yah" """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def and_this():
|
def and_this():
|
||||||
- '''
|
- '''
|
||||||
- "hey yah"'''
|
- "hey yah"'''
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def multiline_whitespace():
|
def multiline_whitespace():
|
||||||
- """ """
|
- """ """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def oneline_whitespace():
|
def oneline_whitespace():
|
||||||
- """ """
|
- """ """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def empty():
|
def empty():
|
||||||
- """"""
|
- """"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def single_quotes():
|
def single_quotes():
|
||||||
- "testing"
|
- "testing"
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def believe_it_or_not_this_is_in_the_py_stdlib():
|
|
||||||
|
def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||||
- '''
|
- '''
|
||||||
- "hey yah"'''
|
- "hey yah"'''
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def ignored_docstring():
|
def ignored_docstring():
|
||||||
- """a => \
|
- """a => \
|
||||||
-b"""
|
-b"""
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def single_line_docstring_with_whitespace():
|
def single_line_docstring_with_whitespace():
|
||||||
- """This should be stripped"""
|
- """This should be stripped"""
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def docstring_with_inline_tabs_and_space_indentation():
|
def docstring_with_inline_tabs_and_space_indentation():
|
||||||
- """hey
|
- """hey
|
||||||
|
-
|
||||||
- tab separated value
|
- tab separated value
|
||||||
- tab at start of line and then a tab separated value
|
- tab at start of line and then a tab separated value
|
||||||
- multiple tabs at the beginning and inline
|
- multiple tabs at the beginning and inline
|
||||||
|
@ -400,12 +399,12 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
-
|
-
|
||||||
- line ends with some tabs
|
- line ends with some tabs
|
||||||
- """
|
- """
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def docstring_with_inline_tabs_and_tab_indentation():
|
|
||||||
|
def docstring_with_inline_tabs_and_tab_indentation():
|
||||||
- """hey
|
- """hey
|
||||||
|
-
|
||||||
- tab separated value
|
- tab separated value
|
||||||
- tab at start of line and then a tab separated value
|
- tab at start of line and then a tab separated value
|
||||||
- multiple tabs at the beginning and inline
|
- multiple tabs at the beginning and inline
|
||||||
|
@ -413,82 +412,83 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
-
|
-
|
||||||
- line ends with some tabs
|
- line ends with some tabs
|
||||||
- """
|
- """
|
||||||
- pass
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def backslash_space():
|
def backslash_space():
|
||||||
- """\ """
|
- """\ """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def multiline_backslash_1():
|
def multiline_backslash_1():
|
||||||
- """
|
- """
|
||||||
- hey\there\
|
- hey\there\
|
||||||
- \ """
|
- \ """
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
-
|
|
||||||
-def multiline_backslash_2():
|
|
||||||
|
def multiline_backslash_2():
|
||||||
- """
|
- """
|
||||||
- hey there \ """
|
- hey there \ """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
# Regression test for #3425
|
# Regression test for #3425
|
||||||
-def multiline_backslash_really_long_dont_crash():
|
def multiline_backslash_really_long_dont_crash():
|
||||||
- """
|
- """
|
||||||
- hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
- hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def multiline_backslash_3():
|
def multiline_backslash_3():
|
||||||
- """
|
- """
|
||||||
- already escaped \\"""
|
- already escaped \\"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def my_god_its_full_of_stars_1():
|
def my_god_its_full_of_stars_1():
|
||||||
- "I'm sorry Dave\u2001"
|
- "I'm sorry Dave\u2001"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
# the space below is actually a \u2001, removed in output
|
# the space below is actually a \u2001, removed in output
|
||||||
-def my_god_its_full_of_stars_2():
|
def my_god_its_full_of_stars_2():
|
||||||
- "I'm sorry Dave"
|
- "I'm sorry Dave"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def docstring_almost_at_line_limit():
|
def docstring_almost_at_line_limit():
|
||||||
- """long docstring................................................................."""
|
- """long docstring................................................................."""
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
-
|
|
||||||
-def docstring_almost_at_line_limit2():
|
|
||||||
|
def docstring_almost_at_line_limit2():
|
||||||
- """long docstring.................................................................
|
- """long docstring.................................................................
|
||||||
-
|
-
|
||||||
- ..................................................................................
|
- ..................................................................................
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def docstring_at_line_limit():
|
def docstring_at_line_limit():
|
||||||
- """long docstring................................................................"""
|
- """long docstring................................................................"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def multiline_docstring_at_line_limit():
|
def multiline_docstring_at_line_limit():
|
||||||
- """first line-----------------------------------------------------------------------
|
- """first line-----------------------------------------------------------------------
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
-
|
||||||
|
|
||||||
- second line----------------------------------------------------------------------"""
|
- second line----------------------------------------------------------------------"""
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
- """'<text here>
|
- """'<text here>
|
||||||
|
-
|
||||||
- <text here, since without another non-empty line black is stable>
|
- <text here, since without another non-empty line black is stable>
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -497,108 +497,152 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def bar():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def baz():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def troz():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def zort():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def poit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def under_indent():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def over_indent():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_line():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def this():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def that():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def and_that():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def and_this():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_whitespace():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def oneline_whitespace():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def empty():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_quotes():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def ignored_docstring():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_line_docstring_with_whitespace():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_with_inline_tabs_and_space_indentation():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_with_inline_tabs_and_tab_indentation():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def backslash_space():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_backslash_1():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_backslash_2():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
# Regression test for #3425
|
# Regression test for #3425
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_backslash_really_long_dont_crash():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_backslash_3():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def my_god_its_full_of_stars_1():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
# the space below is actually a \u2001, removed in output
|
# the space below is actually a \u2001, removed in output
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def my_god_its_full_of_stars_2():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_almost_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_almost_at_line_limit2():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def multiline_docstring_at_line_limit():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -105,13 +105,13 @@ def g():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,89 +1,12 @@
|
@@ -1,89 +1,45 @@
|
||||||
-"""Docstring."""
|
-"""Docstring."""
|
||||||
+"NOT_YET_IMPLEMENTED_STRING"
|
+"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
# leading comment
|
# leading comment
|
||||||
-def f():
|
def f():
|
||||||
- NO = ""
|
- NO = ""
|
||||||
- SPACE = " "
|
- SPACE = " "
|
||||||
- DOUBLESPACE = " "
|
- DOUBLESPACE = " "
|
||||||
|
@ -124,15 +124,23 @@ def g():
|
||||||
- pass
|
- pass
|
||||||
- if t == token.COMMENT: # another trailing comment
|
- if t == token.COMMENT: # another trailing comment
|
||||||
- return DOUBLESPACE
|
- return DOUBLESPACE
|
||||||
-
|
+ NO = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ SPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ DOUBLESPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||||
-
|
+ t = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
+ p = leaf.NOT_IMPLEMENTED_attr # trailing comment
|
||||||
|
+ v = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
|
||||||
- prev = leaf.prev_sibling
|
- prev = leaf.prev_sibling
|
||||||
- if not prev:
|
- if not prev:
|
||||||
- prevp = preceding_leaf(p)
|
- prevp = preceding_leaf(p)
|
||||||
- if not prevp or prevp.type in OPENING_BRACKETS:
|
- if not prevp or prevp.type in OPENING_BRACKETS:
|
||||||
- return NO
|
- return NO
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf # another trailing comment
|
||||||
|
|
||||||
- if prevp.type == token.EQUAL:
|
- if prevp.type == token.EQUAL:
|
||||||
- if prevp.parent and prevp.parent.type in {
|
- if prevp.parent and prevp.parent.type in {
|
||||||
- syms.typedargslist,
|
- syms.typedargslist,
|
||||||
|
@ -142,7 +150,8 @@ def g():
|
||||||
- syms.argument,
|
- syms.argument,
|
||||||
- }:
|
- }:
|
||||||
- return NO
|
- return NO
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
- elif prevp.type == token.DOUBLESTAR:
|
- elif prevp.type == token.DOUBLESTAR:
|
||||||
- if prevp.parent and prevp.parent.type in {
|
- if prevp.parent and prevp.parent.type in {
|
||||||
- syms.typedargslist,
|
- syms.typedargslist,
|
||||||
|
@ -152,7 +161,8 @@ def g():
|
||||||
- syms.dictsetmaker,
|
- syms.dictsetmaker,
|
||||||
- }:
|
- }:
|
||||||
- return NO
|
- return NO
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ prev = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -160,29 +170,38 @@ def g():
|
||||||
###############################################################################
|
###############################################################################
|
||||||
-
|
-
|
||||||
|
|
||||||
-def g():
|
def g():
|
||||||
- NO = ""
|
- NO = ""
|
||||||
- SPACE = " "
|
- SPACE = " "
|
||||||
- DOUBLESPACE = " "
|
- DOUBLESPACE = " "
|
||||||
-
|
+ NO = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ SPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ DOUBLESPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
- t = leaf.type
|
- t = leaf.type
|
||||||
- p = leaf.parent
|
- p = leaf.parent
|
||||||
- v = leaf.value
|
- v = leaf.value
|
||||||
-
|
+ t = leaf.NOT_IMPLEMENTED_attr
|
||||||
- # Comment because comments
|
+ p = leaf.NOT_IMPLEMENTED_attr
|
||||||
-
|
+ v = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
|
||||||
|
# Comment because comments
|
||||||
|
|
||||||
- if t in ALWAYS_NO_SPACE:
|
- if t in ALWAYS_NO_SPACE:
|
||||||
- pass
|
- pass
|
||||||
- if t == token.COMMENT:
|
- if t == token.COMMENT:
|
||||||
- return DOUBLESPACE
|
- return DOUBLESPACE
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
- # Another comment because more comments
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
# Another comment because more comments
|
||||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||||
-
|
-
|
||||||
- prev = leaf.prev_sibling
|
- prev = leaf.prev_sibling
|
||||||
- if not prev:
|
- if not prev:
|
||||||
- prevp = preceding_leaf(p)
|
- prevp = preceding_leaf(p)
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
- if not prevp or prevp.type in OPENING_BRACKETS:
|
- if not prevp or prevp.type in OPENING_BRACKETS:
|
||||||
- # Start of the line or a bracketed expression.
|
- # Start of the line or a bracketed expression.
|
||||||
- # More than one line for the comment.
|
- # More than one line for the comment.
|
||||||
|
@ -197,7 +216,8 @@ def g():
|
||||||
- syms.argument,
|
- syms.argument,
|
||||||
- }:
|
- }:
|
||||||
- return NO
|
- return NO
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ prev = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -207,14 +227,47 @@ def g():
|
||||||
|
|
||||||
|
|
||||||
# leading comment
|
# leading comment
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f():
|
||||||
|
NO = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
SPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
DOUBLESPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
t = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
p = leaf.NOT_IMPLEMENTED_attr # trailing comment
|
||||||
|
v = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf # another trailing comment
|
||||||
|
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
prev = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# SECTION BECAUSE SECTIONS
|
# SECTION BECAUSE SECTIONS
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def g():
|
||||||
|
NO = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
SPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
DOUBLESPACE = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
t = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
p = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
v = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
|
||||||
|
# Comment because comments
|
||||||
|
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
# Another comment because more comments
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
prev = leaf.NOT_IMPLEMENTED_attr
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -276,7 +276,7 @@ last_call()
|
||||||
Name
|
Name
|
||||||
None
|
None
|
||||||
True
|
True
|
||||||
@@ -7,346 +8,240 @@
|
@@ -7,346 +8,245 @@
|
||||||
1
|
1
|
||||||
1.0
|
1.0
|
||||||
1j
|
1j
|
||||||
|
@ -541,6 +541,9 @@ last_call()
|
||||||
- int,
|
- int,
|
||||||
- float,
|
- float,
|
||||||
- dict[str, int],
|
- dict[str, int],
|
||||||
|
-]
|
||||||
|
-very_long_variable_name_filters: t.List[
|
||||||
|
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
+[
|
+[
|
||||||
+ 1,
|
+ 1,
|
||||||
+ 2,
|
+ 2,
|
||||||
|
@ -555,9 +558,6 @@ last_call()
|
||||||
+ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2,
|
+ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2,
|
||||||
+ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2,
|
+ NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2,
|
||||||
]
|
]
|
||||||
-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
|
-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
-)
|
-)
|
||||||
|
@ -679,17 +679,20 @@ last_call()
|
||||||
+mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
+mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
-def gen():
|
def gen():
|
||||||
- yield from outside_of_generator
|
- yield from outside_of_generator
|
||||||
- a = yield
|
- a = yield
|
||||||
- b = yield
|
- b = yield
|
||||||
- c = yield
|
- c = yield
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||||
|
+ a = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
+ b = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
+ c = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
|
||||||
|
|
||||||
-async def f():
|
async def f():
|
||||||
- await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
- await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-print(*[] or [1])
|
-print(*[] or [1])
|
||||||
|
@ -823,7 +826,7 @@ last_call()
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaa
|
||||||
+ aaaaaaaaaaaaaaaa
|
+ aaaaaaaaaaaaaaaa
|
||||||
@@ -363,8 +258,9 @@
|
@@ -363,8 +263,9 @@
|
||||||
bbbb >> bbbb * bbbb
|
bbbb >> bbbb * bbbb
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
@ -1050,10 +1053,15 @@ NOT_IMPLEMENTED_call()
|
||||||
mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def gen():
|
||||||
|
NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||||
|
a = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
b = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
c = NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def f():
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_IMPLEMENTED_call()
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
|
@ -53,7 +53,7 @@ def test_calculate_fades():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,40 +1,26 @@
|
@@ -1,40 +1,38 @@
|
||||||
-import pytest
|
-import pytest
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
@ -67,40 +67,43 @@ def test_calculate_fades():
|
||||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||||
|
|
||||||
-@pytest.mark.parametrize('test', [
|
-@pytest.mark.parametrize('test', [
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
-
|
||||||
+
|
|
||||||
+
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
- # Test don't manage the volume
|
- # Test don't manage the volume
|
||||||
- [
|
- [
|
||||||
- ('stuff', 'in')
|
- ('stuff', 'in')
|
||||||
- ],
|
- ],
|
||||||
-])
|
-])
|
||||||
-def test_fader(test):
|
+@NOT_IMPLEMENTED_call()
|
||||||
- pass
|
def test_fader(test):
|
||||||
|
pass
|
||||||
|
|
||||||
-def check_fader(test):
|
+
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def check_fader(test):
|
||||||
|
+ pass
|
||||||
|
|
||||||
- pass
|
- pass
|
||||||
|
|
||||||
-def verify_fader(test):
|
def verify_fader(test):
|
||||||
- # misaligned comment
|
- # misaligned comment
|
||||||
- pass
|
+ # misaligned comment
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
-def verify_fader(test):
|
+
|
||||||
|
def verify_fader(test):
|
||||||
- """Hey, ho."""
|
- """Hey, ho."""
|
||||||
- assert test.passed()
|
- assert test.passed()
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
+
|
||||||
|
|
||||||
-def test_calculate_fades():
|
def test_calculate_fades():
|
||||||
- calcs = [
|
calcs = [
|
||||||
- # one is zero/none
|
# one is zero/none
|
||||||
- (0, 4, 0, 0, 10, 0, 0, 6, 10),
|
- (0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||||
- (None, 4, 0, 0, 10, 0, 0, 6, 10),
|
- (None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||||
- ]
|
+ (1, 2),
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ (1, 2),
|
||||||
|
]
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
```
|
```
|
||||||
|
@ -119,19 +122,31 @@ TmEx = 2
|
||||||
# Test data:
|
# Test data:
|
||||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@NOT_IMPLEMENTED_call()
|
||||||
|
def test_fader(test):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def check_fader(test):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def verify_fader(test):
|
||||||
|
# misaligned comment
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def verify_fader(test):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def test_calculate_fades():
|
||||||
|
calcs = [
|
||||||
|
# one is zero/none
|
||||||
|
(1, 2),
|
||||||
|
(1, 2),
|
||||||
|
]
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
```
|
```
|
||||||
|
|
|
@ -26,16 +26,16 @@ def f(): pass
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,20 +1,5 @@
|
@@ -1,20 +1,10 @@
|
||||||
# fmt: off
|
# fmt: off
|
||||||
-@test([
|
-@test([
|
||||||
- 1, 2,
|
- 1, 2,
|
||||||
- 3, 4,
|
- 3, 4,
|
||||||
-])
|
-])
|
||||||
-# fmt: on
|
+@NOT_IMPLEMENTED_call()
|
||||||
-def f():
|
# fmt: on
|
||||||
- pass
|
def f():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-@test(
|
-@test(
|
||||||
|
@ -46,19 +46,24 @@ def f(): pass
|
||||||
- 4,
|
- 4,
|
||||||
- ]
|
- ]
|
||||||
-)
|
-)
|
||||||
-def f():
|
+@NOT_IMPLEMENTED_call()
|
||||||
- pass
|
def f():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
# fmt: off
|
# fmt: off
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@NOT_IMPLEMENTED_call()
|
||||||
|
# fmt: on
|
||||||
|
def f():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@NOT_IMPLEMENTED_call()
|
||||||
|
def f():
|
||||||
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -97,7 +97,7 @@ elif unformatted:
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,87 +1,29 @@
|
@@ -1,87 +1,33 @@
|
||||||
# Regression test for https://github.com/psf/black/issues/3129.
|
# Regression test for https://github.com/psf/black/issues/3129.
|
||||||
-setup(
|
-setup(
|
||||||
- entry_points={
|
- entry_points={
|
||||||
|
@ -127,18 +127,18 @@ elif unformatted:
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3026.
|
# Regression test for https://github.com/psf/black/issues/3026.
|
||||||
-def test_func():
|
def test_func():
|
||||||
- # yapf: disable
|
# yapf: disable
|
||||||
- if unformatted( args ):
|
- if unformatted( args ):
|
||||||
- return True
|
- return True
|
||||||
- # yapf: enable
|
- # yapf: enable
|
||||||
- elif b:
|
- elif b:
|
||||||
- return True
|
- return True
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
- return False
|
|
||||||
|
|
||||||
-
|
|
||||||
# Regression test for https://github.com/psf/black/issues/2567.
|
# Regression test for https://github.com/psf/black/issues/2567.
|
||||||
-if True:
|
-if True:
|
||||||
- # fmt: off
|
- # fmt: off
|
||||||
|
@ -161,14 +161,14 @@ elif unformatted:
|
||||||
- ) :
|
- ) :
|
||||||
- # fmt: on
|
- # fmt: on
|
||||||
- print ( "This won't be formatted" )
|
- print ( "This won't be formatted" )
|
||||||
-
|
|
||||||
- elif param[0:4] in ("ZZZZ",):
|
|
||||||
- print ( "This won't be formatted either" )
|
|
||||||
-
|
|
||||||
- print("This will be formatted")
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
- elif param[0:4] in ("ZZZZ",):
|
||||||
|
- print ( "This won't be formatted either" )
|
||||||
|
|
||||||
|
- print("This will be formatted")
|
||||||
|
-
|
||||||
|
-
|
||||||
# Regression test for https://github.com/psf/black/issues/2985.
|
# Regression test for https://github.com/psf/black/issues/2985.
|
||||||
-class Named(t.Protocol):
|
-class Named(t.Protocol):
|
||||||
- # fmt: off
|
- # fmt: off
|
||||||
|
@ -180,10 +180,10 @@ elif unformatted:
|
||||||
-class Factory(t.Protocol):
|
-class Factory(t.Protocol):
|
||||||
- def this_will_be_formatted(self, **kwargs) -> Named:
|
- def this_will_be_formatted(self, **kwargs) -> Named:
|
||||||
- ...
|
- ...
|
||||||
|
-
|
||||||
|
- # fmt: on
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
- # fmt: on
|
|
||||||
-
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3436.
|
# Regression test for https://github.com/psf/black/issues/3436.
|
||||||
-if x:
|
-if x:
|
||||||
|
@ -207,7 +207,11 @@ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3026.
|
# Regression test for https://github.com/psf/black/issues/3026.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def test_func():
|
||||||
|
# yapf: disable
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/2567.
|
# Regression test for https://github.com/psf/black/issues/2567.
|
||||||
|
|
|
@ -199,7 +199,7 @@ d={'a':1,
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,224 +1,72 @@
|
@@ -1,16 +1,14 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
-import asyncio
|
-import asyncio
|
||||||
-import sys
|
-import sys
|
||||||
|
@ -207,10 +207,10 @@ d={'a':1,
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
-from third_party import X, Y, Z
|
-from third_party import X, Y, Z
|
||||||
|
-
|
||||||
|
-from library import some_connection, some_decorator
|
||||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
|
|
||||||
-from library import some_connection, some_decorator
|
|
||||||
-
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
# fmt: off
|
# fmt: off
|
||||||
-from third_party import (X,
|
-from third_party import (X,
|
||||||
|
@ -222,10 +222,10 @@ d={'a':1,
|
||||||
# Comment 1
|
# Comment 1
|
||||||
|
|
||||||
# Comment 2
|
# Comment 2
|
||||||
|
@@ -18,109 +16,109 @@
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
-def func_no_args():
|
def func_no_args():
|
||||||
- a; b; c
|
- a; b; c
|
||||||
- if True: raise RuntimeError
|
- if True: raise RuntimeError
|
||||||
- if False: ...
|
- if False: ...
|
||||||
|
@ -234,7 +234,17 @@ d={'a':1,
|
||||||
- continue
|
- continue
|
||||||
- exec('new-style exec', {}, {})
|
- exec('new-style exec', {}, {})
|
||||||
- return None
|
- return None
|
||||||
-async def coroutine(arg, exec=False):
|
+ a
|
||||||
|
+ b
|
||||||
|
+ c
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtFor
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ return None
|
||||||
|
+
|
||||||
|
+
|
||||||
|
async def coroutine(arg, exec=False):
|
||||||
- 'Single-line docstring. Multiline is harder to reformat.'
|
- 'Single-line docstring. Multiline is harder to reformat.'
|
||||||
- async with some_connection() as conn:
|
- async with some_connection() as conn:
|
||||||
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||||
|
@ -246,47 +256,75 @@ d={'a':1,
|
||||||
-)
|
-)
|
||||||
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||||
- return text[number:-1]
|
- return text[number:-1]
|
||||||
-# fmt: on
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||||
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+@asyncio.NOT_IMPLEMENTED_attr
|
||||||
|
+@NOT_IMPLEMENTED_call()
|
||||||
|
+def function_signature_stress_test(
|
||||||
|
+ number: int,
|
||||||
|
+ no_annotation=None,
|
||||||
|
+ text: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+ debug: bool = False,
|
||||||
|
+ **kwargs,
|
||||||
|
+) -> str:
|
||||||
|
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
+
|
||||||
|
+
|
||||||
|
# fmt: on
|
||||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
|
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
|
||||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+def spaces(
|
||||||
+
|
+ a=1,
|
||||||
+
|
+ b=(1, 2),
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ c=[],
|
||||||
+
|
+ d={NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
+ e=True,
|
||||||
|
+ f=NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
+ g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
+ h="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+ i="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+):
|
||||||
|
+ offset = NOT_IMPLEMENTED_call()
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def spaces_types(
|
def spaces_types(
|
||||||
- a: int = 1,
|
a: int = 1,
|
||||||
- b: tuple = (),
|
- b: tuple = (),
|
||||||
- c: list = [],
|
+ b: tuple = (1, 2),
|
||||||
|
c: list = [],
|
||||||
- d: dict = {},
|
- d: dict = {},
|
||||||
- e: bool = True,
|
+ d: dict = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e: bool = True,
|
||||||
- f: int = -1,
|
- f: int = -1,
|
||||||
- g: int = 1 if False else 2,
|
- g: int = 1 if False else 2,
|
||||||
- h: str = "",
|
- h: str = "",
|
||||||
- i: str = r"",
|
- i: str = r"",
|
||||||
-):
|
+ f: int = NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
- ...
|
+ g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
+ h: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+ i: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
+# fmt: on
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def spaces2(result=_core.Value(None)):
|
-def spaces2(result=_core.Value(None)):
|
||||||
- ...
|
+def spaces2(result=NOT_IMPLEMENTED_call()):
|
||||||
|
...
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-something = {
|
-something = {
|
||||||
- # fmt: off
|
- # fmt: off
|
||||||
- key: 'value',
|
- key: 'value',
|
||||||
-}
|
-}
|
||||||
|
+something = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def subscriptlist():
|
def subscriptlist():
|
||||||
- atom[
|
- atom[
|
||||||
- # fmt: off
|
- # fmt: off
|
||||||
- 'some big and',
|
- 'some big and',
|
||||||
|
@ -295,81 +333,90 @@ d={'a':1,
|
||||||
- goes + here,
|
- goes + here,
|
||||||
- andhere,
|
- andhere,
|
||||||
- ]
|
- ]
|
||||||
|
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
+something = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
|
||||||
|
|
||||||
-def import_as_names():
|
def import_as_names():
|
||||||
- # fmt: off
|
# fmt: off
|
||||||
- from hello import a, b
|
- from hello import a, b
|
||||||
- 'unformatted'
|
- 'unformatted'
|
||||||
- # fmt: on
|
+ NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def testlist_star_expr():
|
def testlist_star_expr():
|
||||||
- # fmt: off
|
# fmt: off
|
||||||
- a , b = *hello
|
- a , b = *hello
|
||||||
- 'unformatted'
|
- 'unformatted'
|
||||||
- # fmt: on
|
+ (1, 2) = NOT_YET_IMPLEMENTED_ExprStarred
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def yield_expr():
|
def yield_expr():
|
||||||
- # fmt: off
|
# fmt: off
|
||||||
- yield hello
|
- yield hello
|
||||||
- 'unformatted'
|
- 'unformatted'
|
||||||
- # fmt: on
|
+ NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
- "formatted"
|
- "formatted"
|
||||||
- # fmt: off
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: off
|
||||||
- ( yield hello )
|
- ( yield hello )
|
||||||
- 'unformatted'
|
- 'unformatted'
|
||||||
- # fmt: on
|
+ (NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def example(session):
|
def example(session):
|
||||||
- # fmt: off
|
# fmt: off
|
||||||
- result = session\
|
- result = session\
|
||||||
- .query(models.Customer.id)\
|
- .query(models.Customer.id)\
|
||||||
- .filter(models.Customer.account_id == account_id,
|
- .filter(models.Customer.account_id == account_id,
|
||||||
- models.Customer.email == email_address)\
|
- models.Customer.email == email_address)\
|
||||||
- .order_by(models.Customer.id.asc())\
|
- .order_by(models.Customer.id.asc())\
|
||||||
- .all()
|
- .all()
|
||||||
- # fmt: on
|
+ result = NOT_IMPLEMENTED_call()
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def off_and_on_without_data():
|
def off_and_on_without_data():
|
||||||
- """All comments here are technically on the same prefix.
|
- """All comments here are technically on the same prefix.
|
||||||
|
-
|
||||||
- The comments between will be formatted. This is a known limitation.
|
- The comments between will be formatted. This is a known limitation.
|
||||||
- """
|
- """
|
||||||
- # fmt: off
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
# fmt: off
|
||||||
|
|
||||||
- # hey, that won't work
|
# hey, that won't work
|
||||||
|
@@ -130,13 +128,15 @@
|
||||||
- # fmt: on
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def on_and_off_broken():
|
def on_and_off_broken():
|
||||||
- """Another known limitation."""
|
- """Another known limitation."""
|
||||||
- # fmt: on
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
- # fmt: off
|
# fmt: on
|
||||||
|
# fmt: off
|
||||||
- this=should.not_be.formatted()
|
- this=should.not_be.formatted()
|
||||||
- and_=indeed . it is not formatted
|
- and_=indeed . it is not formatted
|
||||||
- because . the . handling . inside . generate_ignored_nodes()
|
- because . the . handling . inside . generate_ignored_nodes()
|
||||||
- now . considers . multiple . fmt . directives . within . one . prefix
|
- now . considers . multiple . fmt . directives . within . one . prefix
|
||||||
- # fmt: on
|
+ this = NOT_IMPLEMENTED_call()
|
||||||
- # fmt: off
|
+ and_ = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
|
||||||
- # ...but comments still get reformatted even though they should not be
|
+ NOT_IMPLEMENTED_call()
|
||||||
- # fmt: on
|
+ (
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ now.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr
|
||||||
|
+ )
|
||||||
|
# fmt: on
|
||||||
|
# fmt: off
|
||||||
|
# ...but comments still get reformatted even though they should not be
|
||||||
|
@@ -144,81 +144,18 @@
|
||||||
|
|
||||||
|
|
||||||
-def long_lines():
|
def long_lines():
|
||||||
- if True:
|
- if True:
|
||||||
- typedargslist.extend(
|
- typedargslist.extend(
|
||||||
- gen_annotated_params(
|
- gen_annotated_params(
|
||||||
|
@ -408,13 +455,15 @@ d={'a':1,
|
||||||
- re.MULTILINE|re.VERBOSE
|
- re.MULTILINE|re.VERBOSE
|
||||||
- # fmt: on
|
- # fmt: on
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ _type_comment_re = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def single_literal_yapf_disable():
|
def single_literal_yapf_disable():
|
||||||
- """Black does not support this."""
|
- """Black does not support this."""
|
||||||
- BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
- BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ BAZ = {(1, 2), (1, 2), (1, 2)} # yapf: disable
|
||||||
|
|
||||||
|
|
||||||
-cfg.rule(
|
-cfg.rule(
|
||||||
|
@ -476,53 +525,142 @@ NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func_no_args():
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtFor
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def coroutine(arg, exec=False):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@asyncio.NOT_IMPLEMENTED_attr
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
def function_signature_stress_test(
|
||||||
|
number: int,
|
||||||
|
no_annotation=None,
|
||||||
|
text: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
debug: bool = False,
|
||||||
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
|
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces(
|
||||||
|
a=1,
|
||||||
|
b=(1, 2),
|
||||||
|
c=[],
|
||||||
|
d={NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e=True,
|
||||||
|
f=NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
h="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
i="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
offset = NOT_IMPLEMENTED_call()
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces_types(
|
||||||
|
a: int = 1,
|
||||||
|
b: tuple = (1, 2),
|
||||||
|
c: list = [],
|
||||||
|
d: dict = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e: bool = True,
|
||||||
|
f: int = NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
h: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
i: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces2(result=NOT_IMPLEMENTED_call()):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
something = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
something = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def subscriptlist():
|
||||||
|
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def import_as_names():
|
||||||
|
# fmt: off
|
||||||
|
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def testlist_star_expr():
|
||||||
|
# fmt: off
|
||||||
|
(1, 2) = NOT_YET_IMPLEMENTED_ExprStarred
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def yield_expr():
|
||||||
|
# fmt: off
|
||||||
|
NOT_YET_IMPLEMENTED_ExprYield
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: off
|
||||||
|
(NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example(session):
|
||||||
|
# fmt: off
|
||||||
|
result = NOT_IMPLEMENTED_call()
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def off_and_on_without_data():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: off
|
||||||
|
|
||||||
|
# hey, that won't work
|
||||||
|
|
||||||
|
# fmt: on
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def on_and_off_broken():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
# fmt: on
|
||||||
|
# fmt: off
|
||||||
|
this = NOT_IMPLEMENTED_call()
|
||||||
|
and_ = NOT_IMPLEMENTED_left < NOT_IMPLEMENTED_right
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
(
|
||||||
|
now.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr.NOT_IMPLEMENTED_attr
|
||||||
|
)
|
||||||
|
# fmt: on
|
||||||
|
# fmt: off
|
||||||
|
# ...but comments still get reformatted even though they should not be
|
||||||
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def long_lines():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
_type_comment_re = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def single_literal_yapf_disable():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
BAZ = {(1, 2), (1, 2), (1, 2)} # yapf: disable
|
||||||
|
|
||||||
|
|
||||||
NOT_IMPLEMENTED_call()
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
|
@ -75,20 +75,23 @@ async def test_async_with():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,62 +1,33 @@
|
@@ -1,62 +1,40 @@
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
-def some_func( unformatted, args ): # fmt: skip
|
-def some_func( unformatted, args ): # fmt: skip
|
||||||
- print("I am some_func")
|
- print("I am some_func")
|
||||||
- return 0
|
+def some_func(unformatted, args): # fmt: skip
|
||||||
- # Make sure this comment is not removed.
|
+ NOT_IMPLEMENTED_call()
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
return 0
|
||||||
|
# Make sure this comment is not removed.
|
||||||
|
|
||||||
|
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
-async def some_async_func( unformatted, args): # fmt: skip
|
-async def some_async_func( unformatted, args): # fmt: skip
|
||||||
- print("I am some_async_func")
|
- print("I am some_async_func")
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+async def some_async_func(unformatted, args): # fmt: skip
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
|
@ -96,13 +99,13 @@ async def test_async_with():
|
||||||
- def some_method( self, unformatted, args ): # fmt: skip
|
- def some_method( self, unformatted, args ): # fmt: skip
|
||||||
- print("I am some_method")
|
- print("I am some_method")
|
||||||
- return 0
|
- return 0
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
-
|
||||||
|
|
||||||
- async def some_async_method( self, unformatted, args ): # fmt: skip
|
- async def some_async_method( self, unformatted, args ): # fmt: skip
|
||||||
- print("I am some_async_method")
|
- print("I am some_async_method")
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-
|
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
-if unformatted_call( args ): # fmt: skip
|
-if unformatted_call( args ): # fmt: skip
|
||||||
- print("First branch")
|
- print("First branch")
|
||||||
|
@ -125,10 +128,10 @@ async def test_async_with():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
+NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
-async def test_async_for():
|
async def test_async_for():
|
||||||
- async for i in some_async_iter( unformatted, args ): # fmt: skip
|
- async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||||
- print("Do something")
|
- print("Do something")
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
-try : # fmt: skip
|
-try : # fmt: skip
|
||||||
|
@ -145,21 +148,26 @@ async def test_async_with():
|
||||||
+NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
+NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
-async def test_async_with():
|
async def test_async_with():
|
||||||
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||||
- print("Do something")
|
- print("Do something")
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def some_func(unformatted, args): # fmt: skip
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
return 0
|
||||||
|
# Make sure this comment is not removed.
|
||||||
|
|
||||||
|
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def some_async_func(unformatted, args): # fmt: skip
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Make sure a leading comment is not removed.
|
# Make sure a leading comment is not removed.
|
||||||
|
@ -177,7 +185,8 @@ while NOT_IMPLEMENTED_call(): # fmt: skip
|
||||||
NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def test_async_for():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtTry
|
NOT_YET_IMPLEMENTED_StmtTry
|
||||||
|
@ -186,7 +195,8 @@ NOT_YET_IMPLEMENTED_StmtTry
|
||||||
NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def test_async_with():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -66,11 +66,10 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,65 +1,12 @@
|
@@ -2,64 +2,27 @@
|
||||||
-def f(
|
a,
|
||||||
- a,
|
**kwargs,
|
||||||
- **kwargs,
|
) -> A:
|
||||||
-) -> A:
|
|
||||||
- with cache_dir():
|
- with cache_dir():
|
||||||
- if something:
|
- if something:
|
||||||
- result = CliRunner().invoke(
|
- result = CliRunner().invoke(
|
||||||
|
@ -82,19 +81,24 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
- very_long_argument_name2=-very.long.value.for_the_argument,
|
- very_long_argument_name2=-very.long.value.for_the_argument,
|
||||||
- **kwargs,
|
- **kwargs,
|
||||||
- )
|
- )
|
||||||
-
|
+ NOT_YET_IMPLEMENTED_StmtWith
|
||||||
-
|
+ NOT_IMPLEMENTED_call() # negate top
|
||||||
-def g():
|
+ return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
|
def g():
|
||||||
- "Docstring."
|
- "Docstring."
|
||||||
-
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
- def inner():
|
|
||||||
- pass
|
def inner():
|
||||||
-
|
pass
|
||||||
|
|
||||||
- print("Inner defs should breathe a little.")
|
- print("Inner defs should breathe a little.")
|
||||||
-
|
+ NOT_IMPLEMENTED_call()
|
||||||
-
|
|
||||||
-def h():
|
|
||||||
- def inner():
|
def h():
|
||||||
|
def inner():
|
||||||
- pass
|
- pass
|
||||||
-
|
-
|
||||||
- print("Inner defs should breathe a little.")
|
- print("Inner defs should breathe a little.")
|
||||||
|
@ -104,36 +108,34 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
- import termios
|
- import termios
|
||||||
-
|
-
|
||||||
- def i_should_be_followed_by_only_one_newline():
|
- def i_should_be_followed_by_only_one_newline():
|
||||||
- pass
|
pass
|
||||||
-
|
|
||||||
-elif os.name == "nt":
|
-elif os.name == "nt":
|
||||||
- try:
|
- try:
|
||||||
- import msvcrt
|
- import msvcrt
|
||||||
-
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
- def i_should_be_followed_by_only_one_newline():
|
- def i_should_be_followed_by_only_one_newline():
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
- except ImportError:
|
- except ImportError:
|
||||||
|
+NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
- def i_should_be_followed_by_only_one_newline():
|
- def i_should_be_followed_by_only_one_newline():
|
||||||
- pass
|
- pass
|
||||||
-
|
-
|
||||||
-elif False:
|
-elif False:
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
-
|
||||||
|
|
||||||
- class IHopeYouAreHavingALovelyDay:
|
- class IHopeYouAreHavingALovelyDay:
|
||||||
- def __call__(self):
|
- def __call__(self):
|
||||||
- print("i_should_be_followed_by_only_one_newline")
|
- print("i_should_be_followed_by_only_one_newline")
|
||||||
|
-
|
||||||
-else:
|
-else:
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
-
|
||||||
|
|
||||||
- def foo():
|
- def foo():
|
||||||
- pass
|
- pass
|
||||||
|
-
|
||||||
+NOT_YET_IMPLEMENTED_StmtIf
|
-
|
||||||
|
|
||||||
-with hmm_but_this_should_get_two_preceding_newlines():
|
-with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtWith
|
+NOT_YET_IMPLEMENTED_StmtWith
|
||||||
|
@ -142,13 +144,29 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a,
|
||||||
|
**kwargs,
|
||||||
|
) -> A:
|
||||||
|
NOT_YET_IMPLEMENTED_StmtWith
|
||||||
|
NOT_IMPLEMENTED_call() # negate top
|
||||||
|
return NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def g():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
def inner():
|
||||||
|
pass
|
||||||
|
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def h():
|
||||||
|
def inner():
|
||||||
|
pass
|
||||||
|
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtIf
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
|
@ -108,7 +108,7 @@ def __await__(): return (yield)
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,148 +1,41 @@
|
@@ -1,148 +1,94 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
-import asyncio
|
-import asyncio
|
||||||
-import sys
|
-import sys
|
||||||
|
@ -125,10 +125,10 @@ def __await__(): return (yield)
|
||||||
-f"trigger 3.6 mode"
|
-f"trigger 3.6 mode"
|
||||||
-
|
-
|
||||||
|
|
||||||
-def func_no_args():
|
def func_no_args():
|
||||||
- a
|
a
|
||||||
- b
|
b
|
||||||
- c
|
c
|
||||||
- if True:
|
- if True:
|
||||||
- raise RuntimeError
|
- raise RuntimeError
|
||||||
- if False:
|
- if False:
|
||||||
|
@ -137,59 +137,85 @@ def __await__(): return (yield)
|
||||||
- print(i)
|
- print(i)
|
||||||
- continue
|
- continue
|
||||||
- exec("new-style exec", {}, {})
|
- exec("new-style exec", {}, {})
|
||||||
- return None
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtFor
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
-async def coroutine(arg, exec=False):
|
async def coroutine(arg, exec=False):
|
||||||
- "Single-line docstring. Multiline is harder to reformat."
|
- "Single-line docstring. Multiline is harder to reformat."
|
||||||
- async with some_connection() as conn:
|
- async with some_connection() as conn:
|
||||||
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||||
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-@asyncio.coroutine
|
-@asyncio.coroutine
|
||||||
-@some_decorator(with_args=True, many_args=[1, 2, 3])
|
-@some_decorator(with_args=True, many_args=[1, 2, 3])
|
||||||
-def function_signature_stress_test(
|
+@asyncio.NOT_IMPLEMENTED_attr
|
||||||
- number: int,
|
+@NOT_IMPLEMENTED_call()
|
||||||
- no_annotation=None,
|
def function_signature_stress_test(
|
||||||
|
number: int,
|
||||||
|
no_annotation=None,
|
||||||
- text: str = "default",
|
- text: str = "default",
|
||||||
- *,
|
- *,
|
||||||
- debug: bool = False,
|
+ text: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
- **kwargs,
|
debug: bool = False,
|
||||||
-) -> str:
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
- return text[number:-1]
|
- return text[number:-1]
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
||||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+def spaces(
|
||||||
|
+ a=1,
|
||||||
|
+ b=(1, 2),
|
||||||
|
+ c=[],
|
||||||
|
+ d={NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
+ e=True,
|
||||||
|
+ f=NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
+ g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
+ h="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+ i="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+):
|
||||||
|
+ offset = NOT_IMPLEMENTED_call()
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
-def spaces_types(
|
def spaces_types(
|
||||||
- a: int = 1,
|
a: int = 1,
|
||||||
- b: tuple = (),
|
- b: tuple = (),
|
||||||
- c: list = [],
|
+ b: tuple = (1, 2),
|
||||||
|
c: list = [],
|
||||||
- d: dict = {},
|
- d: dict = {},
|
||||||
- e: bool = True,
|
+ d: dict = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e: bool = True,
|
||||||
- f: int = -1,
|
- f: int = -1,
|
||||||
- g: int = 1 if False else 2,
|
- g: int = 1 if False else 2,
|
||||||
- h: str = "",
|
- h: str = "",
|
||||||
- i: str = r"",
|
- i: str = r"",
|
||||||
-):
|
+ f: int = NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
- ...
|
+ g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ h: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
+ i: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
-def spaces2(result=_core.Value(None)):
|
-def spaces2(result=_core.Value(None)):
|
||||||
- assert fut is self._read_fut, (fut, self._read_fut)
|
- assert fut is self._read_fut, (fut, self._read_fut)
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+def spaces2(result=NOT_IMPLEMENTED_call()):
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
-def example(session):
|
def example(session):
|
||||||
- result = (
|
- result = (
|
||||||
- session.query(models.Customer.id)
|
- session.query(models.Customer.id)
|
||||||
- .filter(
|
- .filter(
|
||||||
|
@ -199,10 +225,10 @@ def __await__(): return (yield)
|
||||||
- .order_by(models.Customer.id.asc())
|
- .order_by(models.Customer.id.asc())
|
||||||
- .all()
|
- .all()
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ result = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def long_lines():
|
def long_lines():
|
||||||
- if True:
|
- if True:
|
||||||
- typedargslist.extend(
|
- typedargslist.extend(
|
||||||
- gen_annotated_params(
|
- gen_annotated_params(
|
||||||
|
@ -243,23 +269,24 @@ def __await__(): return (yield)
|
||||||
- """,
|
- """,
|
||||||
- re.MULTILINE | re.VERBOSE,
|
- re.MULTILINE | re.VERBOSE,
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
+ _type_comment_re = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def trailing_comma():
|
def trailing_comma():
|
||||||
- mapping = {
|
- mapping = {
|
||||||
- A: 0.25 * (10.0 / 12),
|
- A: 0.25 * (10.0 / 12),
|
||||||
- B: 0.1 * (10.0 / 12),
|
- B: 0.1 * (10.0 / 12),
|
||||||
- C: 0.1 * (10.0 / 12),
|
- C: 0.1 * (10.0 / 12),
|
||||||
- D: 0.1 * (10.0 / 12),
|
- D: 0.1 * (10.0 / 12),
|
||||||
- }
|
- }
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
def f(
|
||||||
- a,
|
a,
|
||||||
- **kwargs,
|
**kwargs,
|
||||||
-) -> A:
|
) -> A:
|
||||||
- return (
|
- return (
|
||||||
- yield from A(
|
- yield from A(
|
||||||
- very_long_argument_name1=very_long_value_for_the_argument,
|
- very_long_argument_name1=very_long_value_for_the_argument,
|
||||||
|
@ -267,12 +294,12 @@ def __await__(): return (yield)
|
||||||
- **kwargs,
|
- **kwargs,
|
||||||
- )
|
- )
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||||
|
|
||||||
|
|
||||||
-def __await__():
|
def __await__():
|
||||||
- return (yield)
|
- return (yield)
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_YET_IMPLEMENTED_ExprYield
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -288,37 +315,90 @@ NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func_no_args():
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
NOT_YET_IMPLEMENTED_StmtFor
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def coroutine(arg, exec=False):
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
@asyncio.NOT_IMPLEMENTED_attr
|
||||||
|
@NOT_IMPLEMENTED_call()
|
||||||
|
def function_signature_stress_test(
|
||||||
|
number: int,
|
||||||
|
no_annotation=None,
|
||||||
|
text: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
debug: bool = False,
|
||||||
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
|
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces(
|
||||||
|
a=1,
|
||||||
|
b=(1, 2),
|
||||||
|
c=[],
|
||||||
|
d={NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e=True,
|
||||||
|
f=NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
g=NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
h="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
i="NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
offset = NOT_IMPLEMENTED_call()
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces_types(
|
||||||
|
a: int = 1,
|
||||||
|
b: tuple = (1, 2),
|
||||||
|
c: list = [],
|
||||||
|
d: dict = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value},
|
||||||
|
e: bool = True,
|
||||||
|
f: int = NOT_YET_IMPLEMENTED_ExprUnaryOp,
|
||||||
|
g: int = NOT_IMPLEMENTED_true if NOT_IMPLEMENTED_cond else NOT_IMPLEMENTED_false,
|
||||||
|
h: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
i: str = "NOT_YET_IMPLEMENTED_STRING",
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def spaces2(result=NOT_IMPLEMENTED_call()):
|
||||||
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example(session):
|
||||||
|
result = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def long_lines():
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
_type_comment_re = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def trailing_comma():
|
||||||
|
mapping = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a,
|
||||||
|
**kwargs,
|
||||||
|
) -> A:
|
||||||
|
return NOT_YET_IMPLEMENTED_ExprYieldFrom
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def __await__():
|
||||||
|
return NOT_YET_IMPLEMENTED_ExprYield
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -74,21 +74,22 @@ some_module.some_function(
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,114 +1,31 @@
|
@@ -1,69 +1,29 @@
|
||||||
-def f(
|
def f(
|
||||||
- a,
|
a,
|
||||||
-):
|
):
|
||||||
- d = {
|
- d = {
|
||||||
- "key": "value",
|
- "key": "value",
|
||||||
- }
|
- }
|
||||||
- tup = (1,)
|
- tup = (1,)
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
+ tup = (1, 2)
|
||||||
|
|
||||||
|
|
||||||
-def f2(
|
def f2(
|
||||||
- a,
|
a,
|
||||||
- b,
|
b,
|
||||||
-):
|
):
|
||||||
- d = {
|
- d = {
|
||||||
- "key": "value",
|
- "key": "value",
|
||||||
- "key2": "value2",
|
- "key2": "value2",
|
||||||
|
@ -97,12 +98,13 @@ some_module.some_function(
|
||||||
- 1,
|
- 1,
|
||||||
- 2,
|
- 2,
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
+ tup = (1, 2)
|
||||||
|
|
||||||
|
|
||||||
-def f(
|
def f(
|
||||||
- a: int = 1,
|
a: int = 1,
|
||||||
-):
|
):
|
||||||
- call(
|
- call(
|
||||||
- arg={
|
- arg={
|
||||||
- "explode": "this",
|
- "explode": "this",
|
||||||
|
@ -129,7 +131,10 @@ some_module.some_function(
|
||||||
- }["a"]
|
- }["a"]
|
||||||
- ):
|
- ):
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ x = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
-def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
-def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||||
|
@ -144,23 +149,13 @@ some_module.some_function(
|
||||||
- }
|
- }
|
||||||
- }
|
- }
|
||||||
- }
|
- }
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
|
+ json = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
@@ -80,35 +40,16 @@
|
||||||
-def some_function_with_a_really_long_name() -> (
|
pass
|
||||||
- returning_a_deeply_nested_import_of_a_type_i_suppose
|
|
||||||
-):
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def some_method_with_a_really_long_name(
|
|
||||||
- very_long_parameter_so_yeah: str, another_long_parameter: int
|
|
||||||
-) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
|
||||||
- pass
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def func() -> (
|
-def func() -> (
|
||||||
|
@ -168,8 +163,8 @@ some_module.some_function(
|
||||||
- this_shouldn_t_get_a_trailing_comma_too
|
- this_shouldn_t_get_a_trailing_comma_too
|
||||||
- )
|
- )
|
||||||
-):
|
-):
|
||||||
- pass
|
+def func() -> NOT_IMPLEMENTED_call():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
-def func() -> (
|
-def func() -> (
|
||||||
|
@ -177,8 +172,8 @@ some_module.some_function(
|
||||||
- this_shouldn_t_get_a_trailing_comma_too
|
- this_shouldn_t_get_a_trailing_comma_too
|
||||||
- )
|
- )
|
||||||
-):
|
-):
|
||||||
- pass
|
+def func() -> NOT_IMPLEMENTED_call():
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Make sure inner one-element tuple won't explode
|
# Make sure inner one-element tuple won't explode
|
||||||
|
@ -204,30 +199,54 @@ some_module.some_function(
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
tup = (1, 2)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f2(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
d = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
tup = (1, 2)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def f(
|
||||||
|
a: int = 1,
|
||||||
|
):
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
x = NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
|
json = {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def some_function_with_a_really_long_name() -> (
|
||||||
|
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def some_method_with_a_really_long_name(
|
||||||
|
very_long_parameter_so_yeah: str, another_long_parameter: int
|
||||||
|
) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func() -> NOT_IMPLEMENTED_call():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func() -> NOT_IMPLEMENTED_call():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Make sure inner one-element tuple won't explode
|
# Make sure inner one-element tuple won't explode
|
||||||
|
|
|
@ -76,21 +76,12 @@ return np.divide(
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,63 +1,51 @@
|
@@ -8,56 +8,48 @@
|
||||||
-def function(**kwargs):
|
|
||||||
- t = a**2 + b**3
|
|
||||||
- return t**2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def function_replace_spaces(**kwargs):
|
def function_dont_replace_spaces():
|
||||||
- t = a**2 + b**3 + c**4
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def function_dont_replace_spaces():
|
|
||||||
- {**a, **b, **c}
|
- {**a, **b, **c}
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
-a = 5**~4
|
-a = 5**~4
|
||||||
|
@ -184,13 +175,17 @@ return np.divide(
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function(**kwargs):
|
||||||
|
t = a**2 + b**3
|
||||||
|
return t**2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function_replace_spaces(**kwargs):
|
||||||
|
t = a**2 + b**3 + c**4
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def function_dont_replace_spaces():
|
||||||
|
{NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value}
|
||||||
|
|
||||||
|
|
||||||
a = 5**NOT_YET_IMPLEMENTED_ExprUnaryOp
|
a = 5**NOT_YET_IMPLEMENTED_ExprUnaryOp
|
||||||
|
|
|
@ -94,51 +94,58 @@ async def main():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,93 +1,60 @@
|
@@ -1,66 +1,57 @@
|
||||||
-import asyncio
|
-import asyncio
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
# Control example
|
# Control example
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Remove brackets for short coroutine/task
|
# Remove brackets for short coroutine/task
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1)
|
- await asyncio.sleep(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# Check comments
|
# Check comments
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1) # Hello
|
- await asyncio.sleep(1) # Hello
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ (
|
||||||
|
+ await # Hello
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
+ )
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1) # Hello
|
- await asyncio.sleep(1) # Hello
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ (
|
||||||
|
+ await (
|
||||||
|
+ NOT_IMPLEMENTED_call() # Hello
|
||||||
|
+ )
|
||||||
|
+ )
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.sleep(1) # Hello
|
- await asyncio.sleep(1) # Hello
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_IMPLEMENTED_call()) # Hello
|
||||||
|
|
||||||
|
|
||||||
# Long lines
|
# Long lines
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.gather(
|
- await asyncio.gather(
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
|
@ -148,11 +155,11 @@ async def main():
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Same as above but with magic trailing comma in function
|
# Same as above but with magic trailing comma in function
|
||||||
-async def main():
|
async def main():
|
||||||
- await asyncio.gather(
|
- await asyncio.gather(
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
|
@ -162,50 +169,46 @@ async def main():
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- asyncio.sleep(1),
|
- asyncio.sleep(1),
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Cr@zY Br@ck3Tz
|
# Cr@zY Br@ck3Tz
|
||||||
-async def main():
|
async def main():
|
||||||
- await black(1)
|
- await black(1)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# Keep brackets around non power operations and nested awaits
|
# Keep brackets around non power operations and nested awaits
|
||||||
-async def main():
|
@@ -69,7 +60,7 @@
|
||||||
- await (set_of_tasks | other_set)
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await (await asyncio.sleep(1))
|
- await (await asyncio.sleep(1))
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (await NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# It's awaits all the way down...
|
# It's awaits all the way down...
|
||||||
-async def main():
|
@@ -78,16 +69,16 @@
|
||||||
- await (await x)
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await (yield x)
|
- await (yield x)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await (await asyncio.sleep(1))
|
- await (await asyncio.sleep(1))
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (await (NOT_IMPLEMENTED_call()))
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await (await (await (await (await asyncio.sleep(1)))))
|
- await (await (await (await (await asyncio.sleep(1)))))
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (await (await (await (await (NOT_IMPLEMENTED_call())))))
|
||||||
|
|
||||||
|
|
||||||
-async def main():
|
async def main():
|
||||||
- await (yield)
|
- await (yield)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -215,62 +218,86 @@ NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
# Control example
|
# Control example
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Remove brackets for short coroutine/task
|
# Remove brackets for short coroutine/task
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# Check comments
|
# Check comments
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
(
|
||||||
|
await # Hello
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
(
|
||||||
|
await (
|
||||||
|
NOT_IMPLEMENTED_call() # Hello
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_IMPLEMENTED_call()) # Hello
|
||||||
|
|
||||||
|
|
||||||
# Long lines
|
# Long lines
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Same as above but with magic trailing comma in function
|
# Same as above but with magic trailing comma in function
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Cr@zY Br@ck3Tz
|
# Cr@zY Br@ck3Tz
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# Keep brackets around non power operations and nested awaits
|
# Keep brackets around non power operations and nested awaits
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (set_of_tasks | other_set)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (await NOT_IMPLEMENTED_call())
|
||||||
|
|
||||||
|
|
||||||
# It's awaits all the way down...
|
# It's awaits all the way down...
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (await x)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (await (NOT_IMPLEMENTED_call()))
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (await (await (await (await (NOT_IMPLEMENTED_call())))))
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def main():
|
||||||
|
await (NOT_YET_IMPLEMENTED_ExprYield)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -121,40 +121,40 @@ with open("/path/to/file.txt", mode="r") as read_file:
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,78 +1,56 @@
|
@@ -1,78 +1,64 @@
|
||||||
-import random
|
-import random
|
||||||
+NOT_YET_IMPLEMENTED_StmtImport
|
+NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
-def foo1():
|
def foo1():
|
||||||
- print("The newline above me should be deleted!")
|
- print("The newline above me should be deleted!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def foo2():
|
def foo2():
|
||||||
- print("All the newlines above me should be deleted!")
|
- print("All the newlines above me should be deleted!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-def foo3():
|
def foo3():
|
||||||
- print("No newline above me!")
|
- print("No newline above me!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
- print("There is a newline above me, and that's OK!")
|
- print("There is a newline above me, and that's OK!")
|
||||||
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
-def foo4():
|
def foo4():
|
||||||
- # There is a comment here
|
# There is a comment here
|
||||||
|
|
||||||
- print("The newline above me should not be deleted!")
|
- print("The newline above me should not be deleted!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-class Foo:
|
-class Foo:
|
||||||
- def bar(self):
|
- def bar(self):
|
||||||
- print("The newline above me should be deleted!")
|
- print("The newline above me should be deleted!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtFor
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-for i in range(5):
|
-for i in range(5):
|
||||||
|
@ -170,8 +170,9 @@ with open("/path/to/file.txt", mode="r") as read_file:
|
||||||
-for i in range(5):
|
-for i in range(5):
|
||||||
- for j in range(7):
|
- for j in range(7):
|
||||||
- print(f"{i}) The lines above me should be removed!")
|
- print(f"{i}) The lines above me should be removed!")
|
||||||
-
|
+NOT_YET_IMPLEMENTED_StmtFor
|
||||||
-
|
|
||||||
|
|
||||||
-if random.randint(0, 3) == 0:
|
-if random.randint(0, 3) == 0:
|
||||||
- print("The new line above me is about to be removed!")
|
- print("The new line above me is about to be removed!")
|
||||||
+NOT_YET_IMPLEMENTED_StmtIf
|
+NOT_YET_IMPLEMENTED_StmtIf
|
||||||
|
@ -226,16 +227,24 @@ with open("/path/to/file.txt", mode="r") as read_file:
|
||||||
NOT_YET_IMPLEMENTED_StmtImport
|
NOT_YET_IMPLEMENTED_StmtImport
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo1():
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo2():
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo3():
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo4():
|
||||||
|
# There is a comment here
|
||||||
|
|
||||||
|
NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
|
@ -68,7 +68,7 @@ def example8():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,85 +1,37 @@
|
@@ -1,24 +1,16 @@
|
||||||
x = 1
|
x = 1
|
||||||
x = 1.2
|
x = 1.2
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ def example8():
|
||||||
+data = NOT_IMPLEMENTED_call()
|
+data = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
-async def show_status():
|
async def show_status():
|
||||||
- while True:
|
while True:
|
||||||
- try:
|
- try:
|
||||||
- if report_host:
|
- if report_host:
|
||||||
- data = (
|
- data = (
|
||||||
|
@ -87,54 +87,47 @@ def example8():
|
||||||
- ).encode()
|
- ).encode()
|
||||||
- except Exception as e:
|
- except Exception as e:
|
||||||
- pass
|
- pass
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ NOT_YET_IMPLEMENTED_StmtTry
|
||||||
|
|
||||||
|
|
||||||
-def example():
|
def example():
|
||||||
- return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
- return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def example1():
|
def example1():
|
||||||
- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
@@ -30,15 +22,11 @@
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def example1point5():
|
def example2():
|
||||||
- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def example2():
|
|
||||||
- return (
|
- return (
|
||||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def example3():
|
def example3():
|
||||||
- return (
|
- return (
|
||||||
- 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
- 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
-def example4():
|
def example4():
|
||||||
- return True
|
@@ -46,39 +34,15 @@
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def example5():
|
def example5():
|
||||||
- return ()
|
- return ()
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return (1, 2)
|
||||||
|
|
||||||
|
|
||||||
-def example6():
|
def example6():
|
||||||
- return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
|
- return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
|
|
||||||
|
|
||||||
-def example7():
|
def example7():
|
||||||
- return {
|
- return {
|
||||||
- a: a
|
- a: a
|
||||||
- for a in [
|
- for a in [
|
||||||
|
@ -160,12 +153,10 @@ def example8():
|
||||||
- 20000000000000000000,
|
- 20000000000000000000,
|
||||||
- ]
|
- ]
|
||||||
- }
|
- }
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
|
|
||||||
|
|
||||||
-def example8():
|
def example8():
|
||||||
- return None
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -177,37 +168,49 @@ x = 1.2
|
||||||
data = NOT_IMPLEMENTED_call()
|
data = NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def show_status():
|
||||||
|
while True:
|
||||||
|
NOT_YET_IMPLEMENTED_StmtTry
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example():
|
||||||
|
return "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example1():
|
||||||
|
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example1point5():
|
||||||
|
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example2():
|
||||||
|
return "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example3():
|
||||||
|
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example4():
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example5():
|
||||||
|
return (1, 2)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example6():
|
||||||
|
return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example7():
|
||||||
|
return {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def example8():
|
||||||
|
return None
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -101,123 +101,35 @@ def foo() -> tuple[int, int, int,]:
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,120 +1,65 @@
|
@@ -26,7 +26,9 @@
|
||||||
# Control
|
return 2 * a
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Remove the brackets
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Some newline variations
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Don't lose the comments
|
|
||||||
-def double(a: int) -> int: # Hello
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def double(a: int) -> int: # Hello
|
-def double(a: int) -> int: # Hello
|
||||||
- return 2 * a
|
+def double(a: int) -> (
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ int # Hello
|
||||||
|
+):
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
# Really long annotations
|
@@ -54,7 +56,9 @@
|
||||||
-def foo() -> (
|
a: int,
|
||||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
b: int,
|
||||||
-):
|
c: int,
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def foo() -> (
|
|
||||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
-):
|
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def foo() -> (
|
|
||||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
-):
|
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def foo(
|
|
||||||
- a: int,
|
|
||||||
- b: int,
|
|
||||||
- c: int,
|
|
||||||
-) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
-) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
- return 2
|
+) -> (
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
+):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
-def foo(
|
@@ -95,26 +99,14 @@
|
||||||
- a: int,
|
|
||||||
- b: int,
|
|
||||||
- c: int,
|
|
||||||
-) -> (
|
|
||||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
-):
|
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Split args but no need to split return
|
|
||||||
-def foo(
|
|
||||||
- a: int,
|
|
||||||
- b: int,
|
|
||||||
- c: int,
|
|
||||||
-) -> int:
|
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Deeply nested brackets
|
|
||||||
# with *interesting* spacing
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def double(a: int) -> int:
|
|
||||||
- return 2 * a
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
-def foo() -> (
|
|
||||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
|
||||||
-):
|
|
||||||
- return 2
|
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
|
||||||
|
|
||||||
|
|
||||||
# Return type with commas
|
# Return type with commas
|
||||||
-def foo() -> tuple[int, int, int]:
|
-def foo() -> tuple[int, int, int]:
|
||||||
- return 2
|
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
return 2
|
||||||
|
|
||||||
|
|
||||||
-def foo() -> (
|
-def foo() -> (
|
||||||
|
@ -227,8 +139,8 @@ def foo() -> tuple[int, int, int,]:
|
||||||
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||||
- ]
|
- ]
|
||||||
-):
|
-):
|
||||||
- return 2
|
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
return 2
|
||||||
|
|
||||||
|
|
||||||
# Magic trailing comma example
|
# Magic trailing comma example
|
||||||
|
@ -239,78 +151,125 @@ def foo() -> tuple[int, int, int,]:
|
||||||
- int,
|
- int,
|
||||||
- ]
|
- ]
|
||||||
-):
|
-):
|
||||||
- return 2
|
+def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
return 2
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
# Control
|
# Control
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
# Remove the brackets
|
# Remove the brackets
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
# Some newline variations
|
# Some newline variations
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
# Don't lose the comments
|
# Don't lose the comments
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int: # Hello
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> (
|
||||||
|
int # Hello
|
||||||
|
):
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
# Really long annotations
|
# Really long annotations
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
# Split args but no need to split return
|
# Split args but no need to split return
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> int:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
# Deeply nested brackets
|
# Deeply nested brackets
|
||||||
# with *interesting* spacing
|
# with *interesting* spacing
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
# Return type with commas
|
# Return type with commas
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
# Magic trailing comma example
|
# Magic trailing comma example
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def foo() -> NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]:
|
||||||
|
return 2
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -76,7 +76,7 @@ x[
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,59 +1,37 @@
|
@@ -1,59 +1,38 @@
|
||||||
-slice[a.b : c.d]
|
-slice[a.b : c.d]
|
||||||
-slice[d :: d + 1]
|
-slice[d :: d + 1]
|
||||||
-slice[d + 1 :: d]
|
-slice[d + 1 :: d]
|
||||||
|
@ -117,9 +117,9 @@ x[
|
||||||
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
+NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
-async def f():
|
async def f():
|
||||||
- slice[await x : [i async for i in arange(42)] : 42]
|
- slice[await x : [i async for i in arange(42)] : 42]
|
||||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
+ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
# These are from PEP-8:
|
# These are from PEP-8:
|
||||||
|
@ -191,7 +191,8 @@ NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
async def f():
|
||||||
|
NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
# These are from PEP-8:
|
# These are from PEP-8:
|
||||||
|
|
|
@ -33,7 +33,7 @@ def docstring_multiline():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,20 +1,16 @@
|
@@ -1,20 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
-name = "Łukasz"
|
-name = "Łukasz"
|
||||||
|
@ -53,16 +53,16 @@ def docstring_multiline():
|
||||||
+(1, 2)
|
+(1, 2)
|
||||||
|
|
||||||
|
|
||||||
-def docstring_singleline():
|
def docstring_singleline():
|
||||||
- R"""2020 was one hell of a year. The good news is that we were able to"""
|
- R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
-def docstring_multiline():
|
def docstring_multiline():
|
||||||
- R"""
|
- R"""
|
||||||
- clear out all of the issues opened in that time :p
|
- clear out all of the issues opened in that time :p
|
||||||
- """
|
- """
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ "NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -80,10 +80,12 @@ name = "NOT_YET_IMPLEMENTED_STRING"
|
||||||
(1, 2)
|
(1, 2)
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_singleline():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def docstring_multiline():
|
||||||
|
"NOT_YET_IMPLEMENTED_STRING"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -42,7 +42,7 @@ assert (
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,58 +1,21 @@
|
@@ -1,58 +1,22 @@
|
||||||
importA
|
importA
|
||||||
(
|
(
|
||||||
- ()
|
- ()
|
||||||
|
@ -79,7 +79,7 @@ assert (
|
||||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
-def test(self, othr):
|
def test(self, othr):
|
||||||
- return 1 == 2 and (
|
- return 1 == 2 and (
|
||||||
- name,
|
- name,
|
||||||
- description,
|
- description,
|
||||||
|
@ -99,7 +99,7 @@ assert (
|
||||||
- othr.meta_data,
|
- othr.meta_data,
|
||||||
- othr.schedule,
|
- othr.schedule,
|
||||||
- )
|
- )
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2
|
||||||
|
|
||||||
|
|
||||||
-assert a_function(
|
-assert a_function(
|
||||||
|
@ -129,7 +129,8 @@ importA
|
||||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def test(self, othr):
|
||||||
|
return NOT_IMPLEMENTED_bool_op1 and NOT_IMPLEMENTED_bool_op2
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAssert
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
|
@ -46,7 +46,7 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,50 +1,20 @@
|
@@ -1,50 +1,21 @@
|
||||||
-zero(
|
-zero(
|
||||||
- one,
|
- one,
|
||||||
-).two(
|
-).two(
|
||||||
|
@ -79,14 +79,14 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||||
|
|
||||||
|
|
||||||
# Example from https://github.com/psf/black/issues/3229
|
# Example from https://github.com/psf/black/issues/3229
|
||||||
-def refresh_token(self, device_family, refresh_token, api_key):
|
def refresh_token(self, device_family, refresh_token, api_key):
|
||||||
- return self.orchestration.refresh_token(
|
- return self.orchestration.refresh_token(
|
||||||
- data={
|
- data={
|
||||||
- "refreshToken": refresh_token,
|
- "refreshToken": refresh_token,
|
||||||
- },
|
- },
|
||||||
- api_key=api_key,
|
- api_key=api_key,
|
||||||
- )["extensions"]["sdk"]["token"]
|
- )["extensions"]["sdk"]["token"]
|
||||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
+ return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
# Edge case where a bug in a working-in-progress version of
|
# Edge case where a bug in a working-in-progress version of
|
||||||
|
@ -120,7 +120,8 @@ NOT_IMPLEMENTED_call()
|
||||||
|
|
||||||
|
|
||||||
# Example from https://github.com/psf/black/issues/3229
|
# Example from https://github.com/psf/black/issues/3229
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def refresh_token(self, device_family, refresh_token, api_key):
|
||||||
|
return NOT_IMPLEMENTED_value[NOT_IMPLEMENTED_key]
|
||||||
|
|
||||||
|
|
||||||
# Edge case where a bug in a working-in-progress version of
|
# Edge case where a bug in a working-in-progress version of
|
||||||
|
|
|
@ -0,0 +1,182 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/src/lib.rs
|
||||||
|
expression: snapshot
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
```py
|
||||||
|
# Dangling comments
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
|
||||||
|
# another
|
||||||
|
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
# Argument empty line spacing
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
|
||||||
|
# another
|
||||||
|
|
||||||
|
b,
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
### Different function argument wrappings
|
||||||
|
|
||||||
|
def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def arguments_on_their_own_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def argument_per_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc, ddddddddddddd, eeeeeeeeeeeeeeee, ffffffffffff):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def last_pos_only_trailing_comma(a, b, /,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def last_pos_no_trailing_comma(a, b, /):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def varg_with_leading_comments(
|
||||||
|
a, b,
|
||||||
|
# comment
|
||||||
|
*args
|
||||||
|
): ...
|
||||||
|
|
||||||
|
def kwarg_with_leading_comments(
|
||||||
|
a, b,
|
||||||
|
# comment
|
||||||
|
**kwargs
|
||||||
|
): ...
|
||||||
|
|
||||||
|
def argument_with_long_default(
|
||||||
|
a,
|
||||||
|
b = ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc + [
|
||||||
|
dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff
|
||||||
|
],
|
||||||
|
h = []
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
def argument_with_long_type_annotation(
|
||||||
|
a,
|
||||||
|
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||||
|
h = []
|
||||||
|
): ...
|
||||||
|
|
||||||
|
|
||||||
|
def test(): ...
|
||||||
|
|
||||||
|
# Comment
|
||||||
|
def with_leading_comment(): ...
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Output
|
||||||
|
```py
|
||||||
|
# Dangling comments
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
# another
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
# Argument empty line spacing
|
||||||
|
def test(
|
||||||
|
# comment
|
||||||
|
a,
|
||||||
|
# another
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
### Different function argument wrappings
|
||||||
|
|
||||||
|
def single_line(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccccccccc):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def arguments_on_their_own_line(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbb, ccccccccccc, ddddddddddddd, eeeeeee
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def argument_per_line(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
||||||
|
bbbbbbbbbbbbbbb,
|
||||||
|
ccccccccccccccccc,
|
||||||
|
ddddddddddddd,
|
||||||
|
eeeeeeeeeeeeeeee,
|
||||||
|
ffffffffffff,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def last_pos_only_trailing_comma(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
/,
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def last_pos_no_trailing_comma(a, b, /):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def varg_with_leading_comments(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
# comment
|
||||||
|
*args,
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def kwarg_with_leading_comments(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
# comment
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def argument_with_long_default(
|
||||||
|
a,
|
||||||
|
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||||
|
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
||||||
|
h=[],
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def argument_with_long_type_annotation(
|
||||||
|
a,
|
||||||
|
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
|
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||||
|
h=[],
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
def test():
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
# Comment
|
||||||
|
def with_leading_comment():
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -21,17 +21,13 @@ a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakj
|
||||||
## Output
|
## Output
|
||||||
```py
|
```py
|
||||||
# break left hand side
|
# break left hand side
|
||||||
a1akjdshflkjahdslkfjlasfdahjlfds = bakjdshflkjahdslkfjlasfdahjlfds = cakjdshflkjahdslkfjlasfdahjlfds = kjaödkjaföjfahlfdalfhaöfaöfhaöfha = fkjaödkjaföjfahlfdalfhaöfaöfhaöfha = g = (
|
a1akjdshflkjahdslkfjlasfdahjlfds = bakjdshflkjahdslkfjlasfdahjlfds = cakjdshflkjahdslkfjlasfdahjlfds = kjaödkjaföjfahlfdalfhaöfaöfhaöfha = fkjaödkjaföjfahlfdalfhaöfaöfhaöfha = g = 3
|
||||||
3
|
|
||||||
)
|
|
||||||
|
|
||||||
# join left hand side
|
# join left hand side
|
||||||
a2 = (b2) = 2
|
a2 = (b2) = 2
|
||||||
|
|
||||||
# Break the last element
|
# Break the last element
|
||||||
a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = (
|
a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = 1
|
||||||
1
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
use crate::prelude::*;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::FormatNodeRule;
|
||||||
|
use ruff_python_ast::function::AnyFunctionDefinition;
|
||||||
use rustpython_parser::ast::StmtAsyncFunctionDef;
|
use rustpython_parser::ast::StmtAsyncFunctionDef;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -7,6 +8,15 @@ pub struct FormatStmtAsyncFunctionDef;
|
||||||
|
|
||||||
impl FormatNodeRule<StmtAsyncFunctionDef> for FormatStmtAsyncFunctionDef {
|
impl FormatNodeRule<StmtAsyncFunctionDef> for FormatStmtAsyncFunctionDef {
|
||||||
fn fmt_fields(&self, item: &StmtAsyncFunctionDef, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &StmtAsyncFunctionDef, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented(item)])
|
AnyFunctionDefinition::from(item).format().fmt(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fmt_dangling_comments(
|
||||||
|
&self,
|
||||||
|
_node: &StmtAsyncFunctionDef,
|
||||||
|
_f: &mut PyFormatter,
|
||||||
|
) -> FormatResult<()> {
|
||||||
|
// Handled by `AnyFunctionDef`
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,141 @@
|
||||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
use crate::comments::{leading_comments, trailing_comments};
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::context::NodeLevel;
|
||||||
use rustpython_parser::ast::StmtFunctionDef;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::trivia::{lines_after, skip_trailing_trivia};
|
||||||
|
use crate::FormatNodeRule;
|
||||||
|
use ruff_formatter::{write, FormatOwnedWithRule, FormatRefWithRule};
|
||||||
|
use ruff_python_ast::function::AnyFunctionDefinition;
|
||||||
|
use rustpython_parser::ast::{Ranged, StmtFunctionDef};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatStmtFunctionDef;
|
pub struct FormatStmtFunctionDef;
|
||||||
|
|
||||||
impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||||
fn fmt_fields(&self, item: &StmtFunctionDef, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &StmtFunctionDef, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented(item)])
|
AnyFunctionDefinition::from(item).format().fmt(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fmt_dangling_comments(
|
||||||
|
&self,
|
||||||
|
_node: &StmtFunctionDef,
|
||||||
|
_f: &mut PyFormatter,
|
||||||
|
) -> FormatResult<()> {
|
||||||
|
// Handled by `AnyFunctionDef`
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct FormatAnyFunctionDef;
|
||||||
|
|
||||||
|
impl FormatRule<AnyFunctionDefinition<'_>, PyFormatContext<'_>> for FormatAnyFunctionDef {
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
item: &AnyFunctionDefinition<'_>,
|
||||||
|
f: &mut Formatter<PyFormatContext<'_>>,
|
||||||
|
) -> FormatResult<()> {
|
||||||
|
let comments = f.context().comments().clone();
|
||||||
|
|
||||||
|
let dangling_comments = comments.dangling_comments(item.into());
|
||||||
|
let trailing_definition_comments_start =
|
||||||
|
dangling_comments.partition_point(|comment| comment.position().is_own_line());
|
||||||
|
|
||||||
|
let (leading_function_definition_comments, trailing_definition_comments) =
|
||||||
|
dangling_comments.split_at(trailing_definition_comments_start);
|
||||||
|
|
||||||
|
if let Some(last_decorator) = item.decorators().last() {
|
||||||
|
f.join_nodes(NodeLevel::CompoundStatement)
|
||||||
|
.nodes(item.decorators())
|
||||||
|
.finish()?;
|
||||||
|
|
||||||
|
if leading_function_definition_comments.is_empty() {
|
||||||
|
write!(f, [hard_line_break()])?;
|
||||||
|
} else {
|
||||||
|
// Write any leading function comments (between last decorator and function header)
|
||||||
|
// while maintaining the right amount of empty lines between the comment
|
||||||
|
// and the last decorator.
|
||||||
|
let decorator_end =
|
||||||
|
skip_trailing_trivia(last_decorator.end(), f.context().contents());
|
||||||
|
|
||||||
|
let leading_line = if lines_after(decorator_end, f.context().contents()) <= 1 {
|
||||||
|
hard_line_break()
|
||||||
|
} else {
|
||||||
|
empty_line()
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
leading_line,
|
||||||
|
leading_comments(leading_function_definition_comments)
|
||||||
|
]
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.is_async() {
|
||||||
|
write!(f, [text("async"), space()])?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = item.name();
|
||||||
|
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
text("def"),
|
||||||
|
space(),
|
||||||
|
dynamic_text(name.as_str(), None),
|
||||||
|
item.arguments().format(),
|
||||||
|
]
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if let Some(return_annotation) = item.returns() {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
space(),
|
||||||
|
text("->"),
|
||||||
|
space(),
|
||||||
|
return_annotation
|
||||||
|
.format()
|
||||||
|
.with_options(Parenthesize::IfBreaks)
|
||||||
|
]
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
[
|
||||||
|
text(":"),
|
||||||
|
trailing_comments(trailing_definition_comments),
|
||||||
|
block_indent(&item.body().format())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'def, 'ast> AsFormat<PyFormatContext<'ast>> for AnyFunctionDefinition<'def> {
|
||||||
|
type Format<'a> = FormatRefWithRule<
|
||||||
|
'a,
|
||||||
|
AnyFunctionDefinition<'def>,
|
||||||
|
FormatAnyFunctionDef,
|
||||||
|
PyFormatContext<'ast>,
|
||||||
|
> where Self: 'a;
|
||||||
|
|
||||||
|
fn format(&self) -> Self::Format<'_> {
|
||||||
|
FormatRefWithRule::new(self, FormatAnyFunctionDef::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'def, 'ast> IntoFormat<PyFormatContext<'ast>> for AnyFunctionDefinition<'def> {
|
||||||
|
type Format = FormatOwnedWithRule<
|
||||||
|
AnyFunctionDefinition<'def>,
|
||||||
|
FormatAnyFunctionDef,
|
||||||
|
PyFormatContext<'ast>,
|
||||||
|
>;
|
||||||
|
|
||||||
|
fn into_format(self) -> Self::Format {
|
||||||
|
FormatOwnedWithRule::new(self, FormatAnyFunctionDef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ mod tests {
|
||||||
use crate::comments::Comments;
|
use crate::comments::Comments;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::statement::suite::SuiteLevel;
|
use crate::statement::suite::SuiteLevel;
|
||||||
use ruff_formatter::{format, SimpleFormatOptions};
|
use ruff_formatter::{format, IndentStyle, SimpleFormatOptions};
|
||||||
use rustpython_parser::ast::Suite;
|
use rustpython_parser::ast::Suite;
|
||||||
use rustpython_parser::Parse;
|
use rustpython_parser::Parse;
|
||||||
|
|
||||||
|
@ -216,8 +216,14 @@ def trailing_func():
|
||||||
|
|
||||||
let statements = Suite::parse(source, "test.py").unwrap();
|
let statements = Suite::parse(source, "test.py").unwrap();
|
||||||
|
|
||||||
let context =
|
let context = PyFormatContext::new(
|
||||||
PyFormatContext::new(SimpleFormatOptions::default(), source, Comments::default());
|
SimpleFormatOptions {
|
||||||
|
indent_style: IndentStyle::Space(4),
|
||||||
|
..SimpleFormatOptions::default()
|
||||||
|
},
|
||||||
|
source,
|
||||||
|
Comments::default(),
|
||||||
|
);
|
||||||
|
|
||||||
let test_formatter =
|
let test_formatter =
|
||||||
format_with(|f: &mut PyFormatter| statements.format().with_options(level).fmt(f));
|
format_with(|f: &mut PyFormatter| statements.format().with_options(level).fmt(f));
|
||||||
|
@ -252,10 +258,13 @@ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
trailing_statement = 1
|
trailing_statement = 1
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef"#
|
def trailing_func():
|
||||||
|
pass
|
||||||
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,9 +287,12 @@ NOT_YET_IMPLEMENTED_StmtClassDef
|
||||||
|
|
||||||
trailing_statement = 1
|
trailing_statement = 1
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
def func():
|
||||||
|
pass
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtFunctionDef"#
|
def trailing_func():
|
||||||
|
pass
|
||||||
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue