mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Replace verbatim text with NOT_YET_IMPLEMENTED
(#4904)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR replaces the `verbatim_text` builder with a `not_yet_implemented` builder that emits `NOT_YET_IMPLEMENTED_<NodeKind>` for not yet implemented nodes. The motivation for this change is that partially formatting compound statements can result in incorrectly indented code, which is a syntax error: ```python def func_no_args(): a; b; c if True: raise RuntimeError if False: ... for i in range(10): print(i) continue ``` Get's reformatted to ```python def func_no_args(): a; b; c if True: raise RuntimeError if False: ... for i in range(10): print(i) continue ``` because our formatter does not yet support `for` statements and just inserts the text from the source. ## Downsides Using an identifier will not work in all situations. For example, an identifier is invalid in an `Arguments ` position. That's why I kept `verbatim_text` around and e.g. use it in the `Arguments` formatting logic where incorrect indentations are impossible (to my knowledge). Meaning, `verbatim_text` we can opt in to `verbatim_text` when we want to iterate quickly on nodes that we don't want to provide a full implementation yet and using an identifier would be invalid. ## Upsides Running this on main discovered stability issues with the newline handling that were previously "hidden" because of the verbatim formatting. I guess that's an upside :) ## Test Plan None?
This commit is contained in:
parent
2f125f4019
commit
bcf745c5ba
134 changed files with 5308 additions and 4385 deletions
|
@ -191,16 +191,16 @@ no_leading_newline = 30
|
|||
|
||||
assert_eq!(
|
||||
&printed,
|
||||
r#"a = 10
|
||||
r#"NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
three_leading_newlines = 80
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
two_leading_newlines = 20
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
one_leading_newline = 10
|
||||
no_leading_newline = 30"#
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign"#
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -211,14 +211,14 @@ no_leading_newline = 30"#
|
|||
|
||||
assert_eq!(
|
||||
&printed,
|
||||
r#"a = 10
|
||||
r#"NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
three_leading_newlines = 80
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
two_leading_newlines = 20
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
one_leading_newline = 10
|
||||
no_leading_newline = 30"#
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign"#
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -229,11 +229,11 @@ no_leading_newline = 30"#
|
|||
|
||||
assert_eq!(
|
||||
&printed,
|
||||
r#"a = 10
|
||||
three_leading_newlines = 80
|
||||
two_leading_newlines = 20
|
||||
one_leading_newline = 10
|
||||
no_leading_newline = 30"#
|
||||
r#"NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprAttribute;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprAttribute;
|
|||
|
||||
impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
|
||||
fn fmt_fields(&self, item: &ExprAttribute, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprAwait;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprAwait;
|
|||
|
||||
impl FormatNodeRule<ExprAwait> for FormatExprAwait {
|
||||
fn fmt_fields(&self, item: &ExprAwait, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprBoolOp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprBoolOp;
|
|||
|
||||
impl FormatNodeRule<ExprBoolOp> for FormatExprBoolOp {
|
||||
fn fmt_fields(&self, item: &ExprBoolOp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprCall;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprCall;
|
|||
|
||||
impl FormatNodeRule<ExprCall> for FormatExprCall {
|
||||
fn fmt_fields(&self, item: &ExprCall, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprCompare;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprCompare;
|
|||
|
||||
impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
||||
fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprConstant;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprConstant;
|
|||
|
||||
impl FormatNodeRule<ExprConstant> for FormatExprConstant {
|
||||
fn fmt_fields(&self, item: &ExprConstant, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprDict;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprDict;
|
|||
|
||||
impl FormatNodeRule<ExprDict> for FormatExprDict {
|
||||
fn fmt_fields(&self, item: &ExprDict, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprDictComp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprDictComp;
|
|||
|
||||
impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
||||
fn fmt_fields(&self, item: &ExprDictComp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprFormattedValue;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprFormattedValue;
|
|||
|
||||
impl FormatNodeRule<ExprFormattedValue> for FormatExprFormattedValue {
|
||||
fn fmt_fields(&self, item: &ExprFormattedValue, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprGeneratorExp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprGeneratorExp;
|
|||
|
||||
impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
|
||||
fn fmt_fields(&self, item: &ExprGeneratorExp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprIfExp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprIfExp;
|
|||
|
||||
impl FormatNodeRule<ExprIfExp> for FormatExprIfExp {
|
||||
fn fmt_fields(&self, item: &ExprIfExp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprJoinedStr;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprJoinedStr;
|
|||
|
||||
impl FormatNodeRule<ExprJoinedStr> for FormatExprJoinedStr {
|
||||
fn fmt_fields(&self, item: &ExprJoinedStr, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprLambda;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprLambda;
|
|||
|
||||
impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||
fn fmt_fields(&self, item: &ExprLambda, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprListComp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprListComp;
|
|||
|
||||
impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
||||
fn fmt_fields(&self, item: &ExprListComp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprNamedExpr;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprNamedExpr;
|
|||
|
||||
impl FormatNodeRule<ExprNamedExpr> for FormatExprNamedExpr {
|
||||
fn fmt_fields(&self, item: &ExprNamedExpr, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprSet;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprSet;
|
|||
|
||||
impl FormatNodeRule<ExprSet> for FormatExprSet {
|
||||
fn fmt_fields(&self, item: &ExprSet, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprSetComp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprSetComp;
|
|||
|
||||
impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
||||
fn fmt_fields(&self, item: &ExprSetComp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprSlice;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprSlice;
|
|||
|
||||
impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
||||
fn fmt_fields(&self, item: &ExprSlice, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprStarred;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprStarred;
|
|||
|
||||
impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
||||
fn fmt_fields(&self, item: &ExprStarred, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprSubscript;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprSubscript;
|
|||
|
||||
impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
||||
fn fmt_fields(&self, item: &ExprSubscript, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprTuple;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprTuple;
|
|||
|
||||
impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
||||
fn fmt_fields(&self, item: &ExprTuple, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprUnaryOp;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprUnaryOp;
|
|||
|
||||
impl FormatNodeRule<ExprUnaryOp> for FormatExprUnaryOp {
|
||||
fn fmt_fields(&self, item: &ExprUnaryOp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprYield;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprYield;
|
|||
|
||||
impl FormatNodeRule<ExprYield> for FormatExprYield {
|
||||
fn fmt_fields(&self, item: &ExprYield, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::expression::parentheses::{
|
||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||
};
|
||||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExprYieldFrom;
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub struct FormatExprYieldFrom;
|
|||
|
||||
impl FormatNodeRule<ExprYieldFrom> for FormatExprYieldFrom {
|
||||
fn fmt_fields(&self, item: &ExprYieldFrom, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,15 @@
|
|||
use anyhow::{anyhow, Context, Result};
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::Mod;
|
||||
use ruff_formatter::prelude::*;
|
||||
use ruff_formatter::{format, write};
|
||||
use ruff_formatter::{Formatted, IndentStyle, Printed, SimpleFormatOptions, SourceCode};
|
||||
use ruff_python_ast::node::{AnyNodeRef, AstNode, NodeKind};
|
||||
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator};
|
||||
use ruff_text_size::{TextLen, TextRange};
|
||||
use rustpython_parser::ast::{Mod, Ranged};
|
||||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use ruff_formatter::format_element::tag::VerbatimKind;
|
||||
use ruff_formatter::formatter::Formatter;
|
||||
use ruff_formatter::prelude::{
|
||||
dynamic_text, source_position, source_text_slice, ContainsNewlines, Tag,
|
||||
};
|
||||
use ruff_formatter::{
|
||||
format, normalize_newlines, write, Buffer, Format, FormatElement, FormatResult, Formatted,
|
||||
IndentStyle, Printed, SimpleFormatOptions, SourceCode,
|
||||
};
|
||||
use ruff_python_ast::node::AstNode;
|
||||
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder, Locator};
|
||||
|
||||
use crate::comments::{
|
||||
dangling_node_comments, leading_node_comments, trailing_node_comments, Comments,
|
||||
};
|
||||
|
@ -142,16 +135,49 @@ pub fn format_node<'a>(
|
|||
)
|
||||
}
|
||||
|
||||
pub(crate) struct NotYetImplemented(NodeKind);
|
||||
|
||||
/// Formats a placeholder for nodes that have not yet been implemented
|
||||
pub(crate) fn not_yet_implemented<'a, T>(node: T) -> NotYetImplemented
|
||||
where
|
||||
T: Into<AnyNodeRef<'a>>,
|
||||
{
|
||||
NotYetImplemented(node.into().kind())
|
||||
}
|
||||
|
||||
impl Format<PyFormatContext<'_>> for NotYetImplemented {
|
||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let text = std::format!("NOT_YET_IMPLEMENTED_{:?}", self.0);
|
||||
|
||||
f.write_element(FormatElement::Tag(Tag::StartVerbatim(
|
||||
tag::VerbatimKind::Verbatim {
|
||||
length: text.text_len(),
|
||||
},
|
||||
)))?;
|
||||
|
||||
f.write_element(FormatElement::DynamicText {
|
||||
text: Box::from(text),
|
||||
})?;
|
||||
|
||||
f.write_element(FormatElement::Tag(Tag::EndVerbatim))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct VerbatimText(TextRange);
|
||||
|
||||
pub(crate) const fn verbatim_text(range: TextRange) -> VerbatimText {
|
||||
VerbatimText(range)
|
||||
#[allow(unused)]
|
||||
pub(crate) fn verbatim_text<T>(item: &T) -> VerbatimText
|
||||
where
|
||||
T: Ranged,
|
||||
{
|
||||
VerbatimText(item.range())
|
||||
}
|
||||
|
||||
impl Format<PyFormatContext<'_>> for VerbatimText {
|
||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
f.write_element(FormatElement::Tag(Tag::StartVerbatim(
|
||||
VerbatimKind::Verbatim {
|
||||
tag::VerbatimKind::Verbatim {
|
||||
length: self.0.len(),
|
||||
},
|
||||
)))?;
|
||||
|
@ -203,8 +229,7 @@ if True:
|
|||
# trailing
|
||||
"#;
|
||||
let expected = r#"# preceding
|
||||
if True:
|
||||
print( "hi" )
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
# trailing
|
||||
"#;
|
||||
let actual = format_module(input)?.as_code().to_string();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ModExpression;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatModExpression;
|
|||
|
||||
impl FormatNodeRule<ModExpression> for FormatModExpression {
|
||||
fn fmt_fields(&self, item: &ModExpression, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ModFunctionType;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatModFunctionType;
|
|||
|
||||
impl FormatNodeRule<ModFunctionType> for FormatModFunctionType {
|
||||
fn fmt_fields(&self, item: &ModFunctionType, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ModInteractive;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatModInteractive;
|
|||
|
||||
impl FormatNodeRule<ModInteractive> for FormatModInteractive {
|
||||
fn fmt_fields(&self, item: &ModInteractive, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Alias;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatAlias;
|
|||
|
||||
impl FormatNodeRule<Alias> for FormatAlias {
|
||||
fn fmt_fields(&self, item: &Alias, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Arg;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatArg;
|
|||
|
||||
impl FormatNodeRule<Arg> for FormatArg {
|
||||
fn fmt_fields(&self, item: &Arg, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Arguments;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatArguments;
|
|||
|
||||
impl FormatNodeRule<Arguments> for FormatArguments {
|
||||
fn fmt_fields(&self, item: &Arguments, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Comprehension;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatComprehension;
|
|||
|
||||
impl FormatNodeRule<Comprehension> for FormatComprehension {
|
||||
fn fmt_fields(&self, item: &Comprehension, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::ExcepthandlerExceptHandler;
|
||||
|
||||
|
@ -11,6 +11,6 @@ impl FormatNodeRule<ExcepthandlerExceptHandler> for FormatExcepthandlerExceptHan
|
|||
item: &ExcepthandlerExceptHandler,
|
||||
f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Keyword;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatKeyword;
|
|||
|
||||
impl FormatNodeRule<Keyword> for FormatKeyword {
|
||||
fn fmt_fields(&self, item: &Keyword, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::MatchCase;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatMatchCase;
|
|||
|
||||
impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
||||
fn fmt_fields(&self, item: &MatchCase, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::TypeIgnoreTypeIgnore;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatTypeIgnoreTypeIgnore;
|
|||
|
||||
impl FormatNodeRule<TypeIgnoreTypeIgnore> for FormatTypeIgnoreTypeIgnore {
|
||||
fn fmt_fields(&self, item: &TypeIgnoreTypeIgnore, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::Withitem;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatWithitem;
|
|||
|
||||
impl FormatNodeRule<Withitem> for FormatWithitem {
|
||||
fn fmt_fields(&self, item: &Withitem, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchAs;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchAs;
|
|||
|
||||
impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
||||
fn fmt_fields(&self, item: &PatternMatchAs, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchClass;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchClass;
|
|||
|
||||
impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass {
|
||||
fn fmt_fields(&self, item: &PatternMatchClass, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchMapping;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchMapping;
|
|||
|
||||
impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
|
||||
fn fmt_fields(&self, item: &PatternMatchMapping, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchOr;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchOr;
|
|||
|
||||
impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
|
||||
fn fmt_fields(&self, item: &PatternMatchOr, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchSequence;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchSequence;
|
|||
|
||||
impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
|
||||
fn fmt_fields(&self, item: &PatternMatchSequence, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchSingleton;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchSingleton;
|
|||
|
||||
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
||||
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchStar;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchStar;
|
|||
|
||||
impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
|
||||
fn fmt_fields(&self, item: &PatternMatchStar, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{verbatim_text, FormatNodeRule, PyFormatter};
|
||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
use rustpython_parser::ast::PatternMatchValue;
|
||||
|
||||
|
@ -7,6 +7,6 @@ pub struct FormatPatternMatchValue;
|
|||
|
||||
impl FormatNodeRule<PatternMatchValue> for FormatPatternMatchValue {
|
||||
fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [verbatim_text(item.range)])
|
||||
write!(f, [not_yet_implemented(item)])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,9 @@ y = 100(no)
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,21 +1,21 @@
|
||||
@@ -1,22 +1,21 @@
|
||||
-x = (123456789).bit_count()
|
||||
+x = 123456789 .bit_count()
|
||||
x = (123456).__abs__()
|
||||
-x = (123456).__abs__()
|
||||
-x = (0.1).is_integer()
|
||||
-x = (1.0).imag
|
||||
-x = (1e1).imag
|
||||
|
@ -53,53 +52,57 @@ y = 100(no)
|
|||
-x = 0o777.real
|
||||
-x = (0.000000006).hex()
|
||||
-x = -100.0000j
|
||||
+x = .1.is_integer()
|
||||
+x = 1. .imag
|
||||
+x = 1E+1.imag
|
||||
+x = 1E-1.real
|
||||
+x = 123456789.123456789.hex()
|
||||
+x = 123456789.123456789E123456789 .real
|
||||
+x = 123456789E123456789 .conjugate()
|
||||
+x = 123456789J.real
|
||||
+x = 123456789.123456789J.__add__(0b1011.bit_length())
|
||||
+x = 0XB1ACC.conjugate()
|
||||
+x = 0B1011 .conjugate()
|
||||
+x = 0O777 .real
|
||||
+x = 0.000000006 .hex()
|
||||
+x = -100.0000J
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
-if (10).real:
|
||||
+if 10 .real:
|
||||
...
|
||||
- ...
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
y = 100[no]
|
||||
-y = 100[no]
|
||||
-y = 100(no)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
x = 123456789 .bit_count()
|
||||
x = (123456).__abs__()
|
||||
x = .1.is_integer()
|
||||
x = 1. .imag
|
||||
x = 1E+1.imag
|
||||
x = 1E-1.real
|
||||
x = 123456789.123456789.hex()
|
||||
x = 123456789.123456789E123456789 .real
|
||||
x = 123456789E123456789 .conjugate()
|
||||
x = 123456789J.real
|
||||
x = 123456789.123456789J.__add__(0b1011.bit_length())
|
||||
x = 0XB1ACC.conjugate()
|
||||
x = 0B1011 .conjugate()
|
||||
x = 0O777 .real
|
||||
x = 0.000000006 .hex()
|
||||
x = -100.0000J
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
if 10 .real:
|
||||
...
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
y = 100[no]
|
||||
y = 100(no)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
\
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print("hello, world")
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1 +1 @@
|
||||
-print("hello, world")
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
print("hello, world")
|
||||
```
|
||||
|
||||
|
|
@ -19,27 +19,22 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,6 @@
|
||||
@@ -1,4 +1,3 @@
|
||||
-for ((x in {}) or {})["a"] in x:
|
||||
+for ((x in {}) or {})['a'] in x:
|
||||
pass
|
||||
- pass
|
||||
-pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
|
||||
-lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
|
||||
+pem_spam = lambda l, spam = {
|
||||
+ "x": 3
|
||||
+}: not spam.get(l.strip())
|
||||
+lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_ExprLambda
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
for ((x in {}) or {})['a'] in x:
|
||||
pass
|
||||
pem_spam = lambda l, spam = {
|
||||
"x": 3
|
||||
}: not spam.get(l.strip())
|
||||
lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_ExprLambda
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -36,77 +36,64 @@ class NormalClass (
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,16 +1,16 @@
|
||||
@@ -1,30 +1,16 @@
|
||||
-class SimpleClassWithBlankParentheses:
|
||||
+class SimpleClassWithBlankParentheses():
|
||||
pass
|
||||
|
||||
- pass
|
||||
-
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassWithSpaceParentheses:
|
||||
+class ClassWithSpaceParentheses ( ):
|
||||
first_test_data = 90
|
||||
second_test_data = 100
|
||||
-
|
||||
def test_func(self):
|
||||
return None
|
||||
- first_test_data = 90
|
||||
- second_test_data = 100
|
||||
|
||||
- def test_func(self):
|
||||
- return None
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithEmptyFunc(object):
|
||||
+
|
||||
def func_with_blank_parentheses():
|
||||
return 5
|
||||
|
||||
@@ -20,11 +20,12 @@
|
||||
-class ClassWithEmptyFunc(object):
|
||||
- def func_with_blank_parentheses():
|
||||
- return 5
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def class_under_the_func_with_blank_parentheses():
|
||||
-def public_func_with_blank_parentheses():
|
||||
- return None
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def class_under_the_func_with_blank_parentheses():
|
||||
- class InsideFunc:
|
||||
+ class InsideFunc():
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-class NormalClass:
|
||||
+class NormalClass (
|
||||
+):
|
||||
def func_for_testing(self, first, second):
|
||||
sum = first + second
|
||||
return sum
|
||||
- def func_for_testing(self, first, second):
|
||||
- sum = first + second
|
||||
- return sum
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class SimpleClassWithBlankParentheses():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithSpaceParentheses ( ):
|
||||
first_test_data = 90
|
||||
second_test_data = 100
|
||||
def test_func(self):
|
||||
return None
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithEmptyFunc(object):
|
||||
|
||||
def func_with_blank_parentheses():
|
||||
return 5
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def public_func_with_blank_parentheses():
|
||||
return None
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def class_under_the_func_with_blank_parentheses():
|
||||
class InsideFunc():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
class NormalClass (
|
||||
):
|
||||
def func_for_testing(self, first, second):
|
||||
sum = first + second
|
||||
return sum
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -113,290 +113,259 @@ class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -17,23 +17,19 @@
|
||||
|
||||
class ClassWithTheDocstringAndInit:
|
||||
"""Just a docstring."""
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -1,165 +1,61 @@
|
||||
-class ClassSimplest:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVars:
|
||||
cls_var = 100
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
-class ClassWithSingleField:
|
||||
- a = 1
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@@ -46,7 +42,6 @@
|
||||
|
||||
class ClassWithDecoInitAndVars:
|
||||
cls_var = 100
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -54,9 +49,7 @@
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -70,21 +63,18 @@
|
||||
class ClassSimplestWithInnerWithDocstring:
|
||||
class Inner:
|
||||
"""Just a docstring."""
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
-class ClassWithJustTheDocstring:
|
||||
- """Just a docstring."""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithSingleFieldWithInner:
|
||||
a = 1
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-class ClassWithInit:
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithJustTheDocstringWithInner:
|
||||
"""Just a docstring."""
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-class ClassWithTheDocstringAndInit:
|
||||
- """Just a docstring."""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
@@ -92,29 +82,23 @@
|
||||
class ClassWithInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
- def __init__(self):
|
||||
- pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassWithInitAndVars:
|
||||
- cls_var = 100
|
||||
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
-class ClassWithInitAndVarsAndDocstring:
|
||||
- """Test class"""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- cls_var = 100
|
||||
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
def __init__(self):
|
||||
pass
|
||||
-class ClassWithDecoInit:
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
@@ -122,7 +106,6 @@
|
||||
class ClassWithDecoInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -130,10 +113,8 @@
|
||||
|
||||
class ClassWithDecoInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -141,12 +122,9 @@
|
||||
-class ClassWithDecoInitAndVars:
|
||||
- cls_var = 100
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
-
|
||||
cls_var = 100
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -154,12 +132,9 @@
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
"""Test class"""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassWithDecoInitAndVarsAndDocstring:
|
||||
- """Test class"""
|
||||
|
||||
- cls_var = 100
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassSimplestWithInner:
|
||||
- class Inner:
|
||||
- pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassSimplestWithInnerWithDocstring:
|
||||
- class Inner:
|
||||
- """Just a docstring."""
|
||||
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-class ClassWithSingleFieldWithInner:
|
||||
- a = 1
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- class Inner:
|
||||
- pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
-class ClassWithJustTheDocstringWithInner:
|
||||
- """Just a docstring."""
|
||||
|
||||
- class Inner:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-class ClassWithInitWithInner:
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
class Inner:
|
||||
pass
|
||||
- def __init__(self):
|
||||
- pass
|
||||
-
|
||||
cls_var = 100
|
||||
-
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
-class ClassWithInitAndVarsWithInner:
|
||||
- cls_var = 100
|
||||
-
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- def __init__(self):
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
- """Test class"""
|
||||
-
|
||||
- cls_var = 100
|
||||
-
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- def __init__(self):
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-class ClassWithDecoInitWithInner:
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-class ClassWithDecoInitAndVarsWithInner:
|
||||
- cls_var = 100
|
||||
-
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
- """Test class"""
|
||||
-
|
||||
- cls_var = 100
|
||||
-
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
- """Test class"""
|
||||
-
|
||||
- class Inner:
|
||||
- pass
|
||||
-
|
||||
- cls_var = 100
|
||||
-
|
||||
- @deco
|
||||
- def __init__(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class ClassSimplest:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithSingleField:
|
||||
a = 1
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithJustTheDocstring:
|
||||
"""Just a docstring."""
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInit:
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithTheDocstringAndInit:
|
||||
"""Just a docstring."""
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVars:
|
||||
cls_var = 100
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInit:
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVars:
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstring:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassSimplestWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassSimplestWithInnerWithDocstring:
|
||||
class Inner:
|
||||
"""Just a docstring."""
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithSingleFieldWithInner:
|
||||
a = 1
|
||||
class Inner:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithJustTheDocstringWithInner:
|
||||
"""Just a docstring."""
|
||||
class Inner:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitWithInner:
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsWithInner:
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner:
|
||||
"""Test class"""
|
||||
cls_var = 100
|
||||
class Inner:
|
||||
pass
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
|
||||
"""Test class"""
|
||||
class Inner:
|
||||
pass
|
||||
cls_var = 100
|
||||
@deco
|
||||
def __init__(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -84,9 +84,31 @@ if True:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -18,44 +18,26 @@
|
||||
xyzzy as magic,
|
||||
)
|
||||
@@ -1,99 +1,48 @@
|
||||
-import core, time, a
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-from . import A, B, C
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# keeps existing trailing comma
|
||||
-from foo import (
|
||||
- bar,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# also keeps existing structure
|
||||
-from foo import (
|
||||
- baz,
|
||||
- qux,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# `as` works as well
|
||||
-from foo import (
|
||||
- xyzzy as magic,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-a = {
|
||||
- 1,
|
||||
|
@ -94,15 +116,11 @@ if True:
|
|||
- 3,
|
||||
-}
|
||||
-b = {1, 2, 3}
|
||||
+a = {1,2,3,}
|
||||
+b = {
|
||||
+1,2,
|
||||
+ 3}
|
||||
c = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
}
|
||||
-c = {
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-}
|
||||
-x = (1,)
|
||||
-y = (narf(),)
|
||||
-nested = {
|
||||
|
@ -116,20 +134,27 @@ if True:
|
|||
- "cccccccccccccccccccccccccccccccccccccccc",
|
||||
- (1, 2, 3),
|
||||
- "dddddddddddddddddddddddddddddddddddddddd",
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_ExprDict
|
||||
+NOT_YET_IMPLEMENTED_ExprDict
|
||||
+[
|
||||
+ NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
+ NOT_YET_IMPLEMENTED_ExprConstant
|
||||
+ % NOT_YET_IMPLEMENTED_ExprTuple,
|
||||
]
|
||||
-{
|
||||
- "oneple": (1,),
|
||||
-}
|
||||
+x = 1,
|
||||
+y = narf(),
|
||||
+nested = {(1,2,3),(4,5,6),}
|
||||
+nested_no_trailing_comma = {(1,2,3),(4,5,6)}
|
||||
+nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"]
|
||||
+{"oneple": (1,),}
|
||||
{"oneple": (1,)}
|
||||
-{"oneple": (1,)}
|
||||
-["ls", "lsoneple/%s" % (foo,)]
|
||||
+['ls', 'lsoneple/%s' % (foo,)]
|
||||
x = {"oneple": (1,)}
|
||||
-x = {"oneple": (1,)}
|
||||
-y = {
|
||||
- "oneple": (1,),
|
||||
-}
|
||||
|
@ -137,130 +162,112 @@ if True:
|
|||
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||
- % bar
|
||||
-)
|
||||
+y = {"oneple": (1,),}
|
||||
+assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
@@ -63,13 +45,9 @@
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
-for x in (1,):
|
||||
- pass
|
||||
-for (x,) in (1,), (2,), (3,):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
-[
|
||||
[
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-]
|
||||
+[1, 2, 3]
|
||||
+ NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
+ NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
+ NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
]
|
||||
|
||||
-division_result_tuple = (6 / 2,)
|
||||
+division_result_tuple = (6/2,)
|
||||
print("foo %r", (foo.bar,))
|
||||
-print("foo %r", (foo.bar,))
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
if True:
|
||||
@@ -79,21 +57,15 @@
|
||||
)
|
||||
|
||||
if True:
|
||||
- ec2client.get_waiter("instance_stopped").wait(
|
||||
+ ec2client.get_waiter('instance_stopped').wait(
|
||||
InstanceIds=[instance.id],
|
||||
WaiterConfig={
|
||||
- "Delay": 5,
|
||||
- },
|
||||
-if True:
|
||||
- IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||
- Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||
- | {pylons.controllers.WSGIController}
|
||||
- )
|
||||
+ 'Delay': 5,
|
||||
+ })
|
||||
ec2client.get_waiter("instance_stopped").wait(
|
||||
InstanceIds=[instance.id],
|
||||
- WaiterConfig={
|
||||
- "Delay": 5,
|
||||
- },
|
||||
+ WaiterConfig={"Delay": 5,},
|
||||
)
|
||||
ec2client.get_waiter("instance_stopped").wait(
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
-if True:
|
||||
- ec2client.get_waiter("instance_stopped").wait(
|
||||
- InstanceIds=[instance.id],
|
||||
- WaiterConfig={
|
||||
- "Delay": 5,
|
||||
- },
|
||||
+ InstanceIds=[instance.id], WaiterConfig={"Delay": 5,},
|
||||
)
|
||||
- )
|
||||
- ec2client.get_waiter("instance_stopped").wait(
|
||||
- InstanceIds=[instance.id],
|
||||
- WaiterConfig={
|
||||
- "Delay": 5,
|
||||
- },
|
||||
- )
|
||||
- ec2client.get_waiter("instance_stopped").wait(
|
||||
- InstanceIds=[instance.id],
|
||||
- WaiterConfig={
|
||||
- "Delay": 5,
|
||||
- },
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
import core, time, a
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from . import A, B, C
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# keeps existing trailing comma
|
||||
from foo import (
|
||||
bar,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# also keeps existing structure
|
||||
from foo import (
|
||||
baz,
|
||||
qux,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# `as` works as well
|
||||
from foo import (
|
||||
xyzzy as magic,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
a = {1,2,3,}
|
||||
b = {
|
||||
1,2,
|
||||
3}
|
||||
c = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
}
|
||||
x = 1,
|
||||
y = narf(),
|
||||
nested = {(1,2,3),(4,5,6),}
|
||||
nested_no_trailing_comma = {(1,2,3),(4,5,6)}
|
||||
nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"]
|
||||
{"oneple": (1,),}
|
||||
{"oneple": (1,)}
|
||||
['ls', 'lsoneple/%s' % (foo,)]
|
||||
x = {"oneple": (1,)}
|
||||
y = {"oneple": (1,),}
|
||||
assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_ExprDict
|
||||
NOT_YET_IMPLEMENTED_ExprDict
|
||||
[
|
||||
NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
NOT_YET_IMPLEMENTED_ExprConstant
|
||||
% NOT_YET_IMPLEMENTED_ExprTuple,
|
||||
]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
# looping over a 1-tuple should also not get wrapped
|
||||
for x in (1,):
|
||||
pass
|
||||
for (x,) in (1,), (2,), (3,):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
[1, 2, 3]
|
||||
[
|
||||
NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
NOT_YET_IMPLEMENTED_ExprConstant,
|
||||
]
|
||||
|
||||
division_result_tuple = (6/2,)
|
||||
print("foo %r", (foo.bar,))
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
if True:
|
||||
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||
| {pylons.controllers.WSGIController}
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
if True:
|
||||
ec2client.get_waiter('instance_stopped').wait(
|
||||
InstanceIds=[instance.id],
|
||||
WaiterConfig={
|
||||
'Delay': 5,
|
||||
})
|
||||
ec2client.get_waiter("instance_stopped").wait(
|
||||
InstanceIds=[instance.id],
|
||||
WaiterConfig={"Delay": 5,},
|
||||
)
|
||||
ec2client.get_waiter("instance_stopped").wait(
|
||||
InstanceIds=[instance.id], WaiterConfig={"Delay": 5,},
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -22,32 +22,24 @@ def bobtwo(): \
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,9 @@
|
||||
@@ -1,6 +1,4 @@
|
||||
-def bob(): # pylint: disable=W9016
|
||||
+def bob(): \
|
||||
+ # pylint: disable=W9016
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def bobtwo(): # some comment here
|
||||
+def bobtwo(): \
|
||||
+ \
|
||||
+ # some comment here
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def bob(): \
|
||||
# pylint: disable=W9016
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def bobtwo(): \
|
||||
\
|
||||
# some comment here
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -178,36 +178,28 @@ instruction()#comment with bad spacing
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,39 +1,40 @@
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
@@ -1,165 +1,23 @@
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
+ MyLovelyCompanyTeamProjectComponent # NOT DRY
|
||||
)
|
||||
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 as component, # DRY
|
||||
+ MyLovelyCompanyTeamProjectComponent as component # DRY
|
||||
)
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
__all__ = [
|
||||
# Super-special typing primitives.
|
||||
-__all__ = [
|
||||
- # Super-special typing primitives.
|
||||
- "Any",
|
||||
- "Callable",
|
||||
- "ClassVar",
|
||||
+ 'Any',
|
||||
+ 'Callable',
|
||||
+ 'ClassVar',
|
||||
+
|
||||
# ABCs (from collections.abc).
|
||||
- # ABCs (from collections.abc).
|
||||
- "AbstractSet", # collections.abc.Set.
|
||||
- "ByteString",
|
||||
- "Container",
|
||||
+ 'AbstractSet', # collections.abc.Set.
|
||||
+ 'ByteString',
|
||||
+ 'Container',
|
||||
+
|
||||
# Concrete collection types.
|
||||
- # Concrete collection types.
|
||||
- "Counter",
|
||||
- "Deque",
|
||||
- "Dict",
|
||||
|
@ -217,59 +209,56 @@ instruction()#comment with bad spacing
|
|||
- "FrozenSet",
|
||||
- "NamedTuple", # Not really a type.
|
||||
- "Generator",
|
||||
+ 'Counter',
|
||||
+ 'Deque',
|
||||
+ 'Dict',
|
||||
+ 'DefaultDict',
|
||||
+ 'List',
|
||||
+ 'Set',
|
||||
+ 'FrozenSet',
|
||||
+ 'NamedTuple', # Not really a type.
|
||||
+ 'Generator',
|
||||
]
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
not_shareables = [
|
||||
# singletons
|
||||
True,
|
||||
False,
|
||||
-not_shareables = [
|
||||
- # singletons
|
||||
- True,
|
||||
- False,
|
||||
- NotImplemented,
|
||||
- ...,
|
||||
+ NotImplemented, ...,
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
@@ -48,20 +49,23 @@
|
||||
SubBytes(b"spam"),
|
||||
]
|
||||
- # builtin types and objects
|
||||
- type,
|
||||
- object,
|
||||
- object(),
|
||||
- Exception(),
|
||||
- 42,
|
||||
- 100.0,
|
||||
- "spam",
|
||||
- # user-defined types and objects
|
||||
- Cheese,
|
||||
- Cheese("Wensleydale"),
|
||||
- SubBytes(b"spam"),
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
-if "PYTHON" in os.environ:
|
||||
+if 'PYTHON' in os.environ:
|
||||
add_compiler(compiler_from_env())
|
||||
else:
|
||||
# for compiler in compilers.values():
|
||||
- add_compiler(compiler_from_env())
|
||||
-else:
|
||||
- # for compiler in compilers.values():
|
||||
- # add_compiler(compiler)
|
||||
+ # add_compiler(compiler)
|
||||
add_compiler(compilers[(7.0, 32)])
|
||||
- add_compiler(compilers[(7.0, 32)])
|
||||
- # add_compiler(compilers[(7.1, 64)])
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
# Comment before function.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
-def inline_comments_in_brackets_ruin_everything():
|
||||
- if typedargslist:
|
||||
- parameters.children = [children[0], body, children[-1]] # (1 # )1
|
||||
parameters.children = [
|
||||
+ children[0], # (1
|
||||
+ body,
|
||||
+ children[-1] # )1
|
||||
+ ]
|
||||
+ parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
@@ -73,49 +77,42 @@
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
- parameters.children = [
|
||||
- children[0],
|
||||
- body,
|
||||
- children[-1], # type: ignore
|
||||
- ]
|
||||
- else:
|
||||
- parameters.children = [
|
||||
- parameters.children[0], # (2 what if this was actually long
|
||||
- body,
|
||||
- parameters.children[-1], # )2
|
||||
- ]
|
||||
- parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
- if (
|
||||
- self._proc is not None
|
||||
- # has the child process finished?
|
||||
|
@ -278,92 +267,74 @@ instruction()#comment with bad spacing
|
|||
- # transport hasn't been notified yet?
|
||||
- and self._proc.poll() is None
|
||||
- ):
|
||||
+ if (self._proc is not None
|
||||
+ # has the child process finished?
|
||||
+ and self._returncode is None
|
||||
+ # the child process has finished, but the
|
||||
+ # transport hasn't been notified yet?
|
||||
+ and self._proc.poll() is None):
|
||||
pass
|
||||
# no newline before or after
|
||||
short = [
|
||||
- pass
|
||||
- # no newline before or after
|
||||
- short = [
|
||||
- # one
|
||||
- 1,
|
||||
- # two
|
||||
- 2,
|
||||
- ]
|
||||
+ # one
|
||||
+ 1,
|
||||
+ # two
|
||||
+ 2]
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
# no newline after
|
||||
- # no newline after
|
||||
- call(
|
||||
- arg1,
|
||||
- arg2,
|
||||
- """
|
||||
+ call(arg1, arg2, """
|
||||
short
|
||||
-short
|
||||
-""",
|
||||
- arg3=True,
|
||||
- )
|
||||
+""", arg3=True)
|
||||
|
||||
############################################################################
|
||||
|
||||
call2(
|
||||
- ############################################################################
|
||||
-
|
||||
- call2(
|
||||
- # short
|
||||
- arg1,
|
||||
- # but
|
||||
- arg2,
|
||||
- # multiline
|
||||
- """
|
||||
+ #short
|
||||
+ arg1,
|
||||
+ #but
|
||||
+ arg2,
|
||||
+ #multiline
|
||||
+ """
|
||||
short
|
||||
""",
|
||||
-short
|
||||
-""",
|
||||
- # yup
|
||||
- arg3=True,
|
||||
- )
|
||||
+ # yup
|
||||
+ arg3=True)
|
||||
lcomp = [
|
||||
- lcomp = [
|
||||
- element for element in collection if element is not None # yup # yup # right
|
||||
+ element # yup
|
||||
+ for element in collection # yup
|
||||
+ if element is not None # right
|
||||
]
|
||||
lcomp2 = [
|
||||
# hello
|
||||
@@ -127,7 +124,7 @@
|
||||
]
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
- ]
|
||||
- lcomp2 = [
|
||||
- # hello
|
||||
- element
|
||||
- # yup
|
||||
- for element in collection
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
- lcomp3 = [
|
||||
- # This one is actually too long to fit in a single line.
|
||||
- element.split("\n", 1)[0]
|
||||
+ element.split('\n', 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
@@ -140,25 +137,23 @@
|
||||
# and round and round we go
|
||||
# and round and round we go
|
||||
- # yup
|
||||
- for element in collection.select_elements()
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
- while True:
|
||||
- if False:
|
||||
- continue
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # type: Final
|
||||
|
||||
- # and round and round we go
|
||||
- # and round and round we go
|
||||
|
||||
- # let's return
|
||||
+ # let's return
|
||||
return Node(
|
||||
syms.simple_stmt,
|
||||
- return Node(
|
||||
- syms.simple_stmt,
|
||||
- [Node(statement, result), Leaf(token.NEWLINE, "\n")], # FIXME: \r\n?
|
||||
+ [
|
||||
+ Node(statement, result),
|
||||
+ Leaf(token.NEWLINE, '\n') # FIXME: \r\n?
|
||||
+ ],
|
||||
)
|
||||
|
||||
|
||||
- )
|
||||
-
|
||||
-
|
||||
-CONFIG_FILES = (
|
||||
- [
|
||||
- CONFIG_FILE,
|
||||
|
@ -371,179 +342,50 @@ instruction()#comment with bad spacing
|
|||
- + SHARED_CONFIG_FILES
|
||||
- + USER_CONFIG_FILES
|
||||
-) # type: Final
|
||||
+CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
-
|
||||
-
|
||||
-class Test:
|
||||
- def _init_host(self, parsed) -> None:
|
||||
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
|
||||
+ if (parsed.hostname is None or # type: ignore
|
||||
+ not parsed.hostname.strip()):
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
#######################
|
||||
@@ -167,7 +25,7 @@
|
||||
#######################
|
||||
|
||||
|
||||
-instruction() # comment with bad spacing
|
||||
+NOT_YET_IMPLEMENTED_ExprCall # comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component # DRY
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
# Please keep __all__ alphabetized within each category.
|
||||
|
||||
__all__ = [
|
||||
# Super-special typing primitives.
|
||||
'Any',
|
||||
'Callable',
|
||||
'ClassVar',
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# ABCs (from collections.abc).
|
||||
'AbstractSet', # collections.abc.Set.
|
||||
'ByteString',
|
||||
'Container',
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Concrete collection types.
|
||||
'Counter',
|
||||
'Deque',
|
||||
'Dict',
|
||||
'DefaultDict',
|
||||
'List',
|
||||
'Set',
|
||||
'FrozenSet',
|
||||
'NamedTuple', # Not really a type.
|
||||
'Generator',
|
||||
]
|
||||
|
||||
not_shareables = [
|
||||
# singletons
|
||||
True,
|
||||
False,
|
||||
NotImplemented, ...,
|
||||
# builtin types and objects
|
||||
type,
|
||||
object,
|
||||
object(),
|
||||
Exception(),
|
||||
42,
|
||||
100.0,
|
||||
"spam",
|
||||
# user-defined types and objects
|
||||
Cheese,
|
||||
Cheese("Wensleydale"),
|
||||
SubBytes(b"spam"),
|
||||
]
|
||||
|
||||
if 'PYTHON' in os.environ:
|
||||
add_compiler(compiler_from_env())
|
||||
else:
|
||||
# for compiler in compilers.values():
|
||||
# add_compiler(compiler)
|
||||
add_compiler(compilers[(7.0, 32)])
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
# Comment before function.
|
||||
def inline_comments_in_brackets_ruin_everything():
|
||||
if typedargslist:
|
||||
parameters.children = [
|
||||
children[0], # (1
|
||||
body,
|
||||
children[-1] # )1
|
||||
]
|
||||
parameters.children = [
|
||||
children[0],
|
||||
body,
|
||||
children[-1], # type: ignore
|
||||
]
|
||||
else:
|
||||
parameters.children = [
|
||||
parameters.children[0], # (2 what if this was actually long
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
parameters.children = [parameters.what_if_this_was_actually_long.children[0], body, parameters.children[-1]] # type: ignore
|
||||
if (self._proc is not None
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
and self._proc.poll() is None):
|
||||
pass
|
||||
# no newline before or after
|
||||
short = [
|
||||
# one
|
||||
1,
|
||||
# two
|
||||
2]
|
||||
|
||||
# no newline after
|
||||
call(arg1, arg2, """
|
||||
short
|
||||
""", arg3=True)
|
||||
|
||||
############################################################################
|
||||
|
||||
call2(
|
||||
#short
|
||||
arg1,
|
||||
#but
|
||||
arg2,
|
||||
#multiline
|
||||
"""
|
||||
short
|
||||
""",
|
||||
# yup
|
||||
arg3=True)
|
||||
lcomp = [
|
||||
element # yup
|
||||
for element in collection # yup
|
||||
if element is not None # right
|
||||
]
|
||||
lcomp2 = [
|
||||
# hello
|
||||
element
|
||||
# yup
|
||||
for element in collection
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split('\n', 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
while True:
|
||||
if False:
|
||||
continue
|
||||
|
||||
# and round and round we go
|
||||
# and round and round we go
|
||||
|
||||
# let's return
|
||||
return Node(
|
||||
syms.simple_stmt,
|
||||
[
|
||||
Node(statement, result),
|
||||
Leaf(token.NEWLINE, '\n') # FIXME: \r\n?
|
||||
],
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # type: Final
|
||||
|
||||
|
||||
class Test:
|
||||
def _init_host(self, parsed) -> None:
|
||||
if (parsed.hostname is None or # type: ignore
|
||||
not parsed.hostname.strip()):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
#######################
|
||||
|
@ -551,7 +393,7 @@ class Test:
|
|||
#######################
|
||||
|
||||
|
||||
instruction() # comment with bad spacing
|
||||
NOT_YET_IMPLEMENTED_ExprCall # comment with bad spacing
|
||||
|
||||
# END COMMENTS
|
||||
# MORE END COMMENTS
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split("\n", 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if isinstance(exc_value, MultiError):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
embedded.append(
|
||||
# This should be left alone (before)
|
||||
traceback.TracebackException.from_exception(
|
||||
exc,
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
_seen=set(_seen),
|
||||
)
|
||||
# This should be left alone (after)
|
||||
)
|
||||
|
||||
# everything is fine if the expression isn't nested
|
||||
traceback.TracebackException.from_exception(
|
||||
exc,
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
_seen=set(_seen),
|
||||
)
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,47 +2,7 @@
|
||||
|
||||
|
||||
# %%
|
||||
-def func():
|
||||
- x = """
|
||||
- a really long string
|
||||
- """
|
||||
- lcomp3 = [
|
||||
- # This one is actually too long to fit in a single line.
|
||||
- element.split("\n", 1)[0]
|
||||
- # yup
|
||||
- for element in collection.select_elements()
|
||||
- # right
|
||||
- if element is not None
|
||||
- ]
|
||||
- # Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
- if isinstance(exc_value, MultiError):
|
||||
- embedded = []
|
||||
- for exc in exc_value.exceptions:
|
||||
- if exc not in _seen:
|
||||
- embedded.append(
|
||||
- # This should be left alone (before)
|
||||
- traceback.TracebackException.from_exception(
|
||||
- exc,
|
||||
- limit=limit,
|
||||
- lookup_lines=lookup_lines,
|
||||
- capture_locals=capture_locals,
|
||||
- # copy the set of _seen exceptions so that duplicates
|
||||
- # shared between sub-exceptions are not omitted
|
||||
- _seen=set(_seen),
|
||||
- )
|
||||
- # This should be left alone (after)
|
||||
- )
|
||||
-
|
||||
- # everything is fine if the expression isn't nested
|
||||
- traceback.TracebackException.from_exception(
|
||||
- exc,
|
||||
- limit=limit,
|
||||
- lookup_lines=lookup_lines,
|
||||
- capture_locals=capture_locals,
|
||||
- # copy the set of _seen exceptions so that duplicates
|
||||
- # shared between sub-exceptions are not omitted
|
||||
- _seen=set(_seen),
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
"""
|
||||
lcomp3 = [
|
||||
# This one is actually too long to fit in a single line.
|
||||
element.split("\n", 1)[0]
|
||||
# yup
|
||||
for element in collection.select_elements()
|
||||
# right
|
||||
if element is not None
|
||||
]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if isinstance(exc_value, MultiError):
|
||||
embedded = []
|
||||
for exc in exc_value.exceptions:
|
||||
if exc not in _seen:
|
||||
embedded.append(
|
||||
# This should be left alone (before)
|
||||
traceback.TracebackException.from_exception(
|
||||
exc,
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
_seen=set(_seen),
|
||||
)
|
||||
# This should be left alone (after)
|
||||
)
|
||||
|
||||
# everything is fine if the expression isn't nested
|
||||
traceback.TracebackException.from_exception(
|
||||
exc,
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
_seen=set(_seen),
|
||||
)
|
||||
|
||||
|
||||
# %%
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
)
|
||||
|
||||
|
||||
class C:
|
||||
@pytest.mark.parametrize(
|
||||
("post_data", "message"),
|
||||
[
|
||||
# metadata_version errors.
|
||||
(
|
||||
{},
|
||||
"None is an invalid value for Metadata-Version. Error: This field is"
|
||||
" required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "-1"},
|
||||
"'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
|
||||
" Version see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
# name errors.
|
||||
(
|
||||
{"metadata_version": "1.2"},
|
||||
"'' is an invalid value for Name. Error: This field is required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "foo-"},
|
||||
"'foo-' is an invalid value for Name. Error: Must start and end with a"
|
||||
" letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
" '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
# version errors.
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "example"},
|
||||
"'' is an invalid value for Version. Error: This field is required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "example", "version": "dog"},
|
||||
"'dog' is an invalid value for Version. Error: Must start and end with"
|
||||
" a letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
" '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_fails_invalid_post_data(
|
||||
self, pyramid_config, db_request, post_data, message
|
||||
):
|
||||
pyramid_config.testing_securitypolicy(userid=1)
|
||||
db_request.POST = MultiDict(post_data)
|
||||
|
||||
|
||||
def foo(list_a, list_b):
|
||||
results = (
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter( # Because foo.
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
# Another comment about the filtering on is_quux goes here.
|
||||
.filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True)))
|
||||
.order_by(User.created_at.desc())
|
||||
.with_for_update(key_share=True)
|
||||
.all()
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
return (
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter(
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
)
|
||||
|
||||
|
||||
def foo3(list_a, list_b):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter(
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,94 +1,14 @@
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
-)
|
||||
-from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
- MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
-class C:
|
||||
- @pytest.mark.parametrize(
|
||||
- ("post_data", "message"),
|
||||
- [
|
||||
- # metadata_version errors.
|
||||
- (
|
||||
- {},
|
||||
- "None is an invalid value for Metadata-Version. Error: This field is"
|
||||
- " required. see"
|
||||
- " https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- (
|
||||
- {"metadata_version": "-1"},
|
||||
- "'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
|
||||
- " Version see"
|
||||
- " https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- # name errors.
|
||||
- (
|
||||
- {"metadata_version": "1.2"},
|
||||
- "'' is an invalid value for Name. Error: This field is required. see"
|
||||
- " https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- (
|
||||
- {"metadata_version": "1.2", "name": "foo-"},
|
||||
- "'foo-' is an invalid value for Name. Error: Must start and end with a"
|
||||
- " letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
- " '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- # version errors.
|
||||
- (
|
||||
- {"metadata_version": "1.2", "name": "example"},
|
||||
- "'' is an invalid value for Version. Error: This field is required. see"
|
||||
- " https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- (
|
||||
- {"metadata_version": "1.2", "name": "example", "version": "dog"},
|
||||
- "'dog' is an invalid value for Version. Error: Must start and end with"
|
||||
- " a letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
- " '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
- ),
|
||||
- ],
|
||||
- )
|
||||
- def test_fails_invalid_post_data(
|
||||
- self, pyramid_config, db_request, post_data, message
|
||||
- ):
|
||||
- pyramid_config.testing_securitypolicy(userid=1)
|
||||
- db_request.POST = MultiDict(post_data)
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-def foo(list_a, list_b):
|
||||
- results = (
|
||||
- User.query.filter(User.foo == "bar")
|
||||
- .filter( # Because foo.
|
||||
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
- )
|
||||
- .filter(User.xyz.is_(None))
|
||||
- # Another comment about the filtering on is_quux goes here.
|
||||
- .filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True)))
|
||||
- .order_by(User.created_at.desc())
|
||||
- .with_for_update(key_share=True)
|
||||
- .all()
|
||||
- )
|
||||
- return results
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo2(list_a, list_b):
|
||||
- # Standalone comment reasonably placed.
|
||||
- return (
|
||||
- User.query.filter(User.foo == "bar")
|
||||
- .filter(
|
||||
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
- )
|
||||
- .filter(User.xyz.is_(None))
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo3(list_a, list_b):
|
||||
- return (
|
||||
- # Standalone comment but weirdly placed.
|
||||
- User.query.filter(User.foo == "bar")
|
||||
- .filter(
|
||||
- db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
- )
|
||||
- .filter(User.xyz.is_(None))
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent, # NOT DRY
|
||||
)
|
||||
from com.my_lovely_company.my_lovely_team.my_lovely_project.my_lovely_component import (
|
||||
MyLovelyCompanyTeamProjectComponent as component, # DRY
|
||||
)
|
||||
|
||||
|
||||
class C:
|
||||
@pytest.mark.parametrize(
|
||||
("post_data", "message"),
|
||||
[
|
||||
# metadata_version errors.
|
||||
(
|
||||
{},
|
||||
"None is an invalid value for Metadata-Version. Error: This field is"
|
||||
" required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "-1"},
|
||||
"'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
|
||||
" Version see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
# name errors.
|
||||
(
|
||||
{"metadata_version": "1.2"},
|
||||
"'' is an invalid value for Name. Error: This field is required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "foo-"},
|
||||
"'foo-' is an invalid value for Name. Error: Must start and end with a"
|
||||
" letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
" '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
# version errors.
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "example"},
|
||||
"'' is an invalid value for Version. Error: This field is required. see"
|
||||
" https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
(
|
||||
{"metadata_version": "1.2", "name": "example", "version": "dog"},
|
||||
"'dog' is an invalid value for Version. Error: Must start and end with"
|
||||
" a letter or numeral and contain only ascii numeric and '.', '_' and"
|
||||
" '-'. see https://packaging.python.org/specifications/core-metadata",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_fails_invalid_post_data(
|
||||
self, pyramid_config, db_request, post_data, message
|
||||
):
|
||||
pyramid_config.testing_securitypolicy(userid=1)
|
||||
db_request.POST = MultiDict(post_data)
|
||||
|
||||
|
||||
def foo(list_a, list_b):
|
||||
results = (
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter( # Because foo.
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
# Another comment about the filtering on is_quux goes here.
|
||||
.filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True)))
|
||||
.order_by(User.created_at.desc())
|
||||
.with_for_update(key_share=True)
|
||||
.all()
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def foo2(list_a, list_b):
|
||||
# Standalone comment reasonably placed.
|
||||
return (
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter(
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
)
|
||||
|
||||
|
||||
def foo3(list_a, list_b):
|
||||
return (
|
||||
# Standalone comment but weirdly placed.
|
||||
User.query.filter(User.foo == "bar")
|
||||
.filter(
|
||||
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
|
||||
)
|
||||
.filter(User.xyz.is_(None))
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -86,91 +86,124 @@ if __name__ == "__main__":
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,7 +1,6 @@
|
||||
while True:
|
||||
if something.changed:
|
||||
@@ -1,61 +1,33 @@
|
||||
-while True:
|
||||
- if something.changed:
|
||||
- do.stuff() # trailing comment
|
||||
- # Comment belongs to the `if` block.
|
||||
+ do.stuff()
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
@@ -15,7 +14,6 @@
|
||||
|
||||
# then we do this
|
||||
print(i)
|
||||
- # and finally we loop around
|
||||
|
||||
with open(some_temp_file) as f:
|
||||
data = f.read()
|
||||
@@ -33,7 +31,6 @@
|
||||
# leading function comment
|
||||
def wat():
|
||||
...
|
||||
- # trailing function comment
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
while True:
|
||||
if something.changed:
|
||||
do.stuff()
|
||||
+while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
+ NOT_YET_IMPLEMENTED_StmtIf
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
|
||||
# This one is properly standalone now.
|
||||
|
||||
for i in range(100):
|
||||
# first we do this
|
||||
if i % 33 == 0:
|
||||
break
|
||||
-for i in range(100):
|
||||
- # first we do this
|
||||
- if i % 33 == 0:
|
||||
- break
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# then we do this
|
||||
print(i)
|
||||
- # then we do this
|
||||
- print(i)
|
||||
- # and finally we loop around
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
with open(some_temp_file) as f:
|
||||
data = f.read()
|
||||
-with open(some_temp_file) as f:
|
||||
- data = f.read()
|
||||
-
|
||||
-try:
|
||||
- with open(some_other_file) as w:
|
||||
- w.write(data)
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
try:
|
||||
with open(some_other_file) as w:
|
||||
w.write(data)
|
||||
|
||||
except OSError:
|
||||
print("problems")
|
||||
|
||||
import sys
|
||||
-except OSError:
|
||||
- print("problems")
|
||||
-
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# leading function comment
|
||||
def wat():
|
||||
...
|
||||
-def wat():
|
||||
- ...
|
||||
- # trailing function comment
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
def decorated1():
|
||||
...
|
||||
-@deco1
|
||||
-# leading 2
|
||||
-@deco2(with_args=True)
|
||||
-# leading 3
|
||||
-@deco3
|
||||
-def decorated1():
|
||||
- ...
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
-@deco1
|
||||
-# leading 2
|
||||
-@deco2(with_args=True)
|
||||
-# leading function comment
|
||||
-def decorated1():
|
||||
- ...
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# 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__":
|
||||
- main()
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
# This one belongs to the `while` block.
|
||||
|
||||
# Should this one, too? I guess so.
|
||||
|
||||
# This one is properly standalone now.
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# leading function comment
|
||||
def decorated1():
|
||||
...
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# SECTION COMMENT
|
||||
|
||||
|
||||
# leading 1
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# leading 1
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Note: this is fixed in
|
||||
|
@ -180,12 +213,10 @@ some_instruction
|
|||
|
||||
|
||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||
def g():
|
||||
...
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -131,138 +131,178 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -66,7 +66,7 @@
|
||||
+ element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
@@ -1,118 +1,35 @@
|
||||
-from typing import Any, Tuple
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
-def f(
|
||||
- a, # type: int
|
||||
-):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# test type comments
|
||||
-def f(a, b, c, d, e, f, g, h, i):
|
||||
- # type: (int, int, int, int, int, int, int, int, int) -> None
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-def f(
|
||||
- a, # type: int
|
||||
- b, # type: int
|
||||
- c, # type: int
|
||||
- d, # type: int
|
||||
- e, # type: int
|
||||
- f, # type: int
|
||||
- g, # type: int
|
||||
- h, # type: int
|
||||
- i, # type: int
|
||||
-):
|
||||
- # type: (...) -> None
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-def f(
|
||||
- arg, # type: int
|
||||
- *args, # type: *Any
|
||||
- default=False, # type: bool
|
||||
- **kwargs, # type: **Any
|
||||
-):
|
||||
- # type: (...) -> None
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def f(
|
||||
- a, # type: int
|
||||
- b, # type: int
|
||||
- c, # type: int
|
||||
- d, # type: int
|
||||
-):
|
||||
- # type: (...) -> None
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- element = 0 # type: int
|
||||
- another_element = 1 # type: float
|
||||
- another_element_with_long_name = 2 # type: int
|
||||
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style = (
|
||||
- 3
|
||||
- ) # type: int
|
||||
+ )
|
||||
- an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||
|
||||
- tup = (
|
||||
- another_element,
|
||||
- another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||
- ) # type: Tuple[int, int]
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- 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=some_list[0], # type: int
|
||||
-): # type: () -> int
|
||||
- c = call(
|
||||
- 0.0123,
|
||||
- 0.0456,
|
||||
- 0.0789,
|
||||
- 0.0123,
|
||||
- 0.0456,
|
||||
- 0.0789,
|
||||
- 0.0123,
|
||||
- 0.0456,
|
||||
- 0.0789,
|
||||
- a[-1], # type: ignore
|
||||
- )
|
||||
|
||||
- c = call(
|
||||
- "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def f(
|
||||
-result = ( # aaa
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # type: ignore
|
||||
|
||||
-call_to_some_function_asdf(
|
||||
- foo,
|
||||
- [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # type: ignore[arg-type]
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
from typing import Any, Tuple
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
|
||||
def f(
|
||||
a, # type: int
|
||||
):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# 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 = (
|
||||
3
|
||||
) # type: int
|
||||
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||
|
||||
tup = (
|
||||
another_element,
|
||||
another_really_really_long_element_with_a_unnecessarily_long_name_to_describe_what_it_does_enterprise_style,
|
||||
) # type: Tuple[int, int]
|
||||
|
||||
a = (
|
||||
element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
+ element
|
||||
+ another_element
|
||||
+ another_element_with_long_name
|
||||
)
|
||||
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=some_list[0], # type: int
|
||||
): # type: () -> int
|
||||
c = call(
|
||||
0.0123,
|
||||
0.0456,
|
||||
0.0789,
|
||||
0.0123,
|
||||
0.0456,
|
||||
0.0789,
|
||||
0.0123,
|
||||
0.0456,
|
||||
0.0789,
|
||||
a[-1], # type: ignore
|
||||
)
|
||||
|
||||
c = call(
|
||||
"aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa", "aaaaaaaa" # type: ignore
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
result = ( # aaa
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # type: ignore
|
||||
|
||||
call_to_some_function_asdf(
|
||||
foo,
|
||||
[AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # type: ignore[arg-type]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -152,60 +152,195 @@ def bar():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -35,9 +35,10 @@
|
||||
@@ -1,161 +1,90 @@
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
some = statement
|
||||
-# This should be stick to the statement above
|
||||
# This comment should be split from the statement above by two lines.
|
||||
-def function():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
+# This should be stick to the statement above
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
-def function():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
-async def async_function():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
-class MyClass:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
+
|
||||
+
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
-some = statement
|
||||
# This should be stick to the statement above
|
||||
|
||||
-
|
||||
# This should be split from the above by two lines
|
||||
class MyClassWithComplexLeadingComments:
|
||||
pass
|
||||
@@ -102,11 +103,9 @@
|
||||
# Leading comment before inline function
|
||||
def inline():
|
||||
pass
|
||||
-class MyClassWithComplexLeadingComments:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-class ClassWithDocstring:
|
||||
- """A docstring."""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Leading comment after a class with just a docstring
|
||||
-class MyClassAfterAnotherClassWithDocstring:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
-@deco1
|
||||
-# leading 2
|
||||
-# leading 2 extra
|
||||
-@deco2(with_args=True)
|
||||
-# leading 3
|
||||
-@deco3
|
||||
-# leading 4
|
||||
-def decorated():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
-@deco1
|
||||
-# leading 2
|
||||
-@deco2(with_args=True)
|
||||
-
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
-# leading 3 that already has an empty line
|
||||
-@deco3
|
||||
-# leading 4
|
||||
-def decorated_with_split_leading_comments():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-some = statement
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
-@deco1
|
||||
-# leading 2
|
||||
-@deco2(with_args=True)
|
||||
-# leading 3
|
||||
-@deco3
|
||||
-
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
@@ -117,11 +116,9 @@
|
||||
# Leading comment before "top-level inline" function
|
||||
def top_level_quote_inline():
|
||||
pass
|
||||
-# leading 4 that already has an empty line
|
||||
-def decorated_with_split_leading_comments():
|
||||
- pass
|
||||
-
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def main():
|
||||
- if a:
|
||||
- # Leading comment before inline function
|
||||
- def inline():
|
||||
- pass
|
||||
|
||||
- # Another leading comment
|
||||
- def another_inline():
|
||||
- pass
|
||||
-
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
@@ -138,7 +135,6 @@
|
||||
- else:
|
||||
- # More leading comments
|
||||
- def inline_after_else():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-if a:
|
||||
- # Leading comment before "top-level inline" function
|
||||
- def top_level_quote_inline():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
- # Another leading comment
|
||||
- def another_top_level_quote_inline_inline():
|
||||
- pass
|
||||
|
||||
-else:
|
||||
- # More leading comments
|
||||
- def top_level_quote_inline_after_else():
|
||||
- pass
|
||||
-
|
||||
-
|
||||
-class MyClass:
|
||||
- # First method has no empty lines between bare class def.
|
||||
- # More comments.
|
||||
- def first_method(self):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
-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
|
||||
|
||||
|
||||
@decorator1
|
||||
@@ -150,9 +146,6 @@
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
-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
|
||||
-@decorator1
|
||||
-# A standalone comment
|
||||
-def bar():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -213,158 +348,94 @@ def bar():
|
|||
```py
|
||||
# Test for https://github.com/psf/black/issues/246.
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
def function():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This multiline comments section
|
||||
# should be split from the statement
|
||||
# above by two lines.
|
||||
def function():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
async def async_function():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This comment should be split from the statement above by two lines.
|
||||
class MyClass:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# This should be stick to the statement above
|
||||
|
||||
# This should be split from the above by two lines
|
||||
class MyClassWithComplexLeadingComments:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Leading comment after a class with just a docstring
|
||||
class MyClassAfterAnotherClassWithDocstring:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
# leading 2 extra
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
|
||||
# leading 3 that already has an empty line
|
||||
@deco3
|
||||
# leading 4
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
some = statement
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# leading 1
|
||||
@deco1
|
||||
# leading 2
|
||||
@deco2(with_args=True)
|
||||
# leading 3
|
||||
@deco3
|
||||
|
||||
# leading 4 that already has an empty line
|
||||
def decorated_with_split_leading_comments():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def main():
|
||||
if a:
|
||||
# Leading comment before inline function
|
||||
def inline():
|
||||
pass
|
||||
# Another leading comment
|
||||
def another_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def inline_after_else():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
if a:
|
||||
# Leading comment before "top-level inline" function
|
||||
def top_level_quote_inline():
|
||||
pass
|
||||
# Another leading comment
|
||||
def another_top_level_quote_inline_inline():
|
||||
pass
|
||||
else:
|
||||
# More leading comments
|
||||
def top_level_quote_inline_after_else():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
class MyClass:
|
||||
# First method has no empty lines between bare class def.
|
||||
# More comments.
|
||||
def first_method(self):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3454.
|
||||
def foo():
|
||||
pass
|
||||
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
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
@decorator1
|
||||
# A standalone comment
|
||||
def bar():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -32,63 +32,53 @@ def function(a:int=42):
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,23 +1,20 @@
|
||||
@@ -1,23 +1,11 @@
|
||||
-from .config import (
|
||||
- ConfigTypeAttributes,
|
||||
- Int,
|
||||
- Path, # String,
|
||||
- # DEFAULT_TYPE_ATTRIBUTES,
|
||||
+from .config import ( ConfigTypeAttributes, Int, Path, # String,
|
||||
+ # DEFAULT_TYPE_ATTRIBUTES,
|
||||
)
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
result = 1 # A simple comment
|
||||
-result = 1 # A simple comment
|
||||
-result = (1,) # Another one
|
||||
+result = ( 1, ) # Another one
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # A simple comment
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # Another one
|
||||
|
||||
result = 1 # type: ignore
|
||||
result = 1 # This comment is talking about type: ignore
|
||||
square = Square(4) # type: Optional[Square]
|
||||
-result = 1 # type: ignore
|
||||
-result = 1 # This comment is talking about type: ignore
|
||||
-square = Square(4) # type: Optional[Square]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # type: ignore
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # This comment is talking about type: ignore
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # type: Optional[Square]
|
||||
|
||||
|
||||
-def function(a: int = 42):
|
||||
- """This docstring is already formatted
|
||||
- a
|
||||
- b
|
||||
+def function(a:int=42):
|
||||
+ """ This docstring is already formatted
|
||||
+ a
|
||||
+ b
|
||||
"""
|
||||
- """
|
||||
- # There's a NBSP + 3 spaces before
|
||||
+ # There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
pass
|
||||
- # And 4 spaces on the next line
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
from .config import ( ConfigTypeAttributes, Int, Path, # String,
|
||||
# DEFAULT_TYPE_ATTRIBUTES,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
result = 1 # A simple comment
|
||||
result = ( 1, ) # Another one
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # A simple comment
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # Another one
|
||||
|
||||
result = 1 # type: ignore
|
||||
result = 1 # This comment is talking about type: ignore
|
||||
square = Square(4) # type: Optional[Square]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # type: ignore
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # This comment is talking about type: ignore
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # type: Optional[Square]
|
||||
|
||||
|
||||
def function(a:int=42):
|
||||
""" This docstring is already formatted
|
||||
a
|
||||
b
|
||||
"""
|
||||
# There's a NBSP + 3 spaces before
|
||||
# And 4 spaces on the next line
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -109,31 +109,107 @@ async def wat():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,10 +4,12 @@
|
||||
@@ -4,93 +4,42 @@
|
||||
#
|
||||
# Has many lines. Many, many lines.
|
||||
# Many, many, many lines.
|
||||
-"""Module docstring.
|
||||
+(
|
||||
+ """Module docstring.
|
||||
+NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
+)
|
||||
-Possibly also many, many lines.
|
||||
-"""
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
@@ -19,9 +21,6 @@
|
||||
import fast
|
||||
except ImportError:
|
||||
import slow as fast
|
||||
-import os.path
|
||||
-import sys
|
||||
-
|
||||
-import a
|
||||
-from b.c import X # some noqa comment
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
||||
|
||||
-try:
|
||||
- import fast
|
||||
-except ImportError:
|
||||
- import slow as fast
|
||||
-
|
||||
-
|
||||
-# Some comment before a function.
|
||||
y = 1
|
||||
-y = 1
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
(
|
||||
# some strings
|
||||
@@ -93,4 +92,4 @@
|
||||
y # type: ignore
|
||||
)
|
||||
-
|
||||
|
||||
-def function(default=None):
|
||||
- """Docstring comes first.
|
||||
|
||||
- Possibly many lines.
|
||||
- """
|
||||
- # FIXME: Some comment about why this function is crap but still in production.
|
||||
- import inner_imports
|
||||
-
|
||||
- if inner_imports.are_evil():
|
||||
- # Explains why we have this if.
|
||||
- # In great detail indeed.
|
||||
- x = X()
|
||||
- return x.method1() # type: ignore
|
||||
-
|
||||
- # This return is also commented for some reason.
|
||||
- return default
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Explains why we use global state.
|
||||
-GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# Another comment!
|
||||
# This time two lines.
|
||||
-
|
||||
|
||||
-class Foo:
|
||||
- """Docstring for class Foo. Example from Sphinx docs."""
|
||||
|
||||
- #: Doc comment for class attribute Foo.bar.
|
||||
- #: It can have multiple lines.
|
||||
- bar = 1
|
||||
-
|
||||
- flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||
-
|
||||
- baz = 2
|
||||
- """Docstring for class attribute Foo.baz."""
|
||||
-
|
||||
- def __init__(self):
|
||||
- #: Doc comment for instance attribute qux.
|
||||
- self.qux = 3
|
||||
-
|
||||
- self.spam = 4
|
||||
- """Docstring for instance attribute spam."""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
#' <h1>This is pweave!</h1>
|
||||
|
||||
|
||||
-@fast(really=True)
|
||||
-async def wat():
|
||||
- # This comment, for some reason \
|
||||
- # contains a trailing backslash.
|
||||
- async with X.open_async() as x: # Some more comments
|
||||
- result = await x.method1()
|
||||
- # Comment after ending a block.
|
||||
- if result:
|
||||
- print("A OK", file=sys.stdout)
|
||||
- # Comment between things.
|
||||
- print()
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
|
@ -151,90 +227,40 @@ async def wat():
|
|||
#
|
||||
# Has many lines. Many, many lines.
|
||||
# Many, many, many lines.
|
||||
(
|
||||
"""Module docstring.
|
||||
NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
Possibly also many, many lines.
|
||||
"""
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # some noqa comment
|
||||
|
||||
import a
|
||||
from b.c import X # some noqa comment
|
||||
|
||||
try:
|
||||
import fast
|
||||
except ImportError:
|
||||
import slow as fast
|
||||
y = 1
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
(
|
||||
# some strings
|
||||
y # type: ignore
|
||||
)
|
||||
|
||||
|
||||
def function(default=None):
|
||||
"""Docstring comes first.
|
||||
|
||||
Possibly many lines.
|
||||
"""
|
||||
# FIXME: Some comment about why this function is crap but still in production.
|
||||
import inner_imports
|
||||
|
||||
if inner_imports.are_evil():
|
||||
# Explains why we have this if.
|
||||
# In great detail indeed.
|
||||
x = X()
|
||||
return x.method1() # type: ignore
|
||||
|
||||
# This return is also commented for some reason.
|
||||
return default
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Explains why we use global state.
|
||||
GLOBAL_STATE = {"a": a(1), "b": a(2), "c": a(3)}
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# Another comment!
|
||||
# This time two lines.
|
||||
|
||||
|
||||
class Foo:
|
||||
"""Docstring for class Foo. Example from Sphinx docs."""
|
||||
|
||||
#: Doc comment for class attribute Foo.bar.
|
||||
#: It can have multiple lines.
|
||||
bar = 1
|
||||
|
||||
flox = 1.5 #: Doc comment for Foo.flox. One line only.
|
||||
|
||||
baz = 2
|
||||
"""Docstring for class attribute Foo.baz."""
|
||||
|
||||
def __init__(self):
|
||||
#: Doc comment for instance attribute qux.
|
||||
self.qux = 3
|
||||
|
||||
self.spam = 4
|
||||
"""Docstring for instance attribute spam."""
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
#' <h1>This is pweave!</h1>
|
||||
|
||||
|
||||
@fast(really=True)
|
||||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
async with X.open_async() as x: # Some more comments
|
||||
result = await x.method1()
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
print("A OK", file=sys.stdout)
|
||||
# Comment between things.
|
||||
print()
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Some closing comments.
|
||||
|
|
|
@ -194,272 +194,195 @@ class C:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -34,7 +34,7 @@
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
@@ -1,181 +1 @@
|
||||
-class C:
|
||||
- def test(self) -> None:
|
||||
- with patch("black.out", print):
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "2 files reformatted, 1 file left unchanged, 1 file failed to"
|
||||
- " reformat.",
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
|
||||
- " reformat.",
|
||||
- )
|
||||
- for i in (a,):
|
||||
- if (
|
||||
- # Rule 1
|
||||
- i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
- ):
|
||||
- while (
|
||||
- # Just a comment
|
||||
- call()
|
||||
- # Another
|
||||
- ):
|
||||
- print(i)
|
||||
- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
- push_manager=context.request.resource_manager,
|
||||
- max_items_to_push=num_items,
|
||||
- batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
+ batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE
|
||||
).push(
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
@@ -68,7 +68,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- ).push(
|
||||
- # Only send the first n items.
|
||||
- items=items[:num_items]
|
||||
- )
|
||||
- return (
|
||||
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
- % (test.name, test.filename, lineno, lname, err)
|
||||
- )
|
||||
-
|
||||
- def omitting_trailers(self) -> None:
|
||||
- get_collection(
|
||||
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
- )[OneLevelIndex]
|
||||
- get_collection(
|
||||
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
|
||||
- d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
- 22
|
||||
- ]
|
||||
- assignment = (
|
||||
- some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
- )
|
||||
-
|
||||
- def easy_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
@@ -80,7 +80,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- } == expected, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
@@ -92,7 +92,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- }, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
@@ -105,7 +105,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- }
|
||||
-
|
||||
- def tricky_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
@@ -119,7 +119,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- } == expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ), "Not what we expected"
|
||||
-
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
@@ -135,7 +135,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- } == expected, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- )
|
||||
-
|
||||
- assert expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ) == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
@@ -147,7 +147,7 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- }, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
@@ -176,6 +176,6 @@
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
- }, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- " because it's too long"
|
||||
- )
|
||||
-
|
||||
- dis_c_instance_method = """\
|
||||
- %3d 0 LOAD_FAST 1 (x)
|
||||
- 2 LOAD_CONST 1 (1)
|
||||
- 4 COMPARE_OP 2 (==)
|
||||
- 6 LOAD_FAST 0 (self)
|
||||
- 8 STORE_ATTR 0 (x)
|
||||
- 10 LOAD_CONST 0 (None)
|
||||
- 12 RETURN_VALUE
|
||||
- """ % (
|
||||
- _C.__init__.__code__.co_firstlineno + 1,
|
||||
- )
|
||||
-
|
||||
- assert (
|
||||
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
- == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
+ key9: value9
|
||||
}
|
||||
)
|
||||
- }
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
self.assertEqual(
|
||||
unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 1 file left unchanged, 1 file failed to"
|
||||
" reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 2 files left unchanged, 2 files failed to"
|
||||
" reformat.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE
|
||||
).push(
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex]
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9
|
||||
}
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -0,0 +1,574 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
self.assertEqual(
|
||||
unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 1 file left unchanged, 1 file failed to"
|
||||
" reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 2 files left unchanged, 2 files failed to"
|
||||
" reformat.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex]
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,181 +1 @@
|
||||
-class C:
|
||||
- def test(self) -> None:
|
||||
- with patch("black.out", print):
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "2 files reformatted, 1 file left unchanged, 1 file failed to"
|
||||
- " reformat.",
|
||||
- )
|
||||
- self.assertEqual(
|
||||
- unstyle(str(report)),
|
||||
- "2 files reformatted, 2 files left unchanged, 2 files failed to"
|
||||
- " reformat.",
|
||||
- )
|
||||
- for i in (a,):
|
||||
- if (
|
||||
- # Rule 1
|
||||
- i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
- ):
|
||||
- while (
|
||||
- # Just a comment
|
||||
- call()
|
||||
- # Another
|
||||
- ):
|
||||
- print(i)
|
||||
- xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
- push_manager=context.request.resource_manager,
|
||||
- max_items_to_push=num_items,
|
||||
- batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
- ).push(
|
||||
- # Only send the first n items.
|
||||
- items=items[:num_items]
|
||||
- )
|
||||
- return (
|
||||
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
- % (test.name, test.filename, lineno, lname, err)
|
||||
- )
|
||||
-
|
||||
- def omitting_trailers(self) -> None:
|
||||
- get_collection(
|
||||
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
- )[OneLevelIndex]
|
||||
- get_collection(
|
||||
- hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
- )[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
|
||||
- d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
- 22
|
||||
- ]
|
||||
- assignment = (
|
||||
- some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
- )
|
||||
-
|
||||
- def easy_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
-
|
||||
- def tricky_asserts(self) -> None:
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ), "Not what we expected"
|
||||
-
|
||||
- assert {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- } == expected, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- )
|
||||
-
|
||||
- assert expected(
|
||||
- value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
- ) == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, "Not what we expected"
|
||||
-
|
||||
- assert expected == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }, (
|
||||
- "Not what we expected and the message is too long to fit in one line"
|
||||
- " because it's too long"
|
||||
- )
|
||||
-
|
||||
- dis_c_instance_method = """\
|
||||
- %3d 0 LOAD_FAST 1 (x)
|
||||
- 2 LOAD_CONST 1 (1)
|
||||
- 4 COMPARE_OP 2 (==)
|
||||
- 6 LOAD_FAST 0 (self)
|
||||
- 8 STORE_ATTR 0 (x)
|
||||
- 10 LOAD_CONST 0 (None)
|
||||
- 12 RETURN_VALUE
|
||||
- """ % (
|
||||
- _C.__init__.__code__.co_firstlineno + 1,
|
||||
- )
|
||||
-
|
||||
- assert (
|
||||
- expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
- == {
|
||||
- key1: value1,
|
||||
- key2: value2,
|
||||
- key3: value3,
|
||||
- key4: value4,
|
||||
- key5: value5,
|
||||
- key6: value6,
|
||||
- key7: value7,
|
||||
- key8: value8,
|
||||
- key9: value9,
|
||||
- }
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
class C:
|
||||
def test(self) -> None:
|
||||
with patch("black.out", print):
|
||||
self.assertEqual(
|
||||
unstyle(str(report)), "1 file reformatted, 1 file failed to reformat."
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"1 file reformatted, 1 file left unchanged, 1 file failed to reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 1 file left unchanged, 1 file failed to"
|
||||
" reformat.",
|
||||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
"2 files reformatted, 2 files left unchanged, 2 files failed to"
|
||||
" reformat.",
|
||||
)
|
||||
for i in (a,):
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while (
|
||||
# Just a comment
|
||||
call()
|
||||
# Another
|
||||
):
|
||||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
return (
|
||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
)
|
||||
|
||||
def omitting_trailers(self) -> None:
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex]
|
||||
get_collection(
|
||||
hey_this_is_a_very_long_call, it_has_funny_attributes, really=True
|
||||
)[OneLevelIndex][TwoLevelIndex][ThreeLevelIndex][FourLevelIndex]
|
||||
d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
|
||||
22
|
||||
]
|
||||
assignment = (
|
||||
some.rather.elaborate.rule() and another.rule.ending_with.index[123]
|
||||
)
|
||||
|
||||
def easy_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
|
||||
def tricky_asserts(self) -> None:
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
), "Not what we expected"
|
||||
|
||||
assert {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
} == expected, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
)
|
||||
|
||||
assert expected(
|
||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||
) == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, "Not what we expected"
|
||||
|
||||
assert expected == {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}, (
|
||||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
|
||||
dis_c_instance_method = """\
|
||||
%3d 0 LOAD_FAST 1 (x)
|
||||
2 LOAD_CONST 1 (1)
|
||||
4 COMPARE_OP 2 (==)
|
||||
6 LOAD_FAST 0 (self)
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
""" % (
|
||||
_C.__init__.__code__.co_firstlineno + 1,
|
||||
)
|
||||
|
||||
assert (
|
||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||
== {
|
||||
key1: value1,
|
||||
key2: value2,
|
||||
key3: value3,
|
||||
key4: value4,
|
||||
key5: value5,
|
||||
key6: value6,
|
||||
key7: value7,
|
||||
key8: value8,
|
||||
key9: value9,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
# Make sure when the file ends with class's docstring,
|
||||
# It doesn't add extra blank lines.
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,3 @@
|
||||
# Make sure when the file ends with class's docstring,
|
||||
# It doesn't add extra blank lines.
|
||||
-class ClassWithDocstring:
|
||||
- """A docstring."""
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Make sure when the file ends with class's docstring,
|
||||
# It doesn't add extra blank lines.
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
# Make sure when the file ends with class's docstring,
|
||||
# It doesn't add extra blank lines.
|
||||
class ClassWithDocstring:
|
||||
"""A docstring."""
|
||||
```
|
||||
|
||||
|
|
@ -63,81 +63,98 @@ def single_quote_docstring_over_line_limit2():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,9 +1,11 @@
|
||||
def docstring_almost_at_line_limit():
|
||||
@@ -1,48 +1,28 @@
|
||||
-def docstring_almost_at_line_limit():
|
||||
- """long docstring................................................................."""
|
||||
+ """long docstring.................................................................
|
||||
+ """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
@@ -45,4 +47,4 @@
|
||||
-def mulitline_docstring_almost_at_line_limit():
|
||||
- """long docstring.................................................................
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- ..................................................................................
|
||||
- """
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
- f"""long docstring................................................................
|
||||
|
||||
- ..................................................................................
|
||||
- """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_quote_docstring_over_line_limit2():
|
||||
-def docstring_at_line_limit():
|
||||
- """long docstring................................................................"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def docstring_at_line_limit_with_prefix():
|
||||
- f"""long docstring..............................................................."""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def multiline_docstring_at_line_limit():
|
||||
- """first line-----------------------------------------------------------------------
|
||||
-
|
||||
- second line----------------------------------------------------------------------"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def multiline_docstring_at_line_limit_with_prefix():
|
||||
- f"""first line----------------------------------------------------------------------
|
||||
-
|
||||
- second line----------------------------------------------------------------------"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-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).'
|
||||
-
|
||||
-
|
||||
-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)."
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||
f"""long docstring................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_at_line_limit_with_prefix():
|
||||
f"""long docstring..............................................................."""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit_with_prefix():
|
||||
f"""first line----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
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)."
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
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).'
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -234,86 +234,64 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,83 +1,85 @@
|
||||
class MyClass:
|
||||
+ """ Multiline
|
||||
+ class docstring
|
||||
+ """
|
||||
+
|
||||
+ def method(self):
|
||||
"""Multiline
|
||||
@@ -1,219 +1,105 @@
|
||||
-class MyClass:
|
||||
- """Multiline
|
||||
- class docstring
|
||||
+ method docstring
|
||||
"""
|
||||
-
|
||||
- """
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- def method(self):
|
||||
- """Multiline
|
||||
- method docstring
|
||||
- """
|
||||
- pass
|
||||
+ pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def foo():
|
||||
-def foo():
|
||||
- """This is a docstring with
|
||||
- some lines of text here
|
||||
- """
|
||||
- return
|
||||
+ """This is a docstring with
|
||||
+ some lines of text here
|
||||
+ """
|
||||
+ return
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def bar():
|
||||
-def bar():
|
||||
- """This is another docstring
|
||||
- with more lines of text
|
||||
- """
|
||||
- return
|
||||
+ '''This is another docstring
|
||||
+ with more lines of text
|
||||
+ '''
|
||||
+ return
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def baz():
|
||||
-def baz():
|
||||
- '''"This" is a string with some
|
||||
- embedded "quotes"'''
|
||||
- return
|
||||
+ '''"This" is a string with some
|
||||
+ embedded "quotes"'''
|
||||
+ return
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def troz():
|
||||
-def troz():
|
||||
- """Indentation with tabs
|
||||
- is just as OK
|
||||
- """
|
||||
- return
|
||||
+ '''Indentation with tabs
|
||||
+ is just as OK
|
||||
+ '''
|
||||
+ return
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def zort():
|
||||
-def zort():
|
||||
- """Another
|
||||
- multiline
|
||||
- docstring
|
||||
- """
|
||||
- pass
|
||||
+ """Another
|
||||
+ multiline
|
||||
+ docstring
|
||||
+ """
|
||||
+ pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def poit():
|
||||
-def poit():
|
||||
- """
|
||||
- Lorem ipsum dolor sit amet.
|
||||
+ """
|
||||
+ Lorem ipsum dolor sit amet.
|
||||
|
||||
- Consectetur adipiscing elit:
|
||||
- - sed do eiusmod tempor incididunt ut labore
|
||||
|
@ -323,133 +301,110 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
|||
- - aliquip ex ea commodo consequat
|
||||
- """
|
||||
- pass
|
||||
+ Consectetur adipiscing elit:
|
||||
+ - sed do eiusmod tempor incididunt ut labore
|
||||
+ - dolore magna aliqua
|
||||
+ - enim ad minim veniam
|
||||
+ - quis nostrud exercitation ullamco laboris nisi
|
||||
+ - aliquip ex ea commodo consequat
|
||||
+ """
|
||||
+ pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def under_indent():
|
||||
-def under_indent():
|
||||
- """
|
||||
- These lines are indented in a way that does not
|
||||
- make sense.
|
||||
- """
|
||||
- pass
|
||||
+ """
|
||||
+ These lines are indented in a way that does not
|
||||
+make sense.
|
||||
+ """
|
||||
+ pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def over_indent():
|
||||
-def over_indent():
|
||||
- """
|
||||
- This has a shallow indent
|
||||
- - But some lines are deeper
|
||||
- - And the closing quote is too deep
|
||||
+ """
|
||||
+ This has a shallow indent
|
||||
+ - But some lines are deeper
|
||||
+ - And the closing quote is too deep
|
||||
"""
|
||||
- """
|
||||
- pass
|
||||
+ pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_line():
|
||||
-def single_line():
|
||||
- """But with a newline after it!"""
|
||||
+ """But with a newline after it!
|
||||
+
|
||||
+ """
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
@@ -88,25 +90,30 @@
|
||||
-def this():
|
||||
- r"""
|
||||
- 'hey ho'
|
||||
- """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def that():
|
||||
-def that():
|
||||
- """ "hey yah" """
|
||||
+ """ "hey yah" """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def and_that():
|
||||
-def and_that():
|
||||
- """
|
||||
- "hey yah" """
|
||||
+ """
|
||||
+ "hey yah" """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def and_this():
|
||||
-def and_this():
|
||||
- '''
|
||||
- "hey yah"'''
|
||||
+ '''
|
||||
+ "hey yah"'''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
-def multiline_whitespace():
|
||||
- """ """
|
||||
+ '''
|
||||
+
|
||||
+
|
||||
+
|
||||
+
|
||||
+ '''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
-def oneline_whitespace():
|
||||
- """ """
|
||||
+ ''' '''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def empty():
|
||||
@@ -114,12 +121,11 @@
|
||||
-def empty():
|
||||
- """"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_quotes():
|
||||
-def single_quotes():
|
||||
- "testing"
|
||||
+ 'testing'
|
||||
|
||||
-
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def believe_it_or_not_this_is_in_the_py_stdlib():
|
||||
- '''
|
||||
- "hey yah"'''
|
||||
+def believe_it_or_not_this_is_in_the_py_stdlib(): '''
|
||||
+"hey yah"'''
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def ignored_docstring():
|
||||
@@ -128,32 +134,32 @@
|
||||
-def ignored_docstring():
|
||||
- """a => \
|
||||
-b"""
|
||||
|
||||
+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_StmtFunctionDef
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
-def docstring_with_inline_tabs_and_space_indentation():
|
||||
- """hey
|
||||
|
||||
tab separated value
|
||||
- tab separated value
|
||||
- tab at start of line and then a tab separated value
|
||||
- multiple tabs at the beginning and inline
|
||||
- mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
-
|
||||
- line ends with some tabs
|
||||
+ tab at start of line and then a tab separated value
|
||||
+ multiple tabs at the beginning and inline
|
||||
+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
+
|
||||
+ line ends with some tabs
|
||||
"""
|
||||
- """
|
||||
-
|
||||
+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 at start of line and then a tab separated value
|
||||
|
@ -459,296 +414,191 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
|||
- line ends with some tabs
|
||||
- """
|
||||
- pass
|
||||
+ tab separated value
|
||||
+ tab at start of line and then a tab separated value
|
||||
+ multiple tabs at the beginning and inline
|
||||
+ mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
+
|
||||
+ line ends with some tabs
|
||||
+ """
|
||||
+ pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def backslash_space():
|
||||
@@ -161,14 +167,14 @@
|
||||
-def backslash_space():
|
||||
- """\ """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_backslash_1():
|
||||
-def multiline_backslash_1():
|
||||
- """
|
||||
+ '''
|
||||
hey\there\
|
||||
- hey\there\
|
||||
- \ """
|
||||
+ \ '''
|
||||
|
||||
|
||||
def multiline_backslash_2():
|
||||
-
|
||||
-
|
||||
-def multiline_backslash_2():
|
||||
- """
|
||||
- hey there \ """
|
||||
+ '''
|
||||
+ hey there \ '''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Regression test for #3425
|
||||
@@ -178,8 +184,8 @@
|
||||
-def multiline_backslash_really_long_dont_crash():
|
||||
- """
|
||||
- hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_backslash_3():
|
||||
-def multiline_backslash_3():
|
||||
- """
|
||||
- already escaped \\"""
|
||||
+ '''
|
||||
+ already escaped \\ '''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
@@ -188,7 +194,7 @@
|
||||
-def my_god_its_full_of_stars_1():
|
||||
- "I'm sorry Dave\u2001"
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
@@ -213,7 +219,7 @@
|
||||
|
||||
|
||||
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>
|
||||
-def docstring_almost_at_line_limit():
|
||||
- """long docstring................................................................."""
|
||||
-
|
||||
-
|
||||
-def docstring_almost_at_line_limit2():
|
||||
- """long docstring.................................................................
|
||||
-
|
||||
- ..................................................................................
|
||||
- """
|
||||
+ '''
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def docstring_at_line_limit():
|
||||
- """long docstring................................................................"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def multiline_docstring_at_line_limit():
|
||||
- """first line-----------------------------------------------------------------------
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- second line----------------------------------------------------------------------"""
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
- """'<text here>
|
||||
|
||||
- <text here, since without another non-empty line black is stable>
|
||||
- """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class MyClass:
|
||||
""" Multiline
|
||||
class docstring
|
||||
"""
|
||||
|
||||
def method(self):
|
||||
"""Multiline
|
||||
method docstring
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def foo():
|
||||
"""This is a docstring with
|
||||
some lines of text here
|
||||
"""
|
||||
return
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def bar():
|
||||
'''This is another docstring
|
||||
with more lines of text
|
||||
'''
|
||||
return
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def baz():
|
||||
'''"This" is a string with some
|
||||
embedded "quotes"'''
|
||||
return
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def troz():
|
||||
'''Indentation with tabs
|
||||
is just as OK
|
||||
'''
|
||||
return
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def zort():
|
||||
"""Another
|
||||
multiline
|
||||
docstring
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def poit():
|
||||
"""
|
||||
Lorem ipsum dolor sit amet.
|
||||
|
||||
Consectetur adipiscing elit:
|
||||
- sed do eiusmod tempor incididunt ut labore
|
||||
- dolore magna aliqua
|
||||
- enim ad minim veniam
|
||||
- quis nostrud exercitation ullamco laboris nisi
|
||||
- aliquip ex ea commodo consequat
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def under_indent():
|
||||
"""
|
||||
These lines are indented in a way that does not
|
||||
make sense.
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def over_indent():
|
||||
"""
|
||||
This has a shallow indent
|
||||
- But some lines are deeper
|
||||
- And the closing quote is too deep
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_line():
|
||||
"""But with a newline after it!
|
||||
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def this():
|
||||
r"""
|
||||
'hey ho'
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def that():
|
||||
""" "hey yah" """
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def and_that():
|
||||
"""
|
||||
"hey yah" """
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def and_this():
|
||||
'''
|
||||
"hey yah"'''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_whitespace():
|
||||
'''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
'''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def oneline_whitespace():
|
||||
''' '''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def empty():
|
||||
""""""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_quotes():
|
||||
'testing'
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def believe_it_or_not_this_is_in_the_py_stdlib(): '''
|
||||
"hey yah"'''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def ignored_docstring():
|
||||
"""a => \
|
||||
b"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def single_line_docstring_with_whitespace():
|
||||
""" This should be stripped """
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_space_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_with_inline_tabs_and_tab_indentation():
|
||||
"""hey
|
||||
|
||||
tab separated value
|
||||
tab at start of line and then a tab separated value
|
||||
multiple tabs at the beginning and inline
|
||||
mixed tabs and spaces at beginning. next line has mixed tabs and spaces only.
|
||||
|
||||
line ends with some tabs
|
||||
"""
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def backslash_space():
|
||||
"""\ """
|
||||
|
||||
|
||||
def multiline_backslash_1():
|
||||
'''
|
||||
hey\there\
|
||||
\ '''
|
||||
|
||||
|
||||
def multiline_backslash_2():
|
||||
'''
|
||||
hey there \ '''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Regression test for #3425
|
||||
def multiline_backslash_really_long_dont_crash():
|
||||
"""
|
||||
hey there hello guten tag hi hoow are you ola zdravstvuyte ciao como estas ca va \ """
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_backslash_3():
|
||||
'''
|
||||
already escaped \\ '''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def my_god_its_full_of_stars_1():
|
||||
"I'm sorry Dave\u2001"
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# the space below is actually a \u2001, removed in output
|
||||
def my_god_its_full_of_stars_2():
|
||||
"I'm sorry Dave "
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit():
|
||||
"""long docstring................................................................."""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_almost_at_line_limit2():
|
||||
"""long docstring.................................................................
|
||||
|
||||
..................................................................................
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_at_line_limit():
|
||||
"""long docstring................................................................"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def multiline_docstring_at_line_limit():
|
||||
"""first line-----------------------------------------------------------------------
|
||||
|
||||
second line----------------------------------------------------------------------"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def stable_quote_normalization_with_immediate_inner_single_quote(self):
|
||||
''''<text here>
|
||||
|
||||
<text here, since without another non-empty line black is stable>
|
||||
'''
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -105,162 +105,116 @@ def g():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -3,9 +3,9 @@
|
||||
@@ -1,89 +1,12 @@
|
||||
-"""Docstring."""
|
||||
+NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
|
||||
# leading comment
|
||||
def f():
|
||||
-def f():
|
||||
- NO = ""
|
||||
- SPACE = " "
|
||||
- DOUBLESPACE = " "
|
||||
+ NO = ''
|
||||
+ SPACE = ' '
|
||||
+ DOUBLESPACE = ' '
|
||||
-
|
||||
- t = leaf.type
|
||||
- p = leaf.parent # trailing comment
|
||||
- v = leaf.value
|
||||
-
|
||||
- if t in ALWAYS_NO_SPACE:
|
||||
- pass
|
||||
- if t == token.COMMENT: # another trailing comment
|
||||
- return DOUBLESPACE
|
||||
-
|
||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
-
|
||||
- prev = leaf.prev_sibling
|
||||
- if not prev:
|
||||
- prevp = preceding_leaf(p)
|
||||
- if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
- return NO
|
||||
-
|
||||
- if prevp.type == token.EQUAL:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.argument,
|
||||
- }:
|
||||
- return NO
|
||||
-
|
||||
- elif prevp.type == token.DOUBLESTAR:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.dictsetmaker,
|
||||
- }:
|
||||
- return NO
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent # trailing comment
|
||||
@@ -16,14 +16,19 @@
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
+
|
||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
|
||||
+
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
+
|
||||
+
|
||||
return NO
|
||||
|
||||
+
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
@@ -48,12 +53,11 @@
|
||||
###############################################################################
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
-
|
||||
|
||||
def g():
|
||||
-def g():
|
||||
- NO = ""
|
||||
- SPACE = " "
|
||||
- DOUBLESPACE = " "
|
||||
+ NO = ''
|
||||
+ SPACE = ' '
|
||||
+ DOUBLESPACE = ' '
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent
|
||||
@@ -67,7 +71,7 @@
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
-
|
||||
- t = leaf.type
|
||||
- p = leaf.parent
|
||||
- v = leaf.value
|
||||
-
|
||||
- # Comment because comments
|
||||
-
|
||||
- if t in ALWAYS_NO_SPACE:
|
||||
- pass
|
||||
- if t == token.COMMENT:
|
||||
- return DOUBLESPACE
|
||||
-
|
||||
- # Another comment because more comments
|
||||
- assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
+ assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}'
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
-
|
||||
- prev = leaf.prev_sibling
|
||||
- if not prev:
|
||||
- prevp = preceding_leaf(p)
|
||||
-
|
||||
- if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
- # Start of the line or a bracketed expression.
|
||||
- # More than one line for the comment.
|
||||
- return NO
|
||||
-
|
||||
- if prevp.type == token.EQUAL:
|
||||
- if prevp.parent and prevp.parent.type in {
|
||||
- syms.typedargslist,
|
||||
- syms.varargslist,
|
||||
- syms.parameters,
|
||||
- syms.arglist,
|
||||
- syms.argument,
|
||||
- }:
|
||||
- return NO
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
"""Docstring."""
|
||||
NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
|
||||
# leading comment
|
||||
def f():
|
||||
NO = ''
|
||||
SPACE = ' '
|
||||
DOUBLESPACE = ' '
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent # trailing comment
|
||||
v = leaf.value
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT: # another trailing comment
|
||||
return DOUBLESPACE
|
||||
|
||||
|
||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
|
||||
|
||||
return NO
|
||||
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
|
||||
elif prevp.type == token.DOUBLESTAR:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.dictsetmaker,
|
||||
}:
|
||||
return NO
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
###############################################################################
|
||||
# SECTION BECAUSE SECTIONS
|
||||
###############################################################################
|
||||
|
||||
def g():
|
||||
NO = ''
|
||||
SPACE = ' '
|
||||
DOUBLESPACE = ' '
|
||||
|
||||
t = leaf.type
|
||||
p = leaf.parent
|
||||
v = leaf.value
|
||||
|
||||
# Comment because comments
|
||||
|
||||
if t in ALWAYS_NO_SPACE:
|
||||
pass
|
||||
if t == token.COMMENT:
|
||||
return DOUBLESPACE
|
||||
|
||||
# Another comment because more comments
|
||||
assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}'
|
||||
|
||||
prev = leaf.prev_sibling
|
||||
if not prev:
|
||||
prevp = preceding_leaf(p)
|
||||
|
||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||
# Start of the line or a bracketed expression.
|
||||
# More than one line for the comment.
|
||||
return NO
|
||||
|
||||
if prevp.type == token.EQUAL:
|
||||
if prevp.parent and prevp.parent.type in {
|
||||
syms.typedargslist,
|
||||
syms.varargslist,
|
||||
syms.parameters,
|
||||
syms.arglist,
|
||||
syms.argument,
|
||||
}:
|
||||
return NO
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -53,46 +53,67 @@ def test_calculate_fades():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -3,6 +3,7 @@
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
@@ -1,40 +1,26 @@
|
||||
-import pytest
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-TmSt = 1
|
||||
-TmEx = 2
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+
|
||||
|
||||
# fmt: off
|
||||
|
||||
# Test data:
|
||||
@@ -18,18 +19,22 @@
|
||||
def test_fader(test):
|
||||
pass
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
-@pytest.mark.parametrize('test', [
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
+
|
||||
def check_fader(test):
|
||||
|
||||
pass
|
||||
|
||||
+
|
||||
def verify_fader(test):
|
||||
# misaligned comment
|
||||
pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
+
|
||||
def verify_fader(test):
|
||||
"""Hey, ho."""
|
||||
assert test.passed()
|
||||
- # Test don't manage the volume
|
||||
- [
|
||||
- ('stuff', 'in')
|
||||
- ],
|
||||
-])
|
||||
-def test_fader(test):
|
||||
- pass
|
||||
|
||||
+
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
-def check_fader(test):
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- pass
|
||||
|
||||
-def verify_fader(test):
|
||||
- # misaligned comment
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def verify_fader(test):
|
||||
- """Hey, ho."""
|
||||
- assert test.passed()
|
||||
|
||||
-def test_calculate_fades():
|
||||
- calcs = [
|
||||
- # one is zero/none
|
||||
- (0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
- (None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
- ]
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
import pytest
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
TmSt = 1
|
||||
TmEx = 2
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# fmt: off
|
||||
|
@ -100,38 +121,19 @@ TmEx = 2
|
|||
# Test data:
|
||||
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
|
||||
|
||||
@pytest.mark.parametrize('test', [
|
||||
|
||||
# Test don't manage the volume
|
||||
[
|
||||
('stuff', 'in')
|
||||
],
|
||||
])
|
||||
def test_fader(test):
|
||||
pass
|
||||
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):
|
||||
"""Hey, ho."""
|
||||
assert test.passed()
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def test_calculate_fades():
|
||||
calcs = [
|
||||
# one is zero/none
|
||||
(0, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
(None, 4, 0, 0, 10, 0, 0, 6, 10),
|
||||
]
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
# fmt: on
|
||||
```
|
||||
|
|
|
@ -30,36 +30,39 @@ x = [
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -12,4 +12,6 @@
|
||||
]
|
||||
@@ -1,15 +1,9 @@
|
||||
# fmt: off
|
||||
-x = [
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
-x = [
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
|
||||
-x = [1, 2, 3, 4]
|
||||
+x = [
|
||||
+ 1, 2, 3, 4
|
||||
+]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
|
||||
# fmt: off
|
||||
x = [
|
||||
1, 2,
|
||||
3, 4,
|
||||
]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
|
||||
x = [
|
||||
1, 2, 3, 4
|
||||
]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -26,13 +26,16 @@ def f(): pass
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,17 +4,11 @@
|
||||
3, 4,
|
||||
])
|
||||
# fmt: on
|
||||
@@ -1,20 +1,5 @@
|
||||
# fmt: off
|
||||
-@test([
|
||||
- 1, 2,
|
||||
- 3, 4,
|
||||
-])
|
||||
-# fmt: on
|
||||
-def f():
|
||||
- pass
|
||||
+def f(): pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-@test(
|
||||
|
@ -45,30 +48,17 @@ def f(): pass
|
|||
-)
|
||||
-def f():
|
||||
- pass
|
||||
+@test([
|
||||
+ 1, 2,
|
||||
+ 3, 4,
|
||||
+])
|
||||
+def f(): pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# fmt: off
|
||||
@test([
|
||||
1, 2,
|
||||
3, 4,
|
||||
])
|
||||
# fmt: on
|
||||
def f(): pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
@test([
|
||||
1, 2,
|
||||
3, 4,
|
||||
])
|
||||
def f(): pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -97,133 +97,136 @@ elif unformatted:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -44,7 +44,7 @@
|
||||
print ( "This won't be formatted" )
|
||||
print ( "This won't be formatted either" )
|
||||
else:
|
||||
@@ -1,87 +1,29 @@
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
-setup(
|
||||
- entry_points={
|
||||
- # fmt: off
|
||||
- "console_scripts": [
|
||||
- "foo-bar"
|
||||
- "=foo.bar.:main",
|
||||
- # fmt: on
|
||||
- ] # Includes an formatted indentation.
|
||||
- },
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2015.
|
||||
-run(
|
||||
- # fmt: off
|
||||
- [
|
||||
- "ls",
|
||||
- "-la",
|
||||
- ]
|
||||
- # fmt: on
|
||||
- + path,
|
||||
- check=True,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
-def test_func():
|
||||
- # yapf: disable
|
||||
- if unformatted( args ):
|
||||
- return True
|
||||
- # yapf: enable
|
||||
- elif b:
|
||||
- return True
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- return False
|
||||
|
||||
-
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
-if True:
|
||||
- # fmt: off
|
||||
- for _ in range( 1 ):
|
||||
- # fmt: on
|
||||
- print ( "This won't be formatted" )
|
||||
- print ( "This won't be formatted either" )
|
||||
-else:
|
||||
- print("This will be formatted")
|
||||
+ print ( "This will be formatted" )
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
@@ -61,7 +61,7 @@
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
print ( "This won't be formatted either" )
|
||||
|
||||
-class A:
|
||||
- async def call(param):
|
||||
- if param:
|
||||
- # fmt: off
|
||||
- if param[0:4] in (
|
||||
- "ABCD", "EFGH"
|
||||
- ) :
|
||||
- # fmt: on
|
||||
- print ( "This won't be formatted" )
|
||||
-
|
||||
- elif param[0:4] in ("ZZZZ",):
|
||||
- print ( "This won't be formatted either" )
|
||||
-
|
||||
- print("This will be formatted")
|
||||
+ print ( "This will be formatted" )
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
@@ -72,10 +72,7 @@
|
||||
-class Named(t.Protocol):
|
||||
- # fmt: off
|
||||
- @property
|
||||
- def this_wont_be_formatted ( self ) -> str: ...
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class Factory(t.Protocol):
|
||||
-class Factory(t.Protocol):
|
||||
- def this_will_be_formatted(self, **kwargs) -> Named:
|
||||
- ...
|
||||
-
|
||||
- # fmt: on
|
||||
+ def this_will_be_formatted ( self, **kwargs ) -> Named: ...
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- # fmt: on
|
||||
-
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3436.
|
||||
@@ -83,5 +80,5 @@
|
||||
return x
|
||||
# fmt: off
|
||||
elif unformatted:
|
||||
-if x:
|
||||
- return x
|
||||
-# fmt: off
|
||||
-elif unformatted:
|
||||
- # fmt: on
|
||||
- will_be_formatted()
|
||||
+# fmt: on
|
||||
+ will_be_formatted ()
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Regression test for https://github.com/psf/black/issues/3129.
|
||||
setup(
|
||||
entry_points={
|
||||
# fmt: off
|
||||
"console_scripts": [
|
||||
"foo-bar"
|
||||
"=foo.bar.:main",
|
||||
# fmt: on
|
||||
] # Includes an formatted indentation.
|
||||
},
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2015.
|
||||
run(
|
||||
# fmt: off
|
||||
[
|
||||
"ls",
|
||||
"-la",
|
||||
]
|
||||
# fmt: on
|
||||
+ path,
|
||||
check=True,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3026.
|
||||
def test_func():
|
||||
# yapf: disable
|
||||
if unformatted( args ):
|
||||
return True
|
||||
# yapf: enable
|
||||
elif b:
|
||||
return True
|
||||
|
||||
return False
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2567.
|
||||
if True:
|
||||
# fmt: off
|
||||
for _ in range( 1 ):
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
print ( "This won't be formatted either" )
|
||||
else:
|
||||
print ( "This will be formatted" )
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3184.
|
||||
class A:
|
||||
async def call(param):
|
||||
if param:
|
||||
# fmt: off
|
||||
if param[0:4] in (
|
||||
"ABCD", "EFGH"
|
||||
) :
|
||||
# fmt: on
|
||||
print ( "This won't be formatted" )
|
||||
|
||||
elif param[0:4] in ("ZZZZ",):
|
||||
print ( "This won't be formatted either" )
|
||||
|
||||
print ( "This will be formatted" )
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/2985.
|
||||
class Named(t.Protocol):
|
||||
# fmt: off
|
||||
@property
|
||||
def this_wont_be_formatted ( self ) -> str: ...
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class Factory(t.Protocol):
|
||||
def this_will_be_formatted ( self, **kwargs ) -> Named: ...
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3436.
|
||||
if x:
|
||||
return x
|
||||
# fmt: off
|
||||
elif unformatted:
|
||||
# fmt: on
|
||||
will_be_formatted ()
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -199,58 +199,60 @@ d={'a':1,
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,17 +4,18 @@
|
||||
@@ -1,224 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
-import asyncio
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from third_party import X, Y, Z
|
||||
-from third_party import X, Y, Z
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from library import some_connection, some_decorator
|
||||
-
|
||||
+from library import some_connection, \
|
||||
+ some_decorator
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: off
|
||||
from third_party import (X,
|
||||
Y, Z)
|
||||
-from third_party import (X,
|
||||
- Y, Z)
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: on
|
||||
-f"trigger 3.6 mode"
|
||||
+f'trigger 3.6 mode'
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+
|
||||
+
|
||||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
-
|
||||
|
||||
-
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
@@ -26,11 +27,15 @@
|
||||
continue
|
||||
exec('new-style exec', {}, {})
|
||||
return None
|
||||
+
|
||||
+
|
||||
async def coroutine(arg, exec=False):
|
||||
'Single-line docstring. Multiline is harder to reformat.'
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
+
|
||||
+
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
@@ -38,28 +43,19 @@
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
+
|
||||
+
|
||||
# fmt: on
|
||||
-def func_no_args():
|
||||
- a; b; c
|
||||
- if True: raise RuntimeError
|
||||
- if False: ...
|
||||
- for i in range(10):
|
||||
- print(i)
|
||||
- continue
|
||||
- exec('new-style exec', {}, {})
|
||||
- return None
|
||||
-async def coroutine(arg, exec=False):
|
||||
- 'Single-line docstring. Multiline is harder to reformat.'
|
||||
- async with some_connection() as conn:
|
||||
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
- await asyncio.sleep(1)
|
||||
-@asyncio.coroutine
|
||||
-@some_decorator(
|
||||
-with_args=True,
|
||||
-many_args=[1,2,3]
|
||||
-)
|
||||
-def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
- return text[number:-1]
|
||||
-# fmt: on
|
||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
|
||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
+def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
+ offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2)))
|
||||
+ assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def spaces_types(
|
||||
|
@ -265,115 +267,162 @@ d={'a':1,
|
|||
- i: str = r"",
|
||||
-):
|
||||
- ...
|
||||
+def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-def spaces2(result=_core.Value(None)):
|
||||
- ...
|
||||
+def spaces2(result= _core.Value(None)):
|
||||
+ ...
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
something = {
|
||||
@@ -74,23 +70,20 @@
|
||||
'some big and',
|
||||
'complex subscript',
|
||||
# fmt: on
|
||||
-something = {
|
||||
- # fmt: off
|
||||
- key: 'value',
|
||||
-}
|
||||
+# fmt: on
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def subscriptlist():
|
||||
- atom[
|
||||
- # fmt: off
|
||||
- 'some big and',
|
||||
- 'complex subscript',
|
||||
- # fmt: on
|
||||
- goes + here,
|
||||
- andhere,
|
||||
- ]
|
||||
+ goes + here, andhere,
|
||||
+ ]
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
from hello import a, b
|
||||
'unformatted'
|
||||
-def import_as_names():
|
||||
- # fmt: off
|
||||
- from hello import a, b
|
||||
- 'unformatted'
|
||||
- # fmt: on
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
a , b = *hello
|
||||
'unformatted'
|
||||
-def testlist_star_expr():
|
||||
- # fmt: off
|
||||
- a , b = *hello
|
||||
- 'unformatted'
|
||||
- # fmt: on
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
def yield_expr():
|
||||
@@ -98,11 +91,10 @@
|
||||
yield hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
-def yield_expr():
|
||||
- # fmt: off
|
||||
- yield hello
|
||||
- 'unformatted'
|
||||
- # fmt: on
|
||||
- "formatted"
|
||||
+ 'formatted'
|
||||
# fmt: off
|
||||
( yield hello )
|
||||
'unformatted'
|
||||
- # fmt: off
|
||||
- ( yield hello )
|
||||
- 'unformatted'
|
||||
- # fmt: on
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example(session):
|
||||
@@ -113,7 +105,6 @@
|
||||
models.Customer.email == email_address)\
|
||||
.order_by(models.Customer.id.asc())\
|
||||
.all()
|
||||
-def example(session):
|
||||
- # fmt: off
|
||||
- result = session\
|
||||
- .query(models.Customer.id)\
|
||||
- .filter(models.Customer.account_id == account_id,
|
||||
- models.Customer.email == email_address)\
|
||||
- .order_by(models.Customer.id.asc())\
|
||||
- .all()
|
||||
- # fmt: on
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def off_and_on_without_data():
|
||||
@@ -123,8 +114,10 @@
|
||||
"""
|
||||
# fmt: off
|
||||
-def off_and_on_without_data():
|
||||
- """All comments here are technically on the same prefix.
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- The comments between will be formatted. This is a known limitation.
|
||||
- """
|
||||
- # fmt: off
|
||||
|
||||
- # hey, that won't work
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
+ #hey, that won't work
|
||||
+
|
||||
+
|
||||
# fmt: on
|
||||
pass
|
||||
- # fmt: on
|
||||
- pass
|
||||
|
||||
@@ -137,21 +130,12 @@
|
||||
and_=indeed . it is not formatted
|
||||
because . the . handling . inside . generate_ignored_nodes()
|
||||
now . considers . multiple . fmt . directives . within . one . prefix
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def on_and_off_broken():
|
||||
- """Another known limitation."""
|
||||
- # fmt: on
|
||||
- # fmt: off
|
||||
- this=should.not_be.formatted()
|
||||
- and_=indeed . it is not formatted
|
||||
- because . the . handling . inside . generate_ignored_nodes()
|
||||
- now . considers . multiple . fmt . directives . within . one . prefix
|
||||
- # fmt: on
|
||||
- # fmt: off
|
||||
- # ...but comments still get reformatted even though they should not be
|
||||
- # fmt: on
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
-def long_lines():
|
||||
- if True:
|
||||
- typedargslist.extend(
|
||||
- gen_annotated_params(
|
||||
- ast_args.kwonlyargs,
|
||||
- ast_args.kw_defaults,
|
||||
- parameters,
|
||||
- implicit_default=True,
|
||||
- )
|
||||
+ gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
||||
)
|
||||
# fmt: off
|
||||
a = (
|
||||
@@ -186,20 +170,19 @@
|
||||
- )
|
||||
- # fmt: off
|
||||
- a = (
|
||||
- unnecessary_bracket()
|
||||
- )
|
||||
- # fmt: on
|
||||
- _type_comment_re = re.compile(
|
||||
- r"""
|
||||
- ^
|
||||
- [\t ]*
|
||||
- \#[ ]type:[ ]*
|
||||
- (?P<type>
|
||||
- [^#\t\n]+?
|
||||
- )
|
||||
- (?<!ignore) # note: this will force the non-greedy + in <type> to match
|
||||
- # a trailing space which is why we need the silliness below
|
||||
- (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
|
||||
- (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
|
||||
- (?<!ignore[ ]{9})(?<!ignore[ ]{10})
|
||||
- [\t ]*
|
||||
- (?P<nl>
|
||||
- (?:\#[^\n]*)?
|
||||
- \n?
|
||||
- )
|
||||
- $
|
||||
- """,
|
||||
- # fmt: off
|
||||
- re.MULTILINE|re.VERBOSE
|
||||
- # fmt: on
|
||||
- )
|
||||
|
||||
def single_literal_yapf_disable():
|
||||
"""Black does not support this."""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def single_literal_yapf_disable():
|
||||
- """Black does not support this."""
|
||||
- BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||
+ BAZ = {
|
||||
+ (1, 2, 3, 4),
|
||||
+ (5, 6, 7, 8),
|
||||
+ (9, 10, 11, 12)
|
||||
+ }
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
+
|
||||
+
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
+
|
||||
|
||||
cfg.rule(
|
||||
-cfg.rule(
|
||||
- "Default",
|
||||
- "address",
|
||||
+ "Default", "address",
|
||||
xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
|
||||
- xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
|
||||
- xxxxxx="xx_xxxxx",
|
||||
- xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
- xxxxxxxxx_xxxx=True,
|
||||
|
@ -381,39 +430,48 @@ d={'a':1,
|
|||
- xxxxxx_xxxxxx=2,
|
||||
- xxxxxx_xxxxx_xxxxxxxx=70,
|
||||
- xxxxxx_xxxxxx_xxxxx=True,
|
||||
+ xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
+ xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False,
|
||||
+ xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True,
|
||||
# fmt: off
|
||||
xxxxxxx_xxxxxxxxxxxx={
|
||||
"xxxxxxxx": {
|
||||
@@ -214,7 +197,7 @@
|
||||
},
|
||||
},
|
||||
# fmt: on
|
||||
- # fmt: off
|
||||
- xxxxxxx_xxxxxxxxxxxx={
|
||||
- "xxxxxxxx": {
|
||||
- "xxxxxx": False,
|
||||
- "xxxxxxx": False,
|
||||
- "xxxx_xxxxxx": "xxxxx",
|
||||
- },
|
||||
- "xxxxxxxx-xxxxx": {
|
||||
- "xxxxxx": False,
|
||||
- "xxxxxxx": True,
|
||||
- "xxxx_xxxxxx": "xxxxxx",
|
||||
- },
|
||||
- },
|
||||
- # fmt: on
|
||||
- xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
|
||||
+ xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
|
||||
)
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
# fmt: off
|
||||
yield 'hello'
|
||||
-yield 'hello'
|
||||
+NOT_YET_IMPLEMENTED_ExprYield
|
||||
# No formatting to the end of the file
|
||||
-l=[1,2,3]
|
||||
-d={'a':1,
|
||||
- 'b':2}
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from third_party import X, Y, Z
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from library import some_connection, \
|
||||
some_decorator
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: off
|
||||
from third_party import (X,
|
||||
Y, Z)
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
# fmt: on
|
||||
f'trigger 3.6 mode'
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
# Comment 1
|
||||
|
@ -421,193 +479,61 @@ f'trigger 3.6 mode'
|
|||
# Comment 2
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
a; b; c
|
||||
if True: raise RuntimeError
|
||||
if False: ...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec('new-style exec', {}, {})
|
||||
return None
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
'Single-line docstring. Multiline is harder to reformat.'
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
many_args=[1,2,3]
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# fmt: on
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2)))
|
||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def spaces2(result= _core.Value(None)):
|
||||
...
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
something = {
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
# fmt: off
|
||||
key: 'value',
|
||||
}
|
||||
|
||||
|
||||
def subscriptlist():
|
||||
atom[
|
||||
# fmt: off
|
||||
'some big and',
|
||||
'complex subscript',
|
||||
# fmt: on
|
||||
goes + here, andhere,
|
||||
]
|
||||
|
||||
|
||||
def import_as_names():
|
||||
# fmt: off
|
||||
from hello import a, b
|
||||
'unformatted'
|
||||
|
||||
|
||||
def testlist_star_expr():
|
||||
# fmt: off
|
||||
a , b = *hello
|
||||
'unformatted'
|
||||
|
||||
|
||||
def yield_expr():
|
||||
# fmt: off
|
||||
yield hello
|
||||
'unformatted'
|
||||
# fmt: on
|
||||
'formatted'
|
||||
# fmt: off
|
||||
( yield hello )
|
||||
'unformatted'
|
||||
|
||||
|
||||
def example(session):
|
||||
# fmt: off
|
||||
result = session\
|
||||
.query(models.Customer.id)\
|
||||
.filter(models.Customer.account_id == account_id,
|
||||
models.Customer.email == email_address)\
|
||||
.order_by(models.Customer.id.asc())\
|
||||
.all()
|
||||
|
||||
|
||||
def off_and_on_without_data():
|
||||
"""All comments here are technically on the same prefix.
|
||||
|
||||
The comments between will be formatted. This is a known limitation.
|
||||
"""
|
||||
# fmt: off
|
||||
|
||||
|
||||
#hey, that won't work
|
||||
|
||||
|
||||
# fmt: on
|
||||
pass
|
||||
|
||||
|
||||
def on_and_off_broken():
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
this=should.not_be.formatted()
|
||||
and_=indeed . it is not formatted
|
||||
because . the . handling . inside . generate_ignored_nodes()
|
||||
now . considers . multiple . fmt . directives . within . one . prefix
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
||||
)
|
||||
# fmt: off
|
||||
a = (
|
||||
unnecessary_bracket()
|
||||
)
|
||||
# fmt: on
|
||||
_type_comment_re = re.compile(
|
||||
r"""
|
||||
^
|
||||
[\t ]*
|
||||
\#[ ]type:[ ]*
|
||||
(?P<type>
|
||||
[^#\t\n]+?
|
||||
)
|
||||
(?<!ignore) # note: this will force the non-greedy + in <type> to match
|
||||
# a trailing space which is why we need the silliness below
|
||||
(?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
|
||||
(?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
|
||||
(?<!ignore[ ]{9})(?<!ignore[ ]{10})
|
||||
[\t ]*
|
||||
(?P<nl>
|
||||
(?:\#[^\n]*)?
|
||||
\n?
|
||||
)
|
||||
$
|
||||
""",
|
||||
# fmt: off
|
||||
re.MULTILINE|re.VERBOSE
|
||||
# fmt: on
|
||||
)
|
||||
|
||||
|
||||
def single_literal_yapf_disable():
|
||||
"""Black does not support this."""
|
||||
BAZ = {
|
||||
(1, 2, 3, 4),
|
||||
(5, 6, 7, 8),
|
||||
(9, 10, 11, 12)
|
||||
}
|
||||
|
||||
|
||||
cfg.rule(
|
||||
"Default", "address",
|
||||
xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
|
||||
xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False,
|
||||
xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True,
|
||||
# fmt: off
|
||||
xxxxxxx_xxxxxxxxxxxx={
|
||||
"xxxxxxxx": {
|
||||
"xxxxxx": False,
|
||||
"xxxxxxx": False,
|
||||
"xxxx_xxxxxx": "xxxxx",
|
||||
},
|
||||
"xxxxxxxx-xxxxx": {
|
||||
"xxxxxx": False,
|
||||
"xxxxxxx": True,
|
||||
"xxxx_xxxxxx": "xxxxxx",
|
||||
},
|
||||
},
|
||||
# fmt: on
|
||||
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
|
||||
)
|
||||
# fmt: off
|
||||
yield 'hello'
|
||||
NOT_YET_IMPLEMENTED_ExprYield
|
||||
# No formatting to the end of the file
|
||||
l=[1,2,3]
|
||||
d={'a':1,
|
||||
'b':2}
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -22,22 +22,23 @@ l3 = ["I have", "trailing comma", "so I should be braked",]
|
|||
- "into multiple lines",
|
||||
- "because it is way too long",
|
||||
-]
|
||||
+l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
-l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
-l3 = [
|
||||
- "I have",
|
||||
- "trailing comma",
|
||||
- "so I should be braked",
|
||||
-]
|
||||
+l3 = ["I have", "trailing comma", "so I should be braked",]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
l3 = ["I have", "trailing comma", "so I should be braked",]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -22,29 +22,32 @@ f = ["This is a very long line that should be formatted into a clearer line ", "
|
|||
+++ Ruff
|
||||
@@ -1,10 +1,7 @@
|
||||
-a = 3
|
||||
+a = 3
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: off
|
||||
b, c = 1, 2
|
||||
d = 6 # fmt: skip
|
||||
e = 5
|
||||
-b, c = 1, 2
|
||||
-d = 6 # fmt: skip
|
||||
-e = 5
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
-f = [
|
||||
- "This is a very long line that should be formatted into a clearer line ",
|
||||
- "by rearranging.",
|
||||
-]
|
||||
+f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = 3
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: off
|
||||
b, c = 1, 2
|
||||
d = 6 # fmt: skip
|
||||
e = 5
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: on
|
||||
f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -18,22 +18,22 @@ l = [1, 2, 3,]
|
|||
+++ Ruff
|
||||
@@ -1,7 +1,3 @@
|
||||
-a = 2
|
||||
+a = 2
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: skip
|
||||
-l = [
|
||||
- 1,
|
||||
- 2,
|
||||
- 3,
|
||||
-]
|
||||
+l = [1, 2, 3,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = 2
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
# fmt: skip
|
||||
l = [1, 2, 3,]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -22,29 +22,25 @@ else:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,6 @@
|
||||
@@ -1,9 +1,2 @@
|
||||
-a, b, c = 3, 4, 5
|
||||
+a, b, c = 3, 4, 5
|
||||
if (
|
||||
-if (
|
||||
- a == 3
|
||||
+ a == 3
|
||||
and b != 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
- and b != 9 # fmt: skip
|
||||
- and c is not None
|
||||
-):
|
||||
- print("I'm good!")
|
||||
-else:
|
||||
- print("I'm bad")
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a, b, c = 3, 4, 5
|
||||
if (
|
||||
a == 3
|
||||
and b != 9 # fmt: skip
|
||||
and c is not None
|
||||
):
|
||||
print("I'm good!")
|
||||
else:
|
||||
print("I'm bad")
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -18,22 +18,19 @@ class A:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,4 +2,4 @@
|
||||
def f(self):
|
||||
for line in range(10):
|
||||
if True:
|
||||
@@ -1,5 +1 @@
|
||||
-class A:
|
||||
- def f(self):
|
||||
- for line in range(10):
|
||||
- if True:
|
||||
- pass # fmt: skip
|
||||
+ pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
class A:
|
||||
def f(self):
|
||||
for line in range(10):
|
||||
if True:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -19,19 +19,22 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu
|
|||
+++ Ruff
|
||||
@@ -1,4 +1,4 @@
|
||||
-a = "this is some code"
|
||||
+a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
-b = 5 # fmt:skip
|
||||
-c = 9 # fmt: skip
|
||||
-d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt:skip
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -75,108 +75,118 @@ async def test_async_with():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,7 +2,6 @@
|
||||
def some_func( unformatted, args ): # fmt: skip
|
||||
print("I am some_func")
|
||||
return 0
|
||||
@@ -1,62 +1,33 @@
|
||||
# Make sure a leading comment is not removed.
|
||||
-def some_func( unformatted, args ): # fmt: skip
|
||||
- print("I am some_func")
|
||||
- return 0
|
||||
- # Make sure this comment is not removed.
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
@@ -29,15 +28,15 @@
|
||||
elif another_unformatted_call( args ): # fmt: skip
|
||||
print("Second branch")
|
||||
else : # fmt: skip
|
||||
-async def some_async_func( unformatted, args): # fmt: skip
|
||||
- print("I am some_async_func")
|
||||
- await asyncio.sleep(1)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
-class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
||||
- def some_method( self, unformatted, args ): # fmt: skip
|
||||
- print("I am some_method")
|
||||
- return 0
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
- async def some_async_method( self, unformatted, args ): # fmt: skip
|
||||
- print("I am some_async_method")
|
||||
- await asyncio.sleep(1)
|
||||
|
||||
-
|
||||
# Make sure a leading comment is not removed.
|
||||
-if unformatted_call( args ): # fmt: skip
|
||||
- print("First branch")
|
||||
- # Make sure this is not removed.
|
||||
-elif another_unformatted_call( args ): # fmt: skip
|
||||
- print("Second branch")
|
||||
-else : # fmt: skip
|
||||
- print("Last branch")
|
||||
+ print("Last branch") # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtIf # fmt: skip
|
||||
|
||||
|
||||
-while some_condition( unformatted, args ): # fmt: skip
|
||||
+while some_condition( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
|
||||
|
||||
for i in some_iter( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+ print("Do something") # fmt: skip
|
||||
+while NOT_YET_IMPLEMENTED_ExprCall: # fmt: skip
|
||||
+ NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
@@ -54,7 +53,7 @@
|
||||
|
||||
|
||||
with give_me_context( unformatted, args ): # fmt: skip
|
||||
-for i in some_iter( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+ print("Do something") # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
-async def test_async_for():
|
||||
- async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-try : # fmt: skip
|
||||
- some_call()
|
||||
-except UnformattedError as ex: # fmt: skip
|
||||
- handle_exception()
|
||||
-finally : # fmt: skip
|
||||
- finally_call()
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
-with give_me_context( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||
|
||||
|
||||
-async def test_async_with():
|
||||
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Make sure a leading comment is not removed.
|
||||
def some_func( unformatted, args ): # fmt: skip
|
||||
print("I am some_func")
|
||||
return 0
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
async def some_async_func( unformatted, args): # fmt: skip
|
||||
print("I am some_async_func")
|
||||
await asyncio.sleep(1)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
||||
def some_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_method")
|
||||
return 0
|
||||
|
||||
async def some_async_method( self, unformatted, args ): # fmt: skip
|
||||
print("I am some_async_method")
|
||||
await asyncio.sleep(1)
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
# Make sure a leading comment is not removed.
|
||||
if unformatted_call( args ): # fmt: skip
|
||||
print("First branch")
|
||||
# Make sure this is not removed.
|
||||
elif another_unformatted_call( args ): # fmt: skip
|
||||
print("Second branch")
|
||||
else : # fmt: skip
|
||||
print("Last branch") # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtIf # fmt: skip
|
||||
|
||||
|
||||
while some_condition( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
while NOT_YET_IMPLEMENTED_ExprCall: # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
for i in some_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something") # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtFor # fmt: skip
|
||||
|
||||
|
||||
async def test_async_for():
|
||||
async for i in some_async_iter( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
try : # fmt: skip
|
||||
some_call()
|
||||
except UnformattedError as ex: # fmt: skip
|
||||
handle_exception()
|
||||
finally : # fmt: skip
|
||||
finally_call()
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
|
||||
with give_me_context( unformatted, args ): # fmt: skip
|
||||
print("Do something") # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtWith # fmt: skip
|
||||
|
||||
|
||||
async def test_async_with():
|
||||
async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
print("Do something")
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/src/lib.rs
|
||||
expression: snapshot
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,3 +1,3 @@
|
||||
-a, b = 1, 2
|
||||
-c = 6 # fmt: skip
|
||||
-d = 5
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign # fmt: skip
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
|
|
@ -22,28 +22,39 @@ f'Hello \'{tricky + "example"}\''
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,6 +1,6 @@
|
||||
f"f-string without formatted values is just a string"
|
||||
f"{{NOT a formatted value}}"
|
||||
@@ -1,9 +1,9 @@
|
||||
-f"f-string without formatted values is just a string"
|
||||
-f"{{NOT a formatted value}}"
|
||||
-f'{{NOT \'a\' "formatted" "value"}}'
|
||||
+f"{{NOT 'a' \"formatted\" \"value\"}}"
|
||||
f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
f"{f'''{'nested'} inner'''} outer"
|
||||
-f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
-f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
-f"{f'''{'nested'} inner'''} outer"
|
||||
-f"\"{f'{nested} inner'}\" outer"
|
||||
-f"space between opening braces: { {a for a in (1, 2, 3)}}"
|
||||
-f'Hello \'{tricky + "example"}\''
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
f"f-string without formatted values is just a string"
|
||||
f"{{NOT a formatted value}}"
|
||||
f"{{NOT 'a' \"formatted\" \"value\"}}"
|
||||
f"some f-string with {a} {few():.2f} {formatted.values!r}"
|
||||
f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
|
||||
f"{f'''{'nested'} inner'''} outer"
|
||||
f"\"{f'{nested} inner'}\" outer"
|
||||
f"space between opening braces: { {a for a in (1, 2, 3)}}"
|
||||
f'Hello \'{tricky + "example"}\''
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -66,128 +66,94 @@ with hmm_but_this_should_get_two_preceding_newlines():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,11 +1,11 @@
|
||||
def f(
|
||||
@@ -1,65 +1,12 @@
|
||||
-def f(
|
||||
- a,
|
||||
- **kwargs,
|
||||
+ a,
|
||||
+ **kwargs,
|
||||
) -> A:
|
||||
with cache_dir():
|
||||
if something:
|
||||
-) -> A:
|
||||
- with cache_dir():
|
||||
- if something:
|
||||
- result = CliRunner().invoke(
|
||||
- black.main, [str(src1), str(src2), "--diff", "--check"]
|
||||
+ result = (
|
||||
+ CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"])
|
||||
)
|
||||
limited.append(-limited.pop()) # negate top
|
||||
return A(
|
||||
@@ -17,30 +17,24 @@
|
||||
|
||||
def g():
|
||||
"Docstring."
|
||||
- )
|
||||
- limited.append(-limited.pop()) # negate top
|
||||
- return A(
|
||||
- very_long_argument_name1=very_long_value_for_the_argument,
|
||||
- very_long_argument_name2=-very.long.value.for_the_argument,
|
||||
- **kwargs,
|
||||
- )
|
||||
-
|
||||
def inner():
|
||||
pass
|
||||
-
|
||||
print("Inner defs should breathe a little.")
|
||||
|
||||
|
||||
def h():
|
||||
def inner():
|
||||
pass
|
||||
-def g():
|
||||
- "Docstring."
|
||||
-
|
||||
print("Inner defs should breathe a little.")
|
||||
|
||||
|
||||
if os.name == "posix":
|
||||
import termios
|
||||
- def inner():
|
||||
- pass
|
||||
-
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
- print("Inner defs should breathe a little.")
|
||||
-
|
||||
elif os.name == "nt":
|
||||
try:
|
||||
import msvcrt
|
||||
-
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
-def h():
|
||||
- def inner():
|
||||
- pass
|
||||
-
|
||||
- print("Inner defs should breathe a little.")
|
||||
-
|
||||
-
|
||||
-if os.name == "posix":
|
||||
- import termios
|
||||
-
|
||||
- def i_should_be_followed_by_only_one_newline():
|
||||
- pass
|
||||
-
|
||||
-elif os.name == "nt":
|
||||
- try:
|
||||
- import msvcrt
|
||||
-
|
||||
- def i_should_be_followed_by_only_one_newline():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
@@ -54,12 +48,10 @@
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
print("i_should_be_followed_by_only_one_newline")
|
||||
-
|
||||
else:
|
||||
- except ImportError:
|
||||
|
||||
def foo():
|
||||
pass
|
||||
- def i_should_be_followed_by_only_one_newline():
|
||||
- pass
|
||||
-
|
||||
-elif False:
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
with hmm_but_this_should_get_two_preceding_newlines():
|
||||
pass
|
||||
- class IHopeYouAreHavingALovelyDay:
|
||||
- def __call__(self):
|
||||
- print("i_should_be_followed_by_only_one_newline")
|
||||
|
||||
-else:
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
- def foo():
|
||||
- pass
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
-with hmm_but_this_should_get_two_preceding_newlines():
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
with cache_dir():
|
||||
if something:
|
||||
result = (
|
||||
CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"])
|
||||
)
|
||||
limited.append(-limited.pop()) # negate top
|
||||
return A(
|
||||
very_long_argument_name1=very_long_value_for_the_argument,
|
||||
very_long_argument_name2=-very.long.value.for_the_argument,
|
||||
**kwargs,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def g():
|
||||
"Docstring."
|
||||
def inner():
|
||||
pass
|
||||
print("Inner defs should breathe a little.")
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def h():
|
||||
def inner():
|
||||
pass
|
||||
print("Inner defs should breathe a little.")
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
if os.name == "posix":
|
||||
import termios
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
elif os.name == "nt":
|
||||
try:
|
||||
import msvcrt
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
except ImportError:
|
||||
|
||||
def i_should_be_followed_by_only_one_newline():
|
||||
pass
|
||||
|
||||
elif False:
|
||||
|
||||
class IHopeYouAreHavingALovelyDay:
|
||||
def __call__(self):
|
||||
print("i_should_be_followed_by_only_one_newline")
|
||||
else:
|
||||
|
||||
def foo():
|
||||
pass
|
||||
|
||||
with hmm_but_this_should_get_two_preceding_newlines():
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -108,19 +108,24 @@ def __await__(): return (yield)
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,97 +4,67 @@
|
||||
@@ -1,148 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
-import asyncio
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from third_party import X, Y, Z
|
||||
-from third_party import X, Y, Z
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from library import some_connection, some_decorator
|
||||
+from library import some_connection, \
|
||||
+ some_decorator
|
||||
+f'trigger 3.6 mode'
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
-f"trigger 3.6 mode"
|
||||
-
|
||||
|
||||
def func_no_args():
|
||||
-def func_no_args():
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
|
@ -133,28 +138,18 @@ def __await__(): return (yield)
|
|||
- continue
|
||||
- exec("new-style exec", {}, {})
|
||||
- return None
|
||||
+ a; b; c
|
||||
+ if True: raise RuntimeError
|
||||
+ if False: ...
|
||||
+ for i in range(10):
|
||||
+ print(i)
|
||||
+ continue
|
||||
+ exec("new-style exec", {}, {})
|
||||
+ return None
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
-async def coroutine(arg, exec=False):
|
||||
- "Single-line docstring. Multiline is harder to reformat."
|
||||
- async with some_connection() as conn:
|
||||
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
- await asyncio.sleep(1)
|
||||
+ "Single-line docstring. Multiline is harder to reformat."
|
||||
+ async with some_connection() as conn:
|
||||
+ await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
+ await asyncio.sleep(1)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
-@asyncio.coroutine
|
||||
-@some_decorator(with_args=True, many_args=[1, 2, 3])
|
||||
-def function_signature_stress_test(
|
||||
- number: int,
|
||||
|
@ -165,20 +160,13 @@ def __await__(): return (yield)
|
|||
- **kwargs,
|
||||
-) -> str:
|
||||
- return text[number:-1]
|
||||
+@some_decorator(
|
||||
+with_args=True,
|
||||
+many_args=[1,2,3]
|
||||
+)
|
||||
+def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str:
|
||||
+ return text[number:-1]
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||
- offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
||||
- assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||
+def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
+ offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
|
||||
+ assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def spaces_types(
|
||||
|
@ -193,16 +181,15 @@ def __await__(): return (yield)
|
|||
- i: str = r"",
|
||||
-):
|
||||
- ...
|
||||
+def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def spaces2(result=_core.Value(None)):
|
||||
- assert fut is self._read_fut, (fut, self._read_fut)
|
||||
+def spaces2(result= _core.Value(None)):
|
||||
+ assert fut is self._read_fut, (fut, self._read_fut)
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example(session):
|
||||
-def example(session):
|
||||
- result = (
|
||||
- session.query(models.Customer.id)
|
||||
- .filter(
|
||||
|
@ -212,195 +199,126 @@ def __await__(): return (yield)
|
|||
- .order_by(models.Customer.id.asc())
|
||||
- .all()
|
||||
- )
|
||||
+ result = session.query(models.Customer.id).filter(
|
||||
+ models.Customer.account_id == account_id,
|
||||
+ models.Customer.email == email_address,
|
||||
+ ).order_by(
|
||||
+ models.Customer.id.asc()
|
||||
+ ).all()
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
-def long_lines():
|
||||
- if True:
|
||||
- typedargslist.extend(
|
||||
- gen_annotated_params(
|
||||
- ast_args.kwonlyargs,
|
||||
- ast_args.kw_defaults,
|
||||
- parameters,
|
||||
- implicit_default=True,
|
||||
- )
|
||||
+ gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
||||
)
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(
|
||||
- )
|
||||
- typedargslist.extend(
|
||||
- gen_annotated_params(
|
||||
- ast_args.kwonlyargs,
|
||||
- ast_args.kw_defaults,
|
||||
- parameters,
|
||||
- implicit_default=True,
|
||||
+ ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True,
|
||||
# trailing standalone comment
|
||||
)
|
||||
)
|
||||
@@ -117,23 +87,22 @@
|
||||
\n?
|
||||
)
|
||||
$
|
||||
- # trailing standalone comment
|
||||
- )
|
||||
- )
|
||||
- _type_comment_re = re.compile(
|
||||
- r"""
|
||||
- ^
|
||||
- [\t ]*
|
||||
- \#[ ]type:[ ]*
|
||||
- (?P<type>
|
||||
- [^#\t\n]+?
|
||||
- )
|
||||
- (?<!ignore) # note: this will force the non-greedy + in <type> to match
|
||||
- # a trailing space which is why we need the silliness below
|
||||
- (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
|
||||
- (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
|
||||
- (?<!ignore[ ]{9})(?<!ignore[ ]{10})
|
||||
- [\t ]*
|
||||
- (?P<nl>
|
||||
- (?:\#[^\n]*)?
|
||||
- \n?
|
||||
- )
|
||||
- $
|
||||
- """,
|
||||
- re.MULTILINE | re.VERBOSE,
|
||||
+ """, re.MULTILINE | re.VERBOSE
|
||||
)
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def trailing_comma():
|
||||
mapping = {
|
||||
-def trailing_comma():
|
||||
- mapping = {
|
||||
- A: 0.25 * (10.0 / 12),
|
||||
- B: 0.1 * (10.0 / 12),
|
||||
- C: 0.1 * (10.0 / 12),
|
||||
- D: 0.1 * (10.0 / 12),
|
||||
- }
|
||||
+ A: 0.25 * (10.0 / 12),
|
||||
+ B: 0.1 * (10.0 / 12),
|
||||
+ C: 0.1 * (10.0 / 12),
|
||||
+ D: 0.1 * (10.0 / 12),
|
||||
+}
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def f(
|
||||
-def f(
|
||||
- a,
|
||||
- **kwargs,
|
||||
+ a,
|
||||
+ **kwargs,
|
||||
) -> A:
|
||||
return (
|
||||
yield from A(
|
||||
@@ -144,5 +113,4 @@
|
||||
)
|
||||
-) -> A:
|
||||
- return (
|
||||
- yield from A(
|
||||
- very_long_argument_name1=very_long_value_for_the_argument,
|
||||
- very_long_argument_name2=very_long_value_for_the_argument,
|
||||
- **kwargs,
|
||||
- )
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def __await__():
|
||||
- return (yield)
|
||||
+def __await__(): return (yield)
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import sys
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from third_party import X, Y, Z
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from library import some_connection, \
|
||||
some_decorator
|
||||
f'trigger 3.6 mode'
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def func_no_args():
|
||||
a; b; c
|
||||
if True: raise RuntimeError
|
||||
if False: ...
|
||||
for i in range(10):
|
||||
print(i)
|
||||
continue
|
||||
exec("new-style exec", {}, {})
|
||||
return None
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
@some_decorator(
|
||||
with_args=True,
|
||||
many_args=[1,2,3]
|
||||
)
|
||||
def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str:
|
||||
return text[number:-1]
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
||||
offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
|
||||
assert task._cancel_stack[:len(old_stack)] == old_stack
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def spaces2(result= _core.Value(None)):
|
||||
assert fut is self._read_fut, (fut, self._read_fut)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example(session):
|
||||
result = session.query(models.Customer.id).filter(
|
||||
models.Customer.account_id == account_id,
|
||||
models.Customer.email == email_address,
|
||||
).order_by(
|
||||
models.Customer.id.asc()
|
||||
).all()
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def long_lines():
|
||||
if True:
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
||||
)
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(
|
||||
ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True,
|
||||
# trailing standalone comment
|
||||
)
|
||||
)
|
||||
_type_comment_re = re.compile(
|
||||
r"""
|
||||
^
|
||||
[\t ]*
|
||||
\#[ ]type:[ ]*
|
||||
(?P<type>
|
||||
[^#\t\n]+?
|
||||
)
|
||||
(?<!ignore) # note: this will force the non-greedy + in <type> to match
|
||||
# a trailing space which is why we need the silliness below
|
||||
(?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
|
||||
(?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
|
||||
(?<!ignore[ ]{9})(?<!ignore[ ]{10})
|
||||
[\t ]*
|
||||
(?P<nl>
|
||||
(?:\#[^\n]*)?
|
||||
\n?
|
||||
)
|
||||
$
|
||||
""", re.MULTILINE | re.VERBOSE
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def trailing_comma():
|
||||
mapping = {
|
||||
A: 0.25 * (10.0 / 12),
|
||||
B: 0.1 * (10.0 / 12),
|
||||
C: 0.1 * (10.0 / 12),
|
||||
D: 0.1 * (10.0 / 12),
|
||||
}
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def f(
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
return (
|
||||
yield from A(
|
||||
very_long_argument_name1=very_long_value_for_the_argument,
|
||||
very_long_argument_name2=very_long_value_for_the_argument,
|
||||
**kwargs,
|
||||
)
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def __await__(): return (yield)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -74,16 +74,15 @@ some_module.some_function(
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,69 +1,28 @@
|
||||
@@ -1,114 +1,31 @@
|
||||
-def f(
|
||||
- a,
|
||||
-):
|
||||
- d = {
|
||||
- "key": "value",
|
||||
- }
|
||||
+def f(a,):
|
||||
+ d = {'key': 'value',}
|
||||
tup = (1,)
|
||||
- tup = (1,)
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def f2(
|
||||
|
@ -98,9 +97,7 @@ some_module.some_function(
|
|||
- 1,
|
||||
- 2,
|
||||
- )
|
||||
+def f2(a,b,):
|
||||
+ d = {'key': 'value', 'key2': 'value2',}
|
||||
+ tup = (1,2,)
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def f(
|
||||
|
@ -114,13 +111,10 @@ some_module.some_function(
|
|||
- call2(
|
||||
- arg=[1, 2, 3],
|
||||
- )
|
||||
+def f(a:int=1,):
|
||||
+ call(arg={'explode': 'this',})
|
||||
+ call2(arg=[1,2,3],)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}["a"]
|
||||
- x = {
|
||||
- "a": 1,
|
||||
- "b": 2,
|
||||
- }["a"]
|
||||
- if (
|
||||
- a
|
||||
- == {
|
||||
|
@ -134,8 +128,8 @@ some_module.some_function(
|
|||
- "h": 8,
|
||||
- }["a"]
|
||||
- ):
|
||||
+ if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]:
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||
|
@ -150,48 +144,51 @@ some_module.some_function(
|
|||
- }
|
||||
- }
|
||||
- }
|
||||
+def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
+]:
|
||||
+ json = {"k": {"k2": {"k3": [1,]}}}
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
@@ -74,24 +33,21 @@
|
||||
pass
|
||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||
-def some_function_with_a_really_long_name() -> (
|
||||
- returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||
-):
|
||||
- pass
|
||||
+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:
|
||||
+def some_method_with_a_really_long_name(very_long_parameter_so_yeah: str, another_long_parameter: int) -> (
|
||||
+ another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not
|
||||
+):
|
||||
pass
|
||||
|
||||
|
||||
def func() -> (
|
||||
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
- this_shouldn_t_get_a_trailing_comma_too
|
||||
- )
|
||||
+ also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too)
|
||||
):
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def func() -> (
|
||||
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
+def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
this_shouldn_t_get_a_trailing_comma_too
|
||||
- this_shouldn_t_get_a_trailing_comma_too
|
||||
- )
|
||||
+ ))
|
||||
):
|
||||
pass
|
||||
-):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
@@ -103,12 +59,5 @@
|
||||
|
||||
-def func() -> (
|
||||
- also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
- this_shouldn_t_get_a_trailing_comma_too
|
||||
- )
|
||||
-):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Make sure inner one-element tuple won't explode
|
||||
-some_module.some_function(
|
||||
- argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
# Inner trailing comma causes outer to explode
|
||||
some_module.some_function(
|
||||
-some_module.some_function(
|
||||
- argument1,
|
||||
- (
|
||||
- one,
|
||||
|
@ -200,76 +197,44 @@ some_module.some_function(
|
|||
- argument4,
|
||||
- argument5,
|
||||
- argument6,
|
||||
+ argument1, (one, two,), argument4, argument5, argument6
|
||||
)
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
def f(a,):
|
||||
d = {'key': 'value',}
|
||||
tup = (1,)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def f2(a,b,):
|
||||
d = {'key': 'value', 'key2': 'value2',}
|
||||
tup = (1,2,)
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def f(a:int=1,):
|
||||
call(arg={'explode': 'this',})
|
||||
call2(arg=[1,2,3],)
|
||||
x = {
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
}["a"]
|
||||
if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
]:
|
||||
json = {"k": {"k2": {"k3": [1,]}}}
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||
def some_function_with_a_really_long_name() -> (
|
||||
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||
):
|
||||
pass
|
||||
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() -> (
|
||||
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too)
|
||||
):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||
this_shouldn_t_get_a_trailing_comma_too
|
||||
))
|
||||
):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Make sure inner one-element tuple won't explode
|
||||
some_module.some_function(
|
||||
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
# Inner trailing comma causes outer to explode
|
||||
some_module.some_function(
|
||||
argument1, (one, two,), argument4, argument5, argument6
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -62,22 +62,44 @@ __all__ = (
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,8 +2,10 @@
|
||||
@@ -1,64 +1,31 @@
|
||||
-"""The asyncio package, tracking PEP 3156."""
|
||||
+NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
-from logging import WARNING
|
||||
from logging import (
|
||||
+ WARNING
|
||||
+)
|
||||
+from logging import (
|
||||
ERROR,
|
||||
)
|
||||
import sys
|
||||
@@ -22,33 +24,16 @@
|
||||
from ..streams import *
|
||||
-from logging import (
|
||||
- ERROR,
|
||||
-)
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
from some_library import (
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
-from .base_events import *
|
||||
-from .coroutines import *
|
||||
-from .events import * # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
|
||||
-from .futures import *
|
||||
-from .locks import * # comment here
|
||||
-from .protocols import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from ..runners import * # comment here
|
||||
-from ..queues import *
|
||||
-from ..streams import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
-from some_library import (
|
||||
- Just,
|
||||
- Enough,
|
||||
- Libraries,
|
||||
|
@ -92,82 +114,76 @@ __all__ = (
|
|||
- No,
|
||||
- Longer,
|
||||
- Use,
|
||||
+ Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
|
||||
)
|
||||
-)
|
||||
-from name_of_a_company.extremely_long_project_name.component.ttypes import (
|
||||
- CuteLittleServiceHandlerFactoryyy,
|
||||
-)
|
||||
+from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy
|
||||
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
-from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from .a.b.c.subprocess import *
|
||||
-from .a.b.c.subprocess import *
|
||||
-from . import tasks
|
||||
-from . import A, B, C
|
||||
-from . import (
|
||||
- SomeVeryLongNameAndAllOfItsAdditionalLetters1,
|
||||
- SomeVeryLongNameAndAllOfItsAdditionalLetters2,
|
||||
-)
|
||||
+from . import (tasks)
|
||||
+from . import (A, B, C)
|
||||
+from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \
|
||||
+ SomeVeryLongNameAndAllOfItsAdditionalLetters2
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
-__all__ = (
|
||||
- base_events.__all__
|
||||
- + coroutines.__all__
|
||||
- + events.__all__
|
||||
- + futures.__all__
|
||||
- + locks.__all__
|
||||
- + protocols.__all__
|
||||
- + runners.__all__
|
||||
- + queues.__all__
|
||||
- + streams.__all__
|
||||
- + tasks.__all__
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
"""The asyncio package, tracking PEP 3156."""
|
||||
NOT_YET_IMPLEMENTED_ExprConstant
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
from logging import (
|
||||
WARNING
|
||||
)
|
||||
from logging import (
|
||||
ERROR,
|
||||
)
|
||||
import sys
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
# This relies on each of the submodules having an __all__ variable.
|
||||
from .base_events import *
|
||||
from .coroutines import *
|
||||
from .events import * # comment here
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
|
||||
from .futures import *
|
||||
from .locks import * # comment here
|
||||
from .protocols import *
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from ..runners import * # comment here
|
||||
from ..queues import *
|
||||
from ..streams import *
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom # comment here
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from some_library import (
|
||||
Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
|
||||
)
|
||||
from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy
|
||||
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
from .a.b.c.subprocess import *
|
||||
from . import (tasks)
|
||||
from . import (A, B, C)
|
||||
from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \
|
||||
SomeVeryLongNameAndAllOfItsAdditionalLetters2
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
||||
__all__ = (
|
||||
base_events.__all__
|
||||
+ coroutines.__all__
|
||||
+ events.__all__
|
||||
+ futures.__all__
|
||||
+ locks.__all__
|
||||
+ protocols.__all__
|
||||
+ runners.__all__
|
||||
+ queues.__all__
|
||||
+ streams.__all__
|
||||
+ tasks.__all__
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -25,8 +25,13 @@ list_of_types = [tuple[int,],]
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -4,19 +4,9 @@
|
||||
b = tuple[int,]
|
||||
@@ -1,22 +1,12 @@
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
-a: tuple[int,]
|
||||
-b = tuple[int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
-c: tuple[
|
||||
|
@ -37,8 +42,8 @@ list_of_types = [tuple[int,],]
|
|||
- int,
|
||||
- int,
|
||||
-]
|
||||
+c: tuple[int, int,]
|
||||
+d = tuple[int, int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
-small_list = [
|
||||
|
@ -47,8 +52,8 @@ list_of_types = [tuple[int,],]
|
|||
-list_of_types = [
|
||||
- tuple[int,],
|
||||
-]
|
||||
+small_list = [1,]
|
||||
+list_of_types = [tuple[int,],]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -56,16 +61,16 @@ list_of_types = [tuple[int,],]
|
|||
```py
|
||||
# We should not treat the trailing comma
|
||||
# in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# The magic comma still applies to multi-element subscripts.
|
||||
c: tuple[int, int,]
|
||||
d = tuple[int, int,]
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Magic commas still work as expected for non-subscripts.
|
||||
small_list = [1,]
|
||||
list_of_types = [tuple[int,],]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -76,87 +76,166 @@ return np.divide(
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,10 +1,10 @@
|
||||
def function(**kwargs):
|
||||
t = a**2 + b**3
|
||||
@@ -1,63 +1,51 @@
|
||||
-def function(**kwargs):
|
||||
- t = a**2 + b**3
|
||||
- return t**2
|
||||
+ return t ** 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def function_replace_spaces(**kwargs):
|
||||
-def function_replace_spaces(**kwargs):
|
||||
- t = a**2 + b**3 + c**4
|
||||
+ t = a **2 + b** 3 + c ** 4
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def function_dont_replace_spaces():
|
||||
-def function_dont_replace_spaces():
|
||||
- {**a, **b, **c}
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-a = 5**~4
|
||||
-b = 5 ** f()
|
||||
-c = -(5**2)
|
||||
-d = 5 ** f["hi"]
|
||||
-e = lazy(lambda **kwargs: 5)
|
||||
-f = f() ** 5
|
||||
-g = a.b**c.d
|
||||
-h = 5 ** funcs.f()
|
||||
-i = funcs.f() ** 5
|
||||
-j = super().name ** 5
|
||||
-k = [(2**idx, value) for idx, value in pairs]
|
||||
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
-m = [([2**63], [1, 2**63])]
|
||||
-n = count <= 10**5
|
||||
-o = settings(max_examples=10**6)
|
||||
-p = {(k, k**2): v**2 for k, v in pairs}
|
||||
-q = [10**i for i in range(6)]
|
||||
-r = x**y
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
-a = 5.0**~4.0
|
||||
-b = 5.0 ** f()
|
||||
-c = -(5.0**2.0)
|
||||
-d = 5.0 ** f["hi"]
|
||||
-e = lazy(lambda **kwargs: 5)
|
||||
-f = f() ** 5.0
|
||||
-g = a.b**c.d
|
||||
-h = 5.0 ** funcs.f()
|
||||
-i = funcs.f() ** 5.0
|
||||
-j = super().name ** 5.0
|
||||
-k = [(2.0**idx, value) for idx, value in pairs]
|
||||
-l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
-m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
-n = count <= 10**5.0
|
||||
-o = settings(max_examples=10**6.0)
|
||||
-p = {(k, k**2): v**2.0 for k, v in pairs}
|
||||
-q = [10.5**i for i in range(6)]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
-if hasattr(view, "sum_of_weights"):
|
||||
- return np.divide( # type: ignore[no-any-return]
|
||||
- view.variance, # type: ignore[union-attr]
|
||||
- view.sum_of_weights, # type: ignore[union-attr]
|
||||
- out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr]
|
||||
- where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr]
|
||||
- )
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
-return np.divide(
|
||||
- where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtReturn
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
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():
|
||||
{**a, **b, **c}
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
a = 5**~4
|
||||
b = 5 ** f()
|
||||
c = -(5**2)
|
||||
d = 5 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5
|
||||
g = a.b**c.d
|
||||
h = 5 ** funcs.f()
|
||||
i = funcs.f() ** 5
|
||||
j = super().name ** 5
|
||||
k = [(2**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2**63], [1, 2**63])]
|
||||
n = count <= 10**5
|
||||
o = settings(max_examples=10**6)
|
||||
p = {(k, k**2): v**2 for k, v in pairs}
|
||||
q = [10**i for i in range(6)]
|
||||
r = x**y
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
a = 5.0**~4.0
|
||||
b = 5.0 ** f()
|
||||
c = -(5.0**2.0)
|
||||
d = 5.0 ** f["hi"]
|
||||
e = lazy(lambda **kwargs: 5)
|
||||
f = f() ** 5.0
|
||||
g = a.b**c.d
|
||||
h = 5.0 ** funcs.f()
|
||||
i = funcs.f() ** 5.0
|
||||
j = super().name ** 5.0
|
||||
k = [(2.0**idx, value) for idx, value in pairs]
|
||||
l = mod.weights_[0] == pytest.approx(0.95**100, abs=0.001)
|
||||
m = [([2.0**63.0], [1.0, 2**63.0])]
|
||||
n = count <= 10**5.0
|
||||
o = settings(max_examples=10**6.0)
|
||||
p = {(k, k**2): v**2.0 for k, v in pairs}
|
||||
q = [10.5**i for i in range(6)]
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
# WE SHOULD DEFINITELY NOT EAT THESE COMMENTS (https://github.com/psf/black/issues/2873)
|
||||
if hasattr(view, "sum_of_weights"):
|
||||
return np.divide( # type: ignore[no-any-return]
|
||||
view.variance, # type: ignore[union-attr]
|
||||
view.sum_of_weights, # type: ignore[union-attr]
|
||||
out=np.full(view.sum_of_weights.shape, np.nan), # type: ignore[union-attr]
|
||||
where=view.sum_of_weights**2 > view.sum_of_weights_squared, # type: ignore[union-attr]
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
return np.divide(
|
||||
where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtReturn
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -25,7 +25,7 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,20 +2,11 @@
|
||||
@@ -2,20 +2,8 @@
|
||||
|
||||
# Left hand side fits in a single line but will still be exploded by the
|
||||
# magic trailing comma.
|
||||
|
@ -37,17 +37,17 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
|
|||
- ),
|
||||
- third_value,
|
||||
-) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
|
||||
+first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
|
||||
arg1,
|
||||
arg2,
|
||||
)
|
||||
- arg1,
|
||||
- arg2,
|
||||
-)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Make when when the left side of assignment plus the opening paren "... = (" is
|
||||
# exactly line length limit + 1, it won't be split like that.
|
||||
-xxxxxxxxx_yyy_zzzzzzzz[
|
||||
- xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)
|
||||
-] = 1
|
||||
+xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -57,14 +57,11 @@ xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxx
|
|||
|
||||
# Left hand side fits in a single line but will still be exploded by the
|
||||
# magic trailing comma.
|
||||
first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
|
||||
arg1,
|
||||
arg2,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Make when when the left side of assignment plus the opening paren "... = (" is
|
||||
# exactly line length limit + 1, it won't be split like that.
|
||||
xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -94,51 +94,51 @@ async def main():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -8,59 +8,64 @@
|
||||
@@ -1,93 +1,60 @@
|
||||
-import asyncio
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# Control example
|
||||
-async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (asyncio.sleep(1))
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (
|
||||
+ asyncio.sleep(1)
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1)
|
||||
+ await (asyncio.sleep(1)
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ await ( # Hello
|
||||
+ asyncio.sleep(1)
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ await (
|
||||
+ asyncio.sleep(1) # Hello
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.sleep(1) # Hello
|
||||
+ await (
|
||||
+ asyncio.sleep(1)
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.gather(
|
||||
- asyncio.sleep(1),
|
||||
- asyncio.sleep(1),
|
||||
|
@ -148,11 +148,11 @@ async def main():
|
|||
- asyncio.sleep(1),
|
||||
- asyncio.sleep(1),
|
||||
- )
|
||||
+ await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1))
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Same as above but with magic trailing comma in function
|
||||
async def main():
|
||||
-async def main():
|
||||
- await asyncio.gather(
|
||||
- asyncio.sleep(1),
|
||||
- asyncio.sleep(1),
|
||||
|
@ -162,145 +162,115 @@ async def main():
|
|||
- asyncio.sleep(1),
|
||||
- asyncio.sleep(1),
|
||||
- )
|
||||
+ await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Cr@zY Br@ck3Tz
|
||||
async def main():
|
||||
-async def main():
|
||||
- await black(1)
|
||||
+ await (
|
||||
+ (((((((((((((
|
||||
+ ((( (((
|
||||
+ ((( (((
|
||||
+ ((( (((
|
||||
+ ((( (((
|
||||
+ ((black(1)))
|
||||
+ ))) )))
|
||||
+ ))) )))
|
||||
+ ))) )))
|
||||
+ ))) )))
|
||||
+ )))))))))))))
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
@@ -82,11 +87,11 @@
|
||||
-async def main():
|
||||
- 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
|
||||
|
||||
|
||||
async def main():
|
||||
# It's awaits all the way down...
|
||||
-async def main():
|
||||
- await (await x)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-async def main():
|
||||
- await (yield x)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-async def main():
|
||||
- await (await asyncio.sleep(1))
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
-async def main():
|
||||
- await (await (await (await (await asyncio.sleep(1)))))
|
||||
+ await (await (await (await (await (asyncio.sleep(1))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
-async def main():
|
||||
- await (yield)
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
import asyncio
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
# Control example
|
||||
async def main():
|
||||
await asyncio.sleep(1)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Remove brackets for short coroutine/task
|
||||
async def main():
|
||||
await (asyncio.sleep(1))
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1)
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (asyncio.sleep(1)
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Check comments
|
||||
async def main():
|
||||
await ( # Hello
|
||||
asyncio.sleep(1)
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1) # Hello
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (
|
||||
asyncio.sleep(1)
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Long lines
|
||||
async def main():
|
||||
await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1))
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Same as above but with magic trailing comma in function
|
||||
async def main():
|
||||
await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Cr@zY Br@ck3Tz
|
||||
async def main():
|
||||
await (
|
||||
(((((((((((((
|
||||
((( (((
|
||||
((( (((
|
||||
((( (((
|
||||
((( (((
|
||||
((black(1)))
|
||||
))) )))
|
||||
))) )))
|
||||
))) )))
|
||||
))) )))
|
||||
)))))))))))))
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# Keep brackets around non power operations and nested awaits
|
||||
async def main():
|
||||
await (set_of_tasks | other_set)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (await asyncio.sleep(1))
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# It's awaits all the way down...
|
||||
async def main():
|
||||
await (await x)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (yield x)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (await (asyncio.sleep(1)))
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (await (await (await (await (asyncio.sleep(1))))))
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
async def main():
|
||||
await (yield)
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -48,85 +48,69 @@ except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.ov
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,42 +1,27 @@
|
||||
@@ -1,42 +1,9 @@
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
-try:
|
||||
- a.something
|
||||
-except AttributeError as err:
|
||||
+except (AttributeError) as err:
|
||||
raise err
|
||||
- raise err
|
||||
-
|
||||
-# This is tuple of exceptions.
|
||||
-# Although this could be replaced with just the exception,
|
||||
-# we do not remove brackets to preserve AST.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError,) as err:
|
||||
raise err
|
||||
-try:
|
||||
- a.something
|
||||
-except (AttributeError,) as err:
|
||||
- raise err
|
||||
-
|
||||
-# This is a tuple of exceptions. Do not remove brackets.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError, ValueError) as err:
|
||||
raise err
|
||||
-try:
|
||||
- a.something
|
||||
-except (AttributeError, ValueError) as err:
|
||||
- raise err
|
||||
-
|
||||
-# Test long variants.
|
||||
try:
|
||||
a.something
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error
|
||||
-) as err:
|
||||
+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
try:
|
||||
a.something
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
-) as err:
|
||||
+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err:
|
||||
raise err
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
try:
|
||||
a.something
|
||||
-try:
|
||||
- a.something
|
||||
-except (
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
- some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||
-) as err:
|
||||
+except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
- raise err
|
||||
+NOT_YET_IMPLEMENTED_StmtTry
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# These brackets are redundant, therefore remove.
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError) as err:
|
||||
raise err
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError,) as err:
|
||||
raise err
|
||||
try:
|
||||
a.something
|
||||
except (AttributeError, ValueError) as err:
|
||||
raise err
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err:
|
||||
raise err
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
|
||||
try:
|
||||
a.something
|
||||
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||
raise err
|
||||
NOT_YET_IMPLEMENTED_StmtTry
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -32,23 +32,25 @@ for (((((k, v))))) in d.items():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,5 +1,5 @@
|
||||
@@ -1,27 +1,13 @@
|
||||
# Only remove tuple brackets after `for`
|
||||
-for k, v in d.items():
|
||||
+for (k, v) in d.items():
|
||||
print(k, v)
|
||||
- print(k, v)
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Don't touch tuple brackets after `in`
|
||||
@@ -8,20 +8,12 @@
|
||||
module._verify_python3_env = lambda: None
|
||||
-for module in (core, _unicodefun):
|
||||
- if hasattr(module, "_verify_python3_env"):
|
||||
- module._verify_python3_env = lambda: None
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
-for (
|
||||
- why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long,
|
||||
- i_dont_know_but_we_should_still_check_the_behaviour_if_they_do,
|
||||
-) in d.items():
|
||||
+for (why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do) in d.items():
|
||||
print(k, v)
|
||||
- print(k, v)
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
-for (
|
||||
- k,
|
||||
|
@ -56,37 +58,31 @@ for (((((k, v))))) in d.items():
|
|||
-) in (
|
||||
- dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items()
|
||||
-):
|
||||
+for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
|
||||
print(k, v)
|
||||
- print(k, v)
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Test deeply nested brackets
|
||||
-for k, v in d.items():
|
||||
+for (((((k, v))))) in d.items():
|
||||
print(k, v)
|
||||
- print(k, v)
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Only remove tuple brackets after `for`
|
||||
for (k, v) in d.items():
|
||||
print(k, v)
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Don't touch tuple brackets after `in`
|
||||
for module in (core, _unicodefun):
|
||||
if hasattr(module, "_verify_python3_env"):
|
||||
module._verify_python3_env = lambda: None
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Brackets remain for long for loop lines
|
||||
for (why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do) in d.items():
|
||||
print(k, v)
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
|
||||
print(k, v)
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
# Test deeply nested brackets
|
||||
for (((((k, v))))) in d.items():
|
||||
print(k, v)
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -121,200 +121,168 @@ with open("/path/to/file.txt", mode="r") as read_file:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,20 +2,26 @@
|
||||
@@ -1,78 +1,56 @@
|
||||
-import random
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
def foo1():
|
||||
+
|
||||
print("The newline above me should be deleted!")
|
||||
-def foo1():
|
||||
- print("The newline above me should be deleted!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo2():
|
||||
+
|
||||
+
|
||||
+
|
||||
print("All the newlines above me should be deleted!")
|
||||
-def foo2():
|
||||
- print("All the newlines above me should be deleted!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo3():
|
||||
+
|
||||
print("No newline above me!")
|
||||
-def foo3():
|
||||
- print("No newline above me!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
print("There is a newline above me, and that's OK!")
|
||||
- print("There is a newline above me, and that's OK!")
|
||||
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
-def foo4():
|
||||
- # There is a comment here
|
||||
|
||||
- print("The newline above me should not be deleted!")
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def foo4():
|
||||
+
|
||||
# There is a comment here
|
||||
|
||||
print("The newline above me should not be deleted!")
|
||||
@@ -23,27 +29,39 @@
|
||||
|
||||
class Foo:
|
||||
def bar(self):
|
||||
+
|
||||
print("The newline above me should be deleted!")
|
||||
-class Foo:
|
||||
- def bar(self):
|
||||
- print("The newline above me should be deleted!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
for i in range(5):
|
||||
+
|
||||
print(f"{i}) The line above me should be removed!")
|
||||
-for i in range(5):
|
||||
- print(f"{i}) The line above me should be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
for i in range(5):
|
||||
+
|
||||
+
|
||||
+
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
-for i in range(5):
|
||||
- print(f"{i}) The lines above me should be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
for i in range(5):
|
||||
+
|
||||
for j in range(7):
|
||||
+
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
-for i in range(5):
|
||||
- for j in range(7):
|
||||
- print(f"{i}) The lines above me should be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
+
|
||||
print("The new line above me is about to be removed!")
|
||||
-if random.randint(0, 3) == 0:
|
||||
- print("The new line above me is about to be removed!")
|
||||
-
|
||||
-
|
||||
-if random.randint(0, 3) == 0:
|
||||
- print("The new lines above me is about to be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
+
|
||||
+
|
||||
+
|
||||
+
|
||||
print("The new lines above me is about to be removed!")
|
||||
-if random.randint(0, 3) == 0:
|
||||
- if random.uniform(0, 1) > 0.5:
|
||||
- print("Two lines above me are about to be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
@@ -66,13 +84,19 @@
|
||||
-while True:
|
||||
- print("The newline above me should be deleted!")
|
||||
+while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
+ NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
+
|
||||
file.write("The new line above me is about to be removed!")
|
||||
-while True:
|
||||
- print("The newlines above me should be deleted!")
|
||||
+while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
+ NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
+
|
||||
+
|
||||
+
|
||||
file.write("The new lines above me is about to be removed!")
|
||||
-while True:
|
||||
- while False:
|
||||
- print("The newlines above me should be deleted!")
|
||||
+while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
+ while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
+ NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="r") as read_file:
|
||||
+
|
||||
with open("/path/to/output_file.txt", mode="w") as write_file:
|
||||
+
|
||||
write_file.writelines(read_file.readlines())
|
||||
-with open("/path/to/file.txt", mode="w") as file:
|
||||
- file.write("The new line above me is about to be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
-with open("/path/to/file.txt", mode="w") as file:
|
||||
- file.write("The new lines above me is about to be removed!")
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
-with open("/path/to/file.txt", mode="r") as read_file:
|
||||
- with open("/path/to/output_file.txt", mode="w") as write_file:
|
||||
- write_file.writelines(read_file.readlines())
|
||||
+NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
import random
|
||||
NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
|
||||
def foo1():
|
||||
|
||||
print("The newline above me should be deleted!")
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo2():
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
|
||||
print("All the newlines above me should be deleted!")
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo3():
|
||||
|
||||
print("No newline above me!")
|
||||
|
||||
print("There is a newline above me, and that's OK!")
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo4():
|
||||
|
||||
# There is a comment here
|
||||
|
||||
print("The newline above me should not be deleted!")
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class Foo:
|
||||
def bar(self):
|
||||
|
||||
print("The newline above me should be deleted!")
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
for i in range(5):
|
||||
|
||||
print(f"{i}) The line above me should be removed!")
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
for i in range(5):
|
||||
NOT_YET_IMPLEMENTED_StmtFor
|
||||
|
||||
|
||||
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
for i in range(5):
|
||||
|
||||
for j in range(7):
|
||||
|
||||
print(f"{i}) The lines above me should be removed!")
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
|
||||
print("The new line above me is about to be removed!")
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
print("The new lines above me is about to be removed!")
|
||||
while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
while NOT_YET_IMPLEMENTED_ExprConstant:
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
|
||||
if random.randint(0, 3) == 0:
|
||||
if random.uniform(0, 1) > 0.5:
|
||||
print("Two lines above me are about to be removed!")
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
while True:
|
||||
print("The newline above me should be deleted!")
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
|
||||
|
||||
while True:
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
while True:
|
||||
while False:
|
||||
print("The newlines above me should be deleted!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
|
||||
file.write("The new line above me is about to be removed!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="w") as file:
|
||||
|
||||
|
||||
|
||||
file.write("The new lines above me is about to be removed!")
|
||||
|
||||
|
||||
with open("/path/to/file.txt", mode="r") as read_file:
|
||||
|
||||
with open("/path/to/output_file.txt", mode="w") as write_file:
|
||||
|
||||
write_file.writelines(read_file.readlines())
|
||||
NOT_YET_IMPLEMENTED_StmtWith
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -68,71 +68,75 @@ def example8():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,5 +1,5 @@
|
||||
@@ -1,85 +1,37 @@
|
||||
-x = 1
|
||||
-x = 1.2
|
||||
+x = (1)
|
||||
+x = (1.2)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
data = (
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
@@ -11,75 +11,47 @@
|
||||
try:
|
||||
if report_host:
|
||||
data = (
|
||||
-data = (
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
-).encode()
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
-async def show_status():
|
||||
- while True:
|
||||
- try:
|
||||
- if report_host:
|
||||
- data = (
|
||||
- f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
- ).encode()
|
||||
+ f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
+ ).encode()
|
||||
except Exception as e:
|
||||
pass
|
||||
- except Exception as e:
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
def example():
|
||||
-def example():
|
||||
- return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
+ return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example1():
|
||||
-def example1():
|
||||
- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
+ return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example1point5():
|
||||
-def example1point5():
|
||||
- return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
+ return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example2():
|
||||
-def example2():
|
||||
- return (
|
||||
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
- )
|
||||
+ return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example3():
|
||||
-def example3():
|
||||
- return (
|
||||
- 1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||
- )
|
||||
+ return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example4():
|
||||
-def example4():
|
||||
- return True
|
||||
+ return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example5():
|
||||
-def example5():
|
||||
- return ()
|
||||
+ return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def example7():
|
||||
-def example7():
|
||||
- return {
|
||||
- a: a
|
||||
- for a in [
|
||||
|
@ -158,74 +162,54 @@ def example8():
|
|||
- 20000000000000000000,
|
||||
- ]
|
||||
- }
|
||||
+ return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]})))))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example8():
|
||||
-def example8():
|
||||
- return None
|
||||
+ return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
x = (1)
|
||||
x = (1.2)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
data = (
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
|
||||
async def show_status():
|
||||
while True:
|
||||
try:
|
||||
if report_host:
|
||||
data = (
|
||||
f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
).encode()
|
||||
except Exception as e:
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
def example():
|
||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example1():
|
||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example1point5():
|
||||
return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example2():
|
||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example3():
|
||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example4():
|
||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example5():
|
||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
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]})))))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example7():
|
||||
return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]})))))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def example8():
|
||||
return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -101,78 +101,67 @@ def foo() -> tuple[int, int, int,]:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,33 +1,41 @@
|
||||
@@ -1,120 +1,65 @@
|
||||
# Control
|
||||
def double(a: int) -> int:
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Remove the brackets
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (int):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Some newline variations
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (
|
||||
+ int):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (int
|
||||
+):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+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
|
||||
+def double(a: int) -> ( # Hello
|
||||
+ int
|
||||
+):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def double(a: int) -> int: # Hello
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (
|
||||
+ int # Hello
|
||||
+):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Really long annotations
|
||||
@@ -37,84 +45,62 @@
|
||||
return 2
|
||||
-def foo() -> (
|
||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-):
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo() -> (
|
||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-):
|
||||
+def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo() -> (
|
||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-):
|
||||
+def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo(
|
||||
|
@ -180,8 +169,8 @@ def foo() -> tuple[int, int, int,]:
|
|||
- b: int,
|
||||
- c: int,
|
||||
-) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
+def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo(
|
||||
|
@ -192,8 +181,8 @@ def foo() -> tuple[int, int, int,]:
|
|||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-):
|
||||
+def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Split args but no need to split return
|
||||
|
@ -202,45 +191,33 @@ def foo() -> tuple[int, int, int,]:
|
|||
- b: int,
|
||||
- c: int,
|
||||
-) -> int:
|
||||
+def foo(a: int, b: int, c: int,) -> int:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Deeply nested brackets
|
||||
# with *interesting* spacing
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (((((int))))):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def double(a: int) -> int:
|
||||
- return 2 * a
|
||||
+def double(a: int) -> (
|
||||
+ ( (
|
||||
+ ((int)
|
||||
+ )
|
||||
+ )
|
||||
+ )
|
||||
+ ):
|
||||
+ return 2*a
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo() -> (
|
||||
+ ( (
|
||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-def foo() -> (
|
||||
- intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||
-):
|
||||
+)
|
||||
+)):
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Return type with commas
|
||||
-def foo() -> tuple[int, int, int]:
|
||||
+def foo() -> (
|
||||
+ tuple[int, int, int]
|
||||
+):
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def foo() -> (
|
||||
|
@ -250,8 +227,8 @@ def foo() -> tuple[int, int, int,]:
|
|||
- loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||
- ]
|
||||
-):
|
||||
+def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Magic trailing comma example
|
||||
|
@ -262,119 +239,78 @@ def foo() -> tuple[int, int, int,]:
|
|||
- int,
|
||||
- ]
|
||||
-):
|
||||
+def foo() -> tuple[int, int, int,]:
|
||||
return 2
|
||||
- return 2
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# Control
|
||||
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) -> ( # Hello
|
||||
int
|
||||
):
|
||||
return 2*a
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def double(a: int) -> (
|
||||
int # Hello
|
||||
):
|
||||
return 2*a
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Really long annotations
|
||||
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
|
||||
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
|
||||
def foo() -> (
|
||||
tuple[int, int, int]
|
||||
):
|
||||
return 2
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]:
|
||||
return 2
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
# Magic trailing comma example
|
||||
def foo() -> tuple[int, int, int,]:
|
||||
return 2
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -60,114 +60,75 @@ func(
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -3,23 +3,45 @@
|
||||
b = tuple[int,]
|
||||
@@ -1,25 +1,25 @@
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
-a: tuple[int,]
|
||||
-b = tuple[int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
-c: tuple[int, int]
|
||||
-d = tuple[int, int]
|
||||
+c: tuple[int, int,]
|
||||
+d = tuple[int, int,]
|
||||
+NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
-small_list = [1]
|
||||
-list_of_types = [tuple[int,]]
|
||||
-small_set = {1}
|
||||
-set_of_types = {tuple[int,]}
|
||||
+small_list = [1,]
|
||||
+list_of_types = [tuple[int,],]
|
||||
+small_set = {1,}
|
||||
+set_of_types = {tuple[int,],}
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
-small_tuple = (1,)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
-zero(one).two(three).four(five)
|
||||
+zero(
|
||||
+ one,
|
||||
+).two(
|
||||
+ three,
|
||||
+).four(
|
||||
+ five,
|
||||
+)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
-func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5)
|
||||
+func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
-(a, b, c, d) = func1(arg1) and func2(arg2)
|
||||
+(
|
||||
+ a,
|
||||
+ b,
|
||||
+ c,
|
||||
+ d,
|
||||
+) = func1(
|
||||
+ arg1
|
||||
+) and func2(arg2)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
-func(argument1, (one, two), argument4, argument5, argument6)
|
||||
+func(
|
||||
+ argument1,
|
||||
+ (
|
||||
+ one,
|
||||
+ two,
|
||||
+ ),
|
||||
+ argument4,
|
||||
+ argument5,
|
||||
+ argument6,
|
||||
+)
|
||||
+NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
# We should not remove the trailing comma in a single-element subscript.
|
||||
a: tuple[int,]
|
||||
b = tuple[int,]
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# But commas in multiple element subscripts should be removed.
|
||||
c: tuple[int, int,]
|
||||
d = tuple[int, int,]
|
||||
NOT_YET_IMPLEMENTED_StmtAnnAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Remove commas for non-subscripts.
|
||||
small_list = [1,]
|
||||
list_of_types = [tuple[int,],]
|
||||
small_set = {1,}
|
||||
set_of_types = {tuple[int,],}
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Except single element tuples
|
||||
small_tuple = (1,)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
# Trailing commas in multiple chained non-nested parens.
|
||||
zero(
|
||||
one,
|
||||
).two(
|
||||
three,
|
||||
).four(
|
||||
five,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
|
||||
(
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d,
|
||||
) = func1(
|
||||
arg1
|
||||
) and func2(arg2)
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
|
||||
func(
|
||||
argument1,
|
||||
(
|
||||
one,
|
||||
two,
|
||||
),
|
||||
argument4,
|
||||
argument5,
|
||||
argument6,
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprCall
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -76,127 +76,137 @@ x[
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -31,14 +31,17 @@
|
||||
ham[lower + offset : upper + offset]
|
||||
@@ -1,59 +1,37 @@
|
||||
-slice[a.b : c.d]
|
||||
-slice[d :: d + 1]
|
||||
-slice[d + 1 :: d]
|
||||
-slice[d::d]
|
||||
-slice[0]
|
||||
-slice[-1]
|
||||
-slice[:-1]
|
||||
-slice[::-1]
|
||||
-slice[:c, c - 1]
|
||||
-slice[c, c + 1, d::]
|
||||
-slice[ham[c::d] :: 1]
|
||||
-slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
-slice[:-1:]
|
||||
-slice[lambda: None : lambda: None]
|
||||
-slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
|
||||
-slice[1 or 2 : True and False]
|
||||
-slice[not so_simple : 1 < val <= 10]
|
||||
-slice[(1 for i in range(42)) : x]
|
||||
-slice[:: [i for i in range(42)]]
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
slice[::, ::]
|
||||
|
||||
-async def f():
|
||||
- slice[await x : [i async for i in arange(42)] : 42]
|
||||
+NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
-ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
|
||||
-ham[lower:upper], ham[lower:upper:], ham[lower::step]
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
# ham[lower+offset : upper+offset]
|
||||
-ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
|
||||
-ham[lower + offset : upper + offset]
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
-slice[::, ::]
|
||||
-slice[
|
||||
+(
|
||||
+ slice[
|
||||
# A
|
||||
:
|
||||
# B
|
||||
:
|
||||
# C
|
||||
]
|
||||
- # A
|
||||
- :
|
||||
- # B
|
||||
- :
|
||||
- # C
|
||||
-]
|
||||
-slice[
|
||||
+)
|
||||
+(
|
||||
+ slice[
|
||||
# A
|
||||
1:
|
||||
# B
|
||||
@@ -46,8 +49,10 @@
|
||||
# C
|
||||
3
|
||||
]
|
||||
+)
|
||||
- # A
|
||||
- 1:
|
||||
- # B
|
||||
- 2:
|
||||
- # C
|
||||
- 3
|
||||
-]
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
-slice[
|
||||
+(
|
||||
+ slice[
|
||||
# A
|
||||
1
|
||||
+ 2 :
|
||||
@@ -56,4 +61,11 @@
|
||||
# C
|
||||
4
|
||||
]
|
||||
- # A
|
||||
- 1
|
||||
- + 2 :
|
||||
- # B
|
||||
- 3 :
|
||||
- # C
|
||||
- 4
|
||||
-]
|
||||
-x[1:2:3] # A # B # C
|
||||
+)
|
||||
+(
|
||||
+ x[
|
||||
+ 1: # A
|
||||
+ 2: # B
|
||||
+ 3 # C
|
||||
+]
|
||||
+)
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
+NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
slice[a.b : c.d]
|
||||
slice[d :: d + 1]
|
||||
slice[d + 1 :: d]
|
||||
slice[d::d]
|
||||
slice[0]
|
||||
slice[-1]
|
||||
slice[:-1]
|
||||
slice[::-1]
|
||||
slice[:c, c - 1]
|
||||
slice[c, c + 1, d::]
|
||||
slice[ham[c::d] :: 1]
|
||||
slice[ham[cheese**2 : -1] : 1 : 1, ham[1:2]]
|
||||
slice[:-1:]
|
||||
slice[lambda: None : lambda: None]
|
||||
slice[lambda x, y, *args, really=2, **kwargs: None :, None::]
|
||||
slice[1 or 2 : True and False]
|
||||
slice[not so_simple : 1 < val <= 10]
|
||||
slice[(1 for i in range(42)) : x]
|
||||
slice[:: [i for i in range(42)]]
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
|
||||
async def f():
|
||||
slice[await x : [i async for i in arange(42)] : 42]
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncFunctionDef
|
||||
|
||||
|
||||
# These are from PEP-8:
|
||||
ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
|
||||
ham[lower:upper], ham[lower:upper:], ham[lower::step]
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
# ham[lower+offset : upper+offset]
|
||||
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
|
||||
ham[lower + offset : upper + offset]
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
slice[::, ::]
|
||||
(
|
||||
slice[
|
||||
# A
|
||||
:
|
||||
# B
|
||||
:
|
||||
# C
|
||||
]
|
||||
)
|
||||
(
|
||||
slice[
|
||||
# A
|
||||
1:
|
||||
# B
|
||||
2:
|
||||
# C
|
||||
3
|
||||
]
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
|
||||
(
|
||||
slice[
|
||||
# A
|
||||
1
|
||||
+ 2 :
|
||||
# B
|
||||
3 :
|
||||
# C
|
||||
4
|
||||
]
|
||||
)
|
||||
(
|
||||
x[
|
||||
1: # A
|
||||
2: # B
|
||||
3 # C
|
||||
]
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
NOT_YET_IMPLEMENTED_ExprSubscript
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -33,25 +33,36 @@ def docstring_multiline():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,13 +1,13 @@
|
||||
@@ -1,20 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
-name = "Łukasz"
|
||||
-(f"hello {name}", f"hello {name}")
|
||||
-(b"", b"")
|
||||
-("", "")
|
||||
+(f"hello {name}", F"hello {name}")
|
||||
+(b"", B"")
|
||||
+(u"", U"")
|
||||
(r"", R"")
|
||||
-(r"", R"")
|
||||
+NOT_YET_IMPLEMENTED_StmtAssign
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
|
||||
-(rf"", rf"", Rf"", Rf"", rf"", rf"", Rf"", Rf"")
|
||||
-(rb"", rb"", Rb"", Rb"", rb"", rb"", Rb"", Rb"")
|
||||
+(rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"")
|
||||
+(rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"")
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+NOT_YET_IMPLEMENTED_ExprTuple
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
-def docstring_singleline():
|
||||
- R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-def docstring_multiline():
|
||||
- R"""
|
||||
- clear out all of the issues opened in that time :p
|
||||
- """
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -59,24 +70,20 @@ def docstring_multiline():
|
|||
```py
|
||||
#!/usr/bin/env python3
|
||||
|
||||
name = "Łukasz"
|
||||
(f"hello {name}", F"hello {name}")
|
||||
(b"", B"")
|
||||
(u"", U"")
|
||||
(r"", R"")
|
||||
NOT_YET_IMPLEMENTED_StmtAssign
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
|
||||
(rf"", fr"", Rf"", fR"", rF"", Fr"", RF"", FR"")
|
||||
(rb"", br"", Rb"", bR"", rB"", Br"", RB"", BR"")
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
|
||||
|
||||
def docstring_singleline():
|
||||
R"""2020 was one hell of a year. The good news is that we were able to"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
def docstring_multiline():
|
||||
R"""
|
||||
clear out all of the issues opened in that time :p
|
||||
"""
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -42,16 +42,18 @@ assert (
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -2,18 +2,13 @@
|
||||
@@ -1,58 +1,20 @@
|
||||
importA
|
||||
(
|
||||
()
|
||||
<< 0
|
||||
- ()
|
||||
- << 0
|
||||
- ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
+ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
+ NOT_YET_IMPLEMENTED_ExprTuple
|
||||
+ << NOT_YET_IMPLEMENTED_ExprConstant**NOT_YET_IMPLEMENTED_ExprConstant
|
||||
) #
|
||||
|
||||
assert sort_by_dependency(
|
||||
{
|
||||
-assert sort_by_dependency(
|
||||
- {
|
||||
- "1": {"2", "3"},
|
||||
- "2": {"2a", "2b"},
|
||||
- "3": {"3a", "3b"},
|
||||
|
@ -59,23 +61,27 @@ assert (
|
|||
- "2b": set(),
|
||||
- "3a": set(),
|
||||
- "3b": set(),
|
||||
+ "1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"},
|
||||
+ "2a": set(), "2b": set(), "3a": set(), "3b": set()
|
||||
}
|
||||
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
- }
|
||||
-) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
@@ -25,34 +20,18 @@
|
||||
class A:
|
||||
def foo(self):
|
||||
for _ in range(10):
|
||||
importA
|
||||
-0
|
||||
-0 ^ 0 #
|
||||
+NOT_YET_IMPLEMENTED_ExprConstant
|
||||
+NOT_YET_IMPLEMENTED_ExprConstant ^ NOT_YET_IMPLEMENTED_ExprConstant #
|
||||
|
||||
|
||||
-class A:
|
||||
- def foo(self):
|
||||
- for _ in range(10):
|
||||
- aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc(
|
||||
+ aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member
|
||||
xxxxxxxxxxxx
|
||||
- xxxxxxxxxxxx
|
||||
- ) # pylint: disable=no-member
|
||||
+ )
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def test(self, othr):
|
||||
-def test(self, othr):
|
||||
- return 1 == 2 and (
|
||||
- name,
|
||||
- description,
|
||||
|
@ -95,19 +101,14 @@ assert (
|
|||
- othr.meta_data,
|
||||
- othr.schedule,
|
||||
- )
|
||||
+ return (1 == 2 and
|
||||
+ (name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) ==
|
||||
+ (name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule))
|
||||
+NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
-assert a_function(
|
||||
- very_long_arguments_that_surpass_the_limit,
|
||||
- which_is_eighty_eight_in_this_case_plus_a_bit_more,
|
||||
-) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
+assert (
|
||||
+ a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more)
|
||||
+ == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
+)
|
||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -115,41 +116,24 @@ assert (
|
|||
```py
|
||||
importA
|
||||
(
|
||||
()
|
||||
<< 0
|
||||
**101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||
NOT_YET_IMPLEMENTED_ExprTuple
|
||||
<< NOT_YET_IMPLEMENTED_ExprConstant**NOT_YET_IMPLEMENTED_ExprConstant
|
||||
) #
|
||||
|
||||
assert sort_by_dependency(
|
||||
{
|
||||
"1": {"2", "3"}, "2": {"2a", "2b"}, "3": {"3a", "3b"},
|
||||
"2a": set(), "2b": set(), "3a": set(), "3b": set()
|
||||
}
|
||||
) == ["2a", "2b", "2", "3a", "3b", "3", "1"]
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
|
||||
importA
|
||||
0
|
||||
0 ^ 0 #
|
||||
NOT_YET_IMPLEMENTED_ExprConstant
|
||||
NOT_YET_IMPLEMENTED_ExprConstant ^ NOT_YET_IMPLEMENTED_ExprConstant #
|
||||
|
||||
|
||||
class A:
|
||||
def foo(self):
|
||||
for _ in range(10):
|
||||
aaaaaaaaaaaaaaaaaaa = bbbbbbbbbbbbbbb.cccccccccc( # pylint: disable=no-member
|
||||
xxxxxxxxxxxx
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
def test(self, othr):
|
||||
return (1 == 2 and
|
||||
(name, description, self.default, self.selected, self.auto_generated, self.parameters, self.meta_data, self.schedule) ==
|
||||
(name, description, othr.default, othr.selected, othr.auto_generated, othr.parameters, othr.meta_data, othr.schedule))
|
||||
NOT_YET_IMPLEMENTED_StmtFunctionDef
|
||||
|
||||
|
||||
assert (
|
||||
a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more)
|
||||
== {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
|
||||
)
|
||||
NOT_YET_IMPLEMENTED_StmtAssert
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -38,17 +38,16 @@ class A:
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,18 +1,11 @@
|
||||
@@ -1,34 +1,9 @@
|
||||
-if e1234123412341234.winerror not in (
|
||||
- _winapi.ERROR_SEM_TIMEOUT,
|
||||
- _winapi.ERROR_PIPE_BUSY,
|
||||
-) or _check_timeout(t):
|
||||
+if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
|
||||
+ _winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
|
||||
pass
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
if x:
|
||||
if y:
|
||||
-if x:
|
||||
- if y:
|
||||
- new_id = (
|
||||
- max(
|
||||
- Vegetable.objects.order_by("-id")[0].id,
|
||||
|
@ -56,52 +55,42 @@ class A:
|
|||
- )
|
||||
- + 1
|
||||
- )
|
||||
+ new_id = max(Vegetable.objects.order_by('-id')[0].id,
|
||||
+ Mineral.objects.order_by('-id')[0].id) + 1
|
||||
+NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
class X:
|
||||
@@ -21,7 +14,7 @@
|
||||
"Your password must contain at least %(min_length)d character.",
|
||||
"Your password must contain at least %(min_length)d characters.",
|
||||
self.min_length,
|
||||
-class X:
|
||||
- def get_help_text(self):
|
||||
- return ngettext(
|
||||
- "Your password must contain at least %(min_length)d character.",
|
||||
- "Your password must contain at least %(min_length)d characters.",
|
||||
- self.min_length,
|
||||
- ) % {"min_length": self.min_length}
|
||||
+ ) % {'min_length': self.min_length}
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class A:
|
||||
-class A:
|
||||
- def b(self):
|
||||
- if self.connection.mysql_is_mariadb and (
|
||||
- 10,
|
||||
- 4,
|
||||
- 3,
|
||||
- ) < self.connection.mysql_version < (10, 5, 2):
|
||||
- pass
|
||||
+NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
|
||||
_winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
if x:
|
||||
if y:
|
||||
new_id = max(Vegetable.objects.order_by('-id')[0].id,
|
||||
Mineral.objects.order_by('-id')[0].id) + 1
|
||||
NOT_YET_IMPLEMENTED_StmtIf
|
||||
|
||||
|
||||
class X:
|
||||
def get_help_text(self):
|
||||
return ngettext(
|
||||
"Your password must contain at least %(min_length)d character.",
|
||||
"Your password must contain at least %(min_length)d characters.",
|
||||
self.min_length,
|
||||
) % {'min_length': self.min_length}
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
|
||||
|
||||
class A:
|
||||
def b(self):
|
||||
if self.connection.mysql_is_mariadb and (
|
||||
10,
|
||||
4,
|
||||
3,
|
||||
) < self.connection.mysql_version < (10, 5, 2):
|
||||
pass
|
||||
NOT_YET_IMPLEMENTED_StmtClassDef
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue