Compare commits
2 Commits
implicit-s
...
preview-bi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3e160dcb7 | ||
|
|
003851b54c |
@@ -1,8 +1,9 @@
|
|||||||
use crate::format_element::PrintMode;
|
|
||||||
use crate::{GroupId, TextSize};
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::num::NonZeroU8;
|
use std::num::NonZeroU8;
|
||||||
|
|
||||||
|
use crate::format_element::PrintMode;
|
||||||
|
use crate::{GroupId, TextSize};
|
||||||
|
|
||||||
/// A Tag marking the start and end of some content to which some special formatting should be applied.
|
/// A Tag marking the start and end of some content to which some special formatting should be applied.
|
||||||
///
|
///
|
||||||
/// Tags always come in pairs of a start and an end tag and the styling defined by this tag
|
/// Tags always come in pairs of a start and an end tag and the styling defined by this tag
|
||||||
@@ -99,6 +100,10 @@ pub enum Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
|
pub const fn align(count: NonZeroU8) -> Tag {
|
||||||
|
Tag::StartAlign(Align(count))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` is any start tag.
|
/// Returns `true` if `self` is any start tag.
|
||||||
pub const fn is_start(&self) -> bool {
|
pub const fn is_start(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ use ruff_text_size::{Ranged, TextRange};
|
|||||||
|
|
||||||
use crate::comments::{leading_comments, trailing_comments, Comments, SourceComment};
|
use crate::comments::{leading_comments, trailing_comments, Comments, SourceComment};
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_group, in_parentheses_only_if_group_breaks,
|
in_parentheses_only_group, in_parentheses_only_if_group_breaks, in_parentheses_only_indent_end,
|
||||||
in_parentheses_only_soft_line_break, in_parentheses_only_soft_line_break_or_space,
|
in_parentheses_only_indent_start, in_parentheses_only_soft_line_break,
|
||||||
is_expression_parenthesized, write_in_parentheses_only_group_end_tag,
|
in_parentheses_only_soft_line_break_or_space, is_expression_parenthesized,
|
||||||
write_in_parentheses_only_group_start_tag, Parentheses,
|
write_in_parentheses_only_group_end_tag, write_in_parentheses_only_group_start_tag,
|
||||||
|
Parentheses,
|
||||||
};
|
};
|
||||||
use crate::expression::OperatorPrecedence;
|
use crate::expression::OperatorPrecedence;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
@@ -287,7 +288,7 @@ impl Format<PyFormatContext<'_>> for BinaryLike<'_> {
|
|||||||
let flat_binary = self.flatten(&comments, f.context().source());
|
let flat_binary = self.flatten(&comments, f.context().source());
|
||||||
|
|
||||||
if self.is_bool_op() {
|
if self.is_bool_op() {
|
||||||
return in_parentheses_only_group(&&*flat_binary).fmt(f);
|
return in_parentheses_only_group(&flat_binary).fmt(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
let source = f.context().source();
|
let source = f.context().source();
|
||||||
@@ -481,7 +482,7 @@ impl Format<PyFormatContext<'_>> for BinaryLike<'_> {
|
|||||||
// Finish the group that wraps all implicit concatenated strings
|
// Finish the group that wraps all implicit concatenated strings
|
||||||
write_in_parentheses_only_group_end_tag(f);
|
write_in_parentheses_only_group_end_tag(f);
|
||||||
} else {
|
} else {
|
||||||
in_parentheses_only_group(&&*flat_binary).fmt(f)?;
|
in_parentheses_only_group(&flat_binary).fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -527,6 +528,12 @@ impl<'a> Deref for FlatBinaryExpression<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Format<PyFormatContext<'_>> for FlatBinaryExpression<'_> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
||||||
|
Format::fmt(&**self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Binary chain represented as a flat vector where operands are stored at even indices and operators
|
/// Binary chain represented as a flat vector where operands are stored at even indices and operators
|
||||||
/// add odd indices.
|
/// add odd indices.
|
||||||
///
|
///
|
||||||
@@ -642,7 +649,7 @@ impl<'a> FlatBinaryExpressionSlice<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Formats a binary chain slice by inserting soft line breaks before the lowest-precedence operators.
|
/// Formats a binary chain slice by inserting soft line breaks before the lowest-precedence operators.
|
||||||
/// In other words: It splits the line before by the lowest precedence operators (and it either splits
|
/// In other words: It splits the line before the lowest precedence operators (and it either splits
|
||||||
/// all of them or none). For example, the lowest precedence operator for `a + b * c + d` is the `+` operator.
|
/// all of them or none). For example, the lowest precedence operator for `a + b * c + d` is the `+` operator.
|
||||||
/// The expression either gets formatted as `a + b * c + d` if it fits on the line or as
|
/// The expression either gets formatted as `a + b * c + d` if it fits on the line or as
|
||||||
/// ```python
|
/// ```python
|
||||||
@@ -678,59 +685,64 @@ impl Format<PyFormatContext<'_>> for FlatBinaryExpressionSlice<'_> {
|
|||||||
let mut last_operator: Option<OperatorIndex> = None;
|
let mut last_operator: Option<OperatorIndex> = None;
|
||||||
|
|
||||||
let lowest_precedence = self.lowest_precedence();
|
let lowest_precedence = self.lowest_precedence();
|
||||||
|
let lowest_precedence_operators = self
|
||||||
|
.operators()
|
||||||
|
.filter(|(_, operator)| operator.precedence() == lowest_precedence);
|
||||||
|
|
||||||
for (index, operator_part) in self.operators() {
|
for (index, operator_part) in lowest_precedence_operators {
|
||||||
if operator_part.precedence() == lowest_precedence {
|
let left = self.between_operators(last_operator, index);
|
||||||
let left = self.between_operators(last_operator, index);
|
let right = self.after_operator(index);
|
||||||
let right = self.after_operator(index);
|
|
||||||
|
|
||||||
let is_pow = operator_part.symbol.is_pow()
|
let is_pow = operator_part.symbol.is_pow()
|
||||||
&& is_simple_power_expression(
|
&& is_simple_power_expression(
|
||||||
left.last_operand().expression(),
|
left.last_operand().expression(),
|
||||||
right.first_operand().expression(),
|
right.first_operand().expression(),
|
||||||
f.context().comments().ranges(),
|
f.context().comments().ranges(),
|
||||||
f.context().source(),
|
f.context().source(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(leading) = left.first_operand().leading_binary_comments() {
|
if let Some(leading) = left.first_operand().leading_binary_comments() {
|
||||||
leading_comments(leading).fmt(f)?;
|
leading_comments(leading).fmt(f)?;
|
||||||
}
|
|
||||||
|
|
||||||
match &left.0 {
|
|
||||||
[OperandOrOperator::Operand(operand)] => operand.fmt(f)?,
|
|
||||||
_ => in_parentheses_only_group(&left).fmt(f)?,
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(trailing) = left.last_operand().trailing_binary_comments() {
|
|
||||||
trailing_comments(trailing).fmt(f)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if is_pow {
|
|
||||||
in_parentheses_only_soft_line_break().fmt(f)?;
|
|
||||||
} else {
|
|
||||||
in_parentheses_only_soft_line_break_or_space().fmt(f)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator_part.fmt(f)?;
|
|
||||||
|
|
||||||
// Format the operator on its own line if the right side has any leading comments.
|
|
||||||
if operator_part.has_trailing_comments()
|
|
||||||
|| right.first_operand().has_unparenthesized_leading_comments(
|
|
||||||
f.context().comments(),
|
|
||||||
f.context().source(),
|
|
||||||
)
|
|
||||||
{
|
|
||||||
hard_line_break().fmt(f)?;
|
|
||||||
} else if is_pow {
|
|
||||||
if is_fix_power_op_line_length_enabled(f.context()) {
|
|
||||||
in_parentheses_only_if_group_breaks(&space()).fmt(f)?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
space().fmt(f)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
last_operator = Some(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match &left.0 {
|
||||||
|
[OperandOrOperator::Operand(operand)] => operand.fmt(f)?,
|
||||||
|
_ => in_parentheses_only_group(&left).fmt(f)?,
|
||||||
|
}
|
||||||
|
|
||||||
|
if last_operator.is_none() {
|
||||||
|
in_parentheses_only_indent_start().fmt(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(trailing) = left.last_operand().trailing_binary_comments() {
|
||||||
|
trailing_comments(trailing).fmt(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_pow {
|
||||||
|
in_parentheses_only_soft_line_break().fmt(f)?;
|
||||||
|
} else {
|
||||||
|
in_parentheses_only_soft_line_break_or_space().fmt(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator_part.fmt(f)?;
|
||||||
|
|
||||||
|
// Format the operator on its own line if the right side has any leading comments.
|
||||||
|
if operator_part.has_trailing_comments()
|
||||||
|
|| right.first_operand().has_unparenthesized_leading_comments(
|
||||||
|
f.context().comments(),
|
||||||
|
f.context().source(),
|
||||||
|
)
|
||||||
|
{
|
||||||
|
hard_line_break().fmt(f)?;
|
||||||
|
} else if is_pow {
|
||||||
|
if is_fix_power_op_line_length_enabled(f.context()) {
|
||||||
|
in_parentheses_only_if_group_breaks(&space()).fmt(f)?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
space().fmt(f)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
last_operator = Some(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the last right side
|
// Format the last right side
|
||||||
@@ -745,9 +757,11 @@ impl Format<PyFormatContext<'_>> for FlatBinaryExpressionSlice<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match &right.0 {
|
match &right.0 {
|
||||||
[OperandOrOperator::Operand(operand)] => operand.fmt(f),
|
[OperandOrOperator::Operand(operand)] => operand.fmt(f)?,
|
||||||
_ => in_parentheses_only_group(&right).fmt(f),
|
_ => in_parentheses_only_group(&right).fmt(f)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
in_parentheses_only_indent_end().fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -379,6 +379,42 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn in_parentheses_only_indent_start<'a>() -> impl Format<PyFormatContext<'a>> {
|
||||||
|
format_with(|f: &mut PyFormatter| {
|
||||||
|
match f.context().node_level() {
|
||||||
|
NodeLevel::TopLevel(_) | NodeLevel::CompoundStatement | NodeLevel::Expression(None) => {
|
||||||
|
// no-op, not parenthesized
|
||||||
|
}
|
||||||
|
NodeLevel::Expression(Some(parentheses_id)) => f.write_element(FormatElement::Tag(
|
||||||
|
Tag::StartIndentIfGroupBreaks(parentheses_id),
|
||||||
|
)),
|
||||||
|
NodeLevel::ParenthesizedExpression => {
|
||||||
|
f.write_element(FormatElement::Tag(Tag::StartIndent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn in_parentheses_only_indent_end<'a>() -> impl Format<PyFormatContext<'a>> {
|
||||||
|
format_with(|f: &mut PyFormatter| {
|
||||||
|
match f.context().node_level() {
|
||||||
|
NodeLevel::TopLevel(_) | NodeLevel::CompoundStatement | NodeLevel::Expression(None) => {
|
||||||
|
// no-op, not parenthesized
|
||||||
|
}
|
||||||
|
NodeLevel::Expression(Some(_)) => {
|
||||||
|
f.write_element(FormatElement::Tag(Tag::EndIndentIfGroupBreaks))
|
||||||
|
}
|
||||||
|
NodeLevel::ParenthesizedExpression => {
|
||||||
|
f.write_element(FormatElement::Tag(Tag::EndIndent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Format comments inside empty parentheses, brackets or curly braces.
|
/// Format comments inside empty parentheses, brackets or curly braces.
|
||||||
///
|
///
|
||||||
/// Empty `()`, `[]` and `{}` are special because there can be dangling comments, and they can be in
|
/// Empty `()`, `[]` and `{}` are special because there can be dangling comments, and they can be in
|
||||||
|
|||||||
@@ -1,220 +0,0 @@
|
|||||||
use std::iter::FusedIterator;
|
|
||||||
|
|
||||||
use memchr::memchr2;
|
|
||||||
|
|
||||||
use ruff_python_ast::{
|
|
||||||
self as ast, AnyNodeRef, Expr, ExprBytesLiteral, ExprFString, ExprStringLiteral, ExpressionRef,
|
|
||||||
StringLiteral,
|
|
||||||
};
|
|
||||||
use ruff_source_file::Locator;
|
|
||||||
use ruff_text_size::{Ranged, TextLen, TextRange};
|
|
||||||
|
|
||||||
use crate::expression::expr_f_string::f_string_quoting;
|
|
||||||
use crate::other::f_string::FormatFString;
|
|
||||||
use crate::other::string_literal::{FormatStringLiteral, StringLiteralKind};
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::string::{Quoting, StringPrefix, StringQuotes};
|
|
||||||
|
|
||||||
/// Represents any kind of string expression. This could be either a string,
|
|
||||||
/// bytes or f-string.
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
|
||||||
pub(crate) enum AnyString<'a> {
|
|
||||||
String(&'a ExprStringLiteral),
|
|
||||||
Bytes(&'a ExprBytesLiteral),
|
|
||||||
FString(&'a ExprFString),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> AnyString<'a> {
|
|
||||||
/// Creates a new [`AnyString`] from the given [`Expr`].
|
|
||||||
///
|
|
||||||
/// Returns `None` if the expression is not either a string, bytes or f-string.
|
|
||||||
pub(crate) fn from_expression(expression: &'a Expr) -> Option<AnyString<'a>> {
|
|
||||||
match expression {
|
|
||||||
Expr::StringLiteral(string) => Some(AnyString::String(string)),
|
|
||||||
Expr::BytesLiteral(bytes) => Some(AnyString::Bytes(bytes)),
|
|
||||||
Expr::FString(fstring) => Some(AnyString::FString(fstring)),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if the string is implicitly concatenated.
|
|
||||||
pub(crate) fn is_implicit_concatenated(self) -> bool {
|
|
||||||
match self {
|
|
||||||
Self::String(ExprStringLiteral { value, .. }) => value.is_implicit_concatenated(),
|
|
||||||
Self::Bytes(ExprBytesLiteral { value, .. }) => value.is_implicit_concatenated(),
|
|
||||||
Self::FString(ExprFString { value, .. }) => value.is_implicit_concatenated(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the quoting to be used for this string.
|
|
||||||
pub(super) fn quoting(self, locator: &Locator<'_>) -> Quoting {
|
|
||||||
match self {
|
|
||||||
Self::String(_) | Self::Bytes(_) => Quoting::CanChange,
|
|
||||||
Self::FString(f_string) => f_string_quoting(f_string, locator),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a vector of all the [`AnyStringPart`] of this string.
|
|
||||||
pub(super) fn parts(self, quoting: Quoting) -> AnyStringPartsIter<'a> {
|
|
||||||
match self {
|
|
||||||
Self::String(ExprStringLiteral { value, .. }) => {
|
|
||||||
AnyStringPartsIter::String(value.iter())
|
|
||||||
}
|
|
||||||
Self::Bytes(ExprBytesLiteral { value, .. }) => AnyStringPartsIter::Bytes(value.iter()),
|
|
||||||
Self::FString(ExprFString { value, .. }) => {
|
|
||||||
AnyStringPartsIter::FString(value.iter(), quoting)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn is_multiline(self, source: &str) -> bool {
|
|
||||||
match self {
|
|
||||||
AnyString::String(_) | AnyString::Bytes(_) => {
|
|
||||||
let contents = &source[self.range()];
|
|
||||||
let prefix = StringPrefix::parse(contents);
|
|
||||||
let quotes = StringQuotes::parse(
|
|
||||||
&contents[TextRange::new(prefix.text_len(), contents.text_len())],
|
|
||||||
);
|
|
||||||
|
|
||||||
quotes.is_some_and(StringQuotes::is_triple)
|
|
||||||
&& memchr2(b'\n', b'\r', contents.as_bytes()).is_some()
|
|
||||||
}
|
|
||||||
AnyString::FString(fstring) => {
|
|
||||||
memchr2(b'\n', b'\r', source[fstring.range].as_bytes()).is_some()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ranged for AnyString<'_> {
|
|
||||||
fn range(&self) -> TextRange {
|
|
||||||
match self {
|
|
||||||
Self::String(expr) => expr.range(),
|
|
||||||
Self::Bytes(expr) => expr.range(),
|
|
||||||
Self::FString(expr) => expr.range(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&AnyString<'a>> for AnyNodeRef<'a> {
|
|
||||||
fn from(value: &AnyString<'a>) -> Self {
|
|
||||||
match value {
|
|
||||||
AnyString::String(expr) => AnyNodeRef::ExprStringLiteral(expr),
|
|
||||||
AnyString::Bytes(expr) => AnyNodeRef::ExprBytesLiteral(expr),
|
|
||||||
AnyString::FString(expr) => AnyNodeRef::ExprFString(expr),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<AnyString<'a>> for AnyNodeRef<'a> {
|
|
||||||
fn from(value: AnyString<'a>) -> Self {
|
|
||||||
AnyNodeRef::from(&value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&AnyString<'a>> for ExpressionRef<'a> {
|
|
||||||
fn from(value: &AnyString<'a>) -> Self {
|
|
||||||
match value {
|
|
||||||
AnyString::String(expr) => ExpressionRef::StringLiteral(expr),
|
|
||||||
AnyString::Bytes(expr) => ExpressionRef::BytesLiteral(expr),
|
|
||||||
AnyString::FString(expr) => ExpressionRef::FString(expr),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub(super) enum AnyStringPartsIter<'a> {
|
|
||||||
String(std::slice::Iter<'a, StringLiteral>),
|
|
||||||
Bytes(std::slice::Iter<'a, ast::BytesLiteral>),
|
|
||||||
FString(std::slice::Iter<'a, ast::FStringPart>, Quoting),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for AnyStringPartsIter<'a> {
|
|
||||||
type Item = AnyStringPart<'a>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
let part = match self {
|
|
||||||
Self::String(inner) => {
|
|
||||||
let part = inner.next()?;
|
|
||||||
AnyStringPart::String {
|
|
||||||
part,
|
|
||||||
layout: StringLiteralKind::String,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Self::Bytes(inner) => AnyStringPart::Bytes(inner.next()?),
|
|
||||||
Self::FString(inner, quoting) => {
|
|
||||||
let part = inner.next()?;
|
|
||||||
match part {
|
|
||||||
ast::FStringPart::Literal(string_literal) => AnyStringPart::String {
|
|
||||||
part: string_literal,
|
|
||||||
layout: StringLiteralKind::InImplicitlyConcatenatedFString(*quoting),
|
|
||||||
},
|
|
||||||
ast::FStringPart::FString(f_string) => AnyStringPart::FString {
|
|
||||||
part: f_string,
|
|
||||||
quoting: *quoting,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(part)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FusedIterator for AnyStringPartsIter<'_> {}
|
|
||||||
|
|
||||||
/// Represents any kind of string which is part of an implicitly concatenated
|
|
||||||
/// string. This could be either a string, bytes or f-string.
|
|
||||||
///
|
|
||||||
/// This is constructed from the [`AnyString::parts`] method on [`AnyString`].
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub(super) enum AnyStringPart<'a> {
|
|
||||||
String {
|
|
||||||
part: &'a ast::StringLiteral,
|
|
||||||
layout: StringLiteralKind,
|
|
||||||
},
|
|
||||||
Bytes(&'a ast::BytesLiteral),
|
|
||||||
FString {
|
|
||||||
part: &'a ast::FString,
|
|
||||||
quoting: Quoting,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnyStringPart<'_> {
|
|
||||||
pub(super) fn is_multiline(self, source: &str) -> bool {
|
|
||||||
let text = &source[self.range()];
|
|
||||||
memchr2(b'\n', b'\r', text.as_bytes()).is_some()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&AnyStringPart<'a>> for AnyNodeRef<'a> {
|
|
||||||
fn from(value: &AnyStringPart<'a>) -> Self {
|
|
||||||
match value {
|
|
||||||
AnyStringPart::String { part, .. } => AnyNodeRef::StringLiteral(part),
|
|
||||||
AnyStringPart::Bytes(part) => AnyNodeRef::BytesLiteral(part),
|
|
||||||
AnyStringPart::FString { part, .. } => AnyNodeRef::FString(part),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ranged for AnyStringPart<'_> {
|
|
||||||
fn range(&self) -> TextRange {
|
|
||||||
match self {
|
|
||||||
Self::String { part, .. } => part.range(),
|
|
||||||
Self::Bytes(part) => part.range(),
|
|
||||||
Self::FString { part, .. } => part.range(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Format<PyFormatContext<'_>> for AnyStringPart<'_> {
|
|
||||||
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
|
||||||
match self {
|
|
||||||
AnyStringPart::String { part, layout } => {
|
|
||||||
FormatStringLiteral::new(part, *layout).fmt(f)
|
|
||||||
}
|
|
||||||
AnyStringPart::Bytes(bytes_literal) => bytes_literal.format().fmt(f),
|
|
||||||
AnyStringPart::FString { part, quoting } => FormatFString::new(part, *quoting).fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -109,7 +109,7 @@ use super::{NormalizedString, QuoteChar};
|
|||||||
/// `indent-width * spaces` to tabs because doing so could break ASCII art and other docstrings
|
/// `indent-width * spaces` to tabs because doing so could break ASCII art and other docstrings
|
||||||
/// that use spaces for alignment.
|
/// that use spaces for alignment.
|
||||||
pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> FormatResult<()> {
|
pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
let docstring = &normalized.text();
|
let docstring = &normalized.text;
|
||||||
|
|
||||||
// Black doesn't change the indentation of docstrings that contain an escaped newline
|
// Black doesn't change the indentation of docstrings that contain an escaped newline
|
||||||
if contains_unescaped_newline(docstring) {
|
if contains_unescaped_newline(docstring) {
|
||||||
@@ -125,7 +125,7 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||||||
let mut lines = docstring.split('\n').peekable();
|
let mut lines = docstring.split('\n').peekable();
|
||||||
|
|
||||||
// Start the string
|
// Start the string
|
||||||
write!(f, [normalized.prefix(), normalized.quotes()])?;
|
write!(f, [normalized.prefix, normalized.quotes])?;
|
||||||
// We track where in the source docstring we are (in source code byte offsets)
|
// We track where in the source docstring we are (in source code byte offsets)
|
||||||
let mut offset = normalized.start();
|
let mut offset = normalized.start();
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||||||
|
|
||||||
// Edge case: The first line is `""" "content`, so we need to insert chaperone space that keep
|
// Edge case: The first line is `""" "content`, so we need to insert chaperone space that keep
|
||||||
// inner quotes and closing quotes from getting to close to avoid `""""content`
|
// inner quotes and closing quotes from getting to close to avoid `""""content`
|
||||||
if trim_both.starts_with(normalized.quotes().quote_char.as_char()) {
|
if trim_both.starts_with(normalized.quotes.quote_char.as_char()) {
|
||||||
space().fmt(f)?;
|
space().fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||||||
{
|
{
|
||||||
space().fmt(f)?;
|
space().fmt(f)?;
|
||||||
}
|
}
|
||||||
normalized.quotes().fmt(f)?;
|
normalized.quotes.fmt(f)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||||||
offset,
|
offset,
|
||||||
stripped_indentation,
|
stripped_indentation,
|
||||||
already_normalized,
|
already_normalized,
|
||||||
quote_char: normalized.quotes().quote_char,
|
quote_char: normalized.quotes.quote_char,
|
||||||
code_example: CodeExample::default(),
|
code_example: CodeExample::default(),
|
||||||
}
|
}
|
||||||
.add_iter(lines)?;
|
.add_iter(lines)?;
|
||||||
@@ -207,7 +207,7 @@ pub(crate) fn format(normalized: &NormalizedString, f: &mut PyFormatter) -> Form
|
|||||||
space().fmt(f)?;
|
space().fmt(f)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(f, [normalized.quotes()])
|
write!(f, [normalized.quotes])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_unescaped_newline(haystack: &str) -> bool {
|
fn contains_unescaped_newline(haystack: &str) -> bool {
|
||||||
@@ -1569,7 +1569,7 @@ fn docstring_format_source(
|
|||||||
/// that avoids `content""""` and `content\"""`. This does only applies to un-escaped backslashes,
|
/// that avoids `content""""` and `content\"""`. This does only applies to un-escaped backslashes,
|
||||||
/// so `content\\ """` doesn't need a space while `content\\\ """` does.
|
/// so `content\\ """` doesn't need a space while `content\\\ """` does.
|
||||||
fn needs_chaperone_space(normalized: &NormalizedString, trim_end: &str) -> bool {
|
fn needs_chaperone_space(normalized: &NormalizedString, trim_end: &str) -> bool {
|
||||||
trim_end.ends_with(normalized.quotes().quote_char.as_char())
|
trim_end.ends_with(normalized.quotes.quote_char.as_char())
|
||||||
|| trim_end.chars().rev().take_while(|c| *c == '\\').count() % 2 == 1
|
|| trim_end.chars().rev().take_while(|c| *c == '\\').count() % 2 == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,27 @@
|
|||||||
use bitflags::bitflags;
|
use std::borrow::Cow;
|
||||||
|
use std::iter::FusedIterator;
|
||||||
|
|
||||||
|
use bitflags::bitflags;
|
||||||
|
use memchr::memchr2;
|
||||||
|
|
||||||
pub(crate) use any::AnyString;
|
|
||||||
pub(crate) use normalize::{NormalizedString, StringNormalizer};
|
|
||||||
use ruff_formatter::{format_args, write};
|
use ruff_formatter::{format_args, write};
|
||||||
|
use ruff_python_ast::{
|
||||||
|
self as ast, Expr, ExprBytesLiteral, ExprFString, ExprStringLiteral, ExpressionRef,
|
||||||
|
};
|
||||||
|
use ruff_python_ast::{AnyNodeRef, StringLiteral};
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||||
|
|
||||||
use crate::comments::{leading_comments, trailing_comments};
|
use crate::comments::{leading_comments, trailing_comments};
|
||||||
|
use crate::expression::expr_f_string::f_string_quoting;
|
||||||
use crate::expression::parentheses::in_parentheses_only_soft_line_break_or_space;
|
use crate::expression::parentheses::in_parentheses_only_soft_line_break_or_space;
|
||||||
|
use crate::other::f_string::FormatFString;
|
||||||
|
use crate::other::string_literal::{FormatStringLiteral, StringLiteralKind};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::preview::is_hex_codes_in_unicode_sequences_enabled;
|
||||||
use crate::QuoteStyle;
|
use crate::QuoteStyle;
|
||||||
|
|
||||||
mod any;
|
|
||||||
pub(crate) mod docstring;
|
pub(crate) mod docstring;
|
||||||
mod normalize;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub(crate) enum Quoting {
|
pub(crate) enum Quoting {
|
||||||
@@ -22,6 +30,202 @@ pub(crate) enum Quoting {
|
|||||||
Preserve,
|
Preserve,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents any kind of string expression. This could be either a string,
|
||||||
|
/// bytes or f-string.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub(crate) enum AnyString<'a> {
|
||||||
|
String(&'a ExprStringLiteral),
|
||||||
|
Bytes(&'a ExprBytesLiteral),
|
||||||
|
FString(&'a ExprFString),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AnyString<'a> {
|
||||||
|
/// Creates a new [`AnyString`] from the given [`Expr`].
|
||||||
|
///
|
||||||
|
/// Returns `None` if the expression is not either a string, bytes or f-string.
|
||||||
|
pub(crate) fn from_expression(expression: &'a Expr) -> Option<AnyString<'a>> {
|
||||||
|
match expression {
|
||||||
|
Expr::StringLiteral(string) => Some(AnyString::String(string)),
|
||||||
|
Expr::BytesLiteral(bytes) => Some(AnyString::Bytes(bytes)),
|
||||||
|
Expr::FString(fstring) => Some(AnyString::FString(fstring)),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the string is implicitly concatenated.
|
||||||
|
pub(crate) fn is_implicit_concatenated(self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::String(ExprStringLiteral { value, .. }) => value.is_implicit_concatenated(),
|
||||||
|
Self::Bytes(ExprBytesLiteral { value, .. }) => value.is_implicit_concatenated(),
|
||||||
|
Self::FString(ExprFString { value, .. }) => value.is_implicit_concatenated(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the quoting to be used for this string.
|
||||||
|
fn quoting(self, locator: &Locator<'_>) -> Quoting {
|
||||||
|
match self {
|
||||||
|
Self::String(_) | Self::Bytes(_) => Quoting::CanChange,
|
||||||
|
Self::FString(f_string) => f_string_quoting(f_string, locator),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a vector of all the [`AnyStringPart`] of this string.
|
||||||
|
fn parts(self, quoting: Quoting) -> AnyStringPartsIter<'a> {
|
||||||
|
match self {
|
||||||
|
Self::String(ExprStringLiteral { value, .. }) => {
|
||||||
|
AnyStringPartsIter::String(value.iter())
|
||||||
|
}
|
||||||
|
Self::Bytes(ExprBytesLiteral { value, .. }) => AnyStringPartsIter::Bytes(value.iter()),
|
||||||
|
Self::FString(ExprFString { value, .. }) => {
|
||||||
|
AnyStringPartsIter::FString(value.iter(), quoting)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_multiline(self, source: &str) -> bool {
|
||||||
|
match self {
|
||||||
|
AnyString::String(_) | AnyString::Bytes(_) => {
|
||||||
|
let contents = &source[self.range()];
|
||||||
|
let prefix = StringPrefix::parse(contents);
|
||||||
|
let quotes = StringQuotes::parse(
|
||||||
|
&contents[TextRange::new(prefix.text_len(), contents.text_len())],
|
||||||
|
);
|
||||||
|
|
||||||
|
quotes.is_some_and(StringQuotes::is_triple)
|
||||||
|
&& memchr2(b'\n', b'\r', contents.as_bytes()).is_some()
|
||||||
|
}
|
||||||
|
AnyString::FString(fstring) => {
|
||||||
|
memchr2(b'\n', b'\r', source[fstring.range].as_bytes()).is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ranged for AnyString<'_> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
match self {
|
||||||
|
Self::String(expr) => expr.range(),
|
||||||
|
Self::Bytes(expr) => expr.range(),
|
||||||
|
Self::FString(expr) => expr.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&AnyString<'a>> for AnyNodeRef<'a> {
|
||||||
|
fn from(value: &AnyString<'a>) -> Self {
|
||||||
|
match value {
|
||||||
|
AnyString::String(expr) => AnyNodeRef::ExprStringLiteral(expr),
|
||||||
|
AnyString::Bytes(expr) => AnyNodeRef::ExprBytesLiteral(expr),
|
||||||
|
AnyString::FString(expr) => AnyNodeRef::ExprFString(expr),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<AnyString<'a>> for AnyNodeRef<'a> {
|
||||||
|
fn from(value: AnyString<'a>) -> Self {
|
||||||
|
AnyNodeRef::from(&value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&AnyString<'a>> for ExpressionRef<'a> {
|
||||||
|
fn from(value: &AnyString<'a>) -> Self {
|
||||||
|
match value {
|
||||||
|
AnyString::String(expr) => ExpressionRef::StringLiteral(expr),
|
||||||
|
AnyString::Bytes(expr) => ExpressionRef::BytesLiteral(expr),
|
||||||
|
AnyString::FString(expr) => ExpressionRef::FString(expr),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum AnyStringPartsIter<'a> {
|
||||||
|
String(std::slice::Iter<'a, StringLiteral>),
|
||||||
|
Bytes(std::slice::Iter<'a, ast::BytesLiteral>),
|
||||||
|
FString(std::slice::Iter<'a, ast::FStringPart>, Quoting),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for AnyStringPartsIter<'a> {
|
||||||
|
type Item = AnyStringPart<'a>;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let part = match self {
|
||||||
|
Self::String(inner) => {
|
||||||
|
let part = inner.next()?;
|
||||||
|
AnyStringPart::String {
|
||||||
|
part,
|
||||||
|
layout: StringLiteralKind::String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self::Bytes(inner) => AnyStringPart::Bytes(inner.next()?),
|
||||||
|
Self::FString(inner, quoting) => {
|
||||||
|
let part = inner.next()?;
|
||||||
|
match part {
|
||||||
|
ast::FStringPart::Literal(string_literal) => AnyStringPart::String {
|
||||||
|
part: string_literal,
|
||||||
|
layout: StringLiteralKind::InImplicitlyConcatenatedFString(*quoting),
|
||||||
|
},
|
||||||
|
ast::FStringPart::FString(f_string) => AnyStringPart::FString {
|
||||||
|
part: f_string,
|
||||||
|
quoting: *quoting,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FusedIterator for AnyStringPartsIter<'_> {}
|
||||||
|
|
||||||
|
/// Represents any kind of string which is part of an implicitly concatenated
|
||||||
|
/// string. This could be either a string, bytes or f-string.
|
||||||
|
///
|
||||||
|
/// This is constructed from the [`AnyString::parts`] method on [`AnyString`].
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum AnyStringPart<'a> {
|
||||||
|
String {
|
||||||
|
part: &'a ast::StringLiteral,
|
||||||
|
layout: StringLiteralKind,
|
||||||
|
},
|
||||||
|
Bytes(&'a ast::BytesLiteral),
|
||||||
|
FString {
|
||||||
|
part: &'a ast::FString,
|
||||||
|
quoting: Quoting,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&AnyStringPart<'a>> for AnyNodeRef<'a> {
|
||||||
|
fn from(value: &AnyStringPart<'a>) -> Self {
|
||||||
|
match value {
|
||||||
|
AnyStringPart::String { part, .. } => AnyNodeRef::StringLiteral(part),
|
||||||
|
AnyStringPart::Bytes(part) => AnyNodeRef::BytesLiteral(part),
|
||||||
|
AnyStringPart::FString { part, .. } => AnyNodeRef::FString(part),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ranged for AnyStringPart<'_> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
match self {
|
||||||
|
Self::String { part, .. } => part.range(),
|
||||||
|
Self::Bytes(part) => part.range(),
|
||||||
|
Self::FString { part, .. } => part.range(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Format<PyFormatContext<'_>> for AnyStringPart<'_> {
|
||||||
|
fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
|
match self {
|
||||||
|
AnyStringPart::String { part, layout } => {
|
||||||
|
FormatStringLiteral::new(part, *layout).fmt(f)
|
||||||
|
}
|
||||||
|
AnyStringPart::Bytes(bytes_literal) => bytes_literal.format().fmt(f),
|
||||||
|
AnyStringPart::FString { part, quoting } => FormatFString::new(part, *quoting).fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Formats any implicitly concatenated string. This could be any valid combination
|
/// Formats any implicitly concatenated string. This could be any valid combination
|
||||||
/// of string, bytes or f-string literals.
|
/// of string, bytes or f-string literals.
|
||||||
pub(crate) struct FormatStringContinuation<'a> {
|
pub(crate) struct FormatStringContinuation<'a> {
|
||||||
@@ -39,120 +243,18 @@ impl Format<PyFormatContext<'_>> for FormatStringContinuation<'_> {
|
|||||||
let comments = f.context().comments().clone();
|
let comments = f.context().comments().clone();
|
||||||
let quoting = self.string.quoting(&f.context().locator());
|
let quoting = self.string.quoting(&f.context().locator());
|
||||||
|
|
||||||
let parts = self.string.parts(quoting);
|
let mut joiner = f.join_with(in_parentheses_only_soft_line_break_or_space());
|
||||||
|
|
||||||
// Don't try the flat layout if it is know that the implicit string remains on multiple lines either because one
|
for part in self.string.parts(quoting) {
|
||||||
// part is a multline or a part has a leading or trailing comment.
|
joiner.entry(&format_args![
|
||||||
let should_try_flat = !parts.clone().any(|part| {
|
line_suffix_boundary(),
|
||||||
let part_comments = comments.leading_dangling_trailing(&part);
|
leading_comments(comments.leading(&part)),
|
||||||
|
part,
|
||||||
part.is_multiline(f.context().source())
|
trailing_comments(comments.trailing(&part))
|
||||||
|| part_comments.has_leading()
|
]);
|
||||||
|| part_comments.has_trailing()
|
|
||||||
});
|
|
||||||
|
|
||||||
let format_flat = format_with(|f: &mut PyFormatter| {
|
|
||||||
let mut merged_prefix = StringPrefix::empty();
|
|
||||||
let mut all_raw = true;
|
|
||||||
let quotes = parts.clone().next().map_or(
|
|
||||||
StringQuotes {
|
|
||||||
triple: false,
|
|
||||||
quote_char: QuoteChar::Double,
|
|
||||||
},
|
|
||||||
|part| StringPart::from_source(part.range(), &f.context().locator()).quotes,
|
|
||||||
);
|
|
||||||
|
|
||||||
for part in parts.clone() {
|
|
||||||
let string_part = StringPart::from_source(part.range(), &f.context().locator());
|
|
||||||
|
|
||||||
let prefix = string_part.prefix;
|
|
||||||
merged_prefix = prefix.union(merged_prefix);
|
|
||||||
all_raw &= prefix.is_raw_string();
|
|
||||||
|
|
||||||
// quotes are more complicated. We need to collect the statistics about the used quotes for each string
|
|
||||||
// - number of single quotes
|
|
||||||
// - number of double quotes
|
|
||||||
// - number of triple quotes
|
|
||||||
// And they need to be normalized as a second step
|
|
||||||
// Also requires tracking how many times a simple string uses an escaped triple quoted sequence to avoid
|
|
||||||
// stability issues.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prefer lower case raw string flags over uppercase if both are present.
|
|
||||||
if merged_prefix.contains(StringPrefix::RAW)
|
|
||||||
&& merged_prefix.contains(StringPrefix::RAW_UPPER)
|
|
||||||
{
|
|
||||||
merged_prefix.remove(StringPrefix::RAW_UPPER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the raw prefix if there's a mixture of raw and non-raw string. The formatting code coming later normalizes raw strings to regular
|
|
||||||
// strings if the flag isn't present.
|
|
||||||
if !all_raw {
|
|
||||||
merged_prefix.remove(StringPrefix::RAW);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need to find the common prefix and quotes for all parts and use that one.
|
|
||||||
// no prefix: easy
|
|
||||||
// bitflags! {
|
|
||||||
// #[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
||||||
// pub(crate) struct StringPrefix: u8 {
|
|
||||||
// const UNICODE = 0b0000_0001;
|
|
||||||
// /// `r"test"`
|
|
||||||
// const RAW = 0b0000_0010;
|
|
||||||
// /// `R"test"
|
|
||||||
// const RAW_UPPER = 0b0000_0100;
|
|
||||||
// const BYTE = 0b0000_1000;
|
|
||||||
// const F_STRING = 0b0001_0000;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Prefix precedence:
|
|
||||||
// - Unicode -> Always remove
|
|
||||||
// - Raw upper -> Remove except when all parts are raw upper
|
|
||||||
// - Raw -> Remove except when all parts are raw or raw upper.
|
|
||||||
// - F-String -> Preserve
|
|
||||||
// - Bytes -> Preserve
|
|
||||||
// Quotes:
|
|
||||||
// - Single quotes: Identify the number of single and double quotes in the string and use the one with the least count.
|
|
||||||
// - single and triple: Use triple quotes
|
|
||||||
// - triples: Use `choose_quote` for every part and use the one with the highest count
|
|
||||||
|
|
||||||
write!(f, [merged_prefix, quotes])?;
|
|
||||||
for part in parts.clone() {
|
|
||||||
let string_part = StringPart::from_source(part.range(), &f.context().locator());
|
|
||||||
|
|
||||||
write!(f, [source_text_slice(string_part.content_range)])?;
|
|
||||||
}
|
|
||||||
|
|
||||||
quotes.fmt(f)
|
|
||||||
});
|
|
||||||
|
|
||||||
let format_expanded = format_with(|f| {
|
|
||||||
let mut joiner = f.join_with(in_parentheses_only_soft_line_break_or_space());
|
|
||||||
|
|
||||||
for part in parts.clone() {
|
|
||||||
joiner.entry(&format_args![
|
|
||||||
line_suffix_boundary(),
|
|
||||||
leading_comments(comments.leading(&part)),
|
|
||||||
part,
|
|
||||||
trailing_comments(comments.trailing(&part))
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
joiner.finish()
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: where's the group coming from?
|
|
||||||
|
|
||||||
if should_try_flat {
|
|
||||||
group(&format_args![
|
|
||||||
if_group_fits_on_line(&format_flat),
|
|
||||||
if_group_breaks(&format_expanded)
|
|
||||||
])
|
|
||||||
.fmt(f)
|
|
||||||
} else {
|
|
||||||
format_expanded.fmt(f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joiner.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +308,167 @@ impl StringPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct StringNormalizer {
|
||||||
|
quoting: Quoting,
|
||||||
|
preferred_quote_style: QuoteStyle,
|
||||||
|
parent_docstring_quote_char: Option<QuoteChar>,
|
||||||
|
normalize_hex: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StringNormalizer {
|
||||||
|
pub(crate) fn from_context(context: &PyFormatContext<'_>) -> Self {
|
||||||
|
Self {
|
||||||
|
quoting: Quoting::default(),
|
||||||
|
preferred_quote_style: QuoteStyle::default(),
|
||||||
|
parent_docstring_quote_char: context.docstring(),
|
||||||
|
normalize_hex: is_hex_codes_in_unicode_sequences_enabled(context),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn with_preferred_quote_style(mut self, quote_style: QuoteStyle) -> Self {
|
||||||
|
self.preferred_quote_style = quote_style;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn with_quoting(mut self, quoting: Quoting) -> Self {
|
||||||
|
self.quoting = quoting;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Computes the strings preferred quotes.
|
||||||
|
pub(crate) fn choose_quotes(&self, string: &StringPart, locator: &Locator) -> StringQuotes {
|
||||||
|
// Per PEP 8, always prefer double quotes for triple-quoted strings.
|
||||||
|
// Except when using quote-style-preserve.
|
||||||
|
let preferred_style = if string.quotes().triple {
|
||||||
|
// ... unless we're formatting a code snippet inside a docstring,
|
||||||
|
// then we specifically want to invert our quote style to avoid
|
||||||
|
// writing out invalid Python.
|
||||||
|
//
|
||||||
|
// It's worth pointing out that we can actually wind up being
|
||||||
|
// somewhat out of sync with PEP8 in this case. Consider this
|
||||||
|
// example:
|
||||||
|
//
|
||||||
|
// def foo():
|
||||||
|
// '''
|
||||||
|
// Something.
|
||||||
|
//
|
||||||
|
// >>> """tricksy"""
|
||||||
|
// '''
|
||||||
|
// pass
|
||||||
|
//
|
||||||
|
// Ideally, this would be reformatted as:
|
||||||
|
//
|
||||||
|
// def foo():
|
||||||
|
// """
|
||||||
|
// Something.
|
||||||
|
//
|
||||||
|
// >>> '''tricksy'''
|
||||||
|
// """
|
||||||
|
// pass
|
||||||
|
//
|
||||||
|
// But the logic here results in the original quoting being
|
||||||
|
// preserved. This is because the quoting style of the outer
|
||||||
|
// docstring is determined, in part, by looking at its contents. In
|
||||||
|
// this case, it notices that it contains a `"""` and thus infers
|
||||||
|
// that using `'''` would overall read better because it avoids
|
||||||
|
// the need to escape the interior `"""`. Except... in this case,
|
||||||
|
// the `"""` is actually part of a code snippet that could get
|
||||||
|
// reformatted to using a different quoting style itself.
|
||||||
|
//
|
||||||
|
// Fixing this would, I believe, require some fairly seismic
|
||||||
|
// changes to how formatting strings works. Namely, we would need
|
||||||
|
// to look for code snippets before normalizing the docstring, and
|
||||||
|
// then figure out the quoting style more holistically by looking
|
||||||
|
// at the various kinds of quotes used in the code snippets and
|
||||||
|
// what reformatting them might look like.
|
||||||
|
//
|
||||||
|
// Overall this is a bit of a corner case and just inverting the
|
||||||
|
// style from what the parent ultimately decided upon works, even
|
||||||
|
// if it doesn't have perfect alignment with PEP8.
|
||||||
|
if let Some(quote) = self.parent_docstring_quote_char {
|
||||||
|
QuoteStyle::from(quote.invert())
|
||||||
|
} else if self.preferred_quote_style.is_preserve() {
|
||||||
|
QuoteStyle::Preserve
|
||||||
|
} else {
|
||||||
|
QuoteStyle::Double
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.preferred_quote_style
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.quoting {
|
||||||
|
Quoting::Preserve => string.quotes(),
|
||||||
|
Quoting::CanChange => {
|
||||||
|
if let Some(preferred_quote) = QuoteChar::from_style(preferred_style) {
|
||||||
|
let raw_content = locator.slice(string.content_range());
|
||||||
|
if string.prefix().is_raw_string() {
|
||||||
|
choose_quotes_for_raw_string(raw_content, string.quotes(), preferred_quote)
|
||||||
|
} else {
|
||||||
|
choose_quotes_impl(raw_content, string.quotes(), preferred_quote)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
string.quotes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Computes the strings preferred quotes and normalizes its content.
|
||||||
|
pub(crate) fn normalize<'a>(
|
||||||
|
&self,
|
||||||
|
string: &StringPart,
|
||||||
|
locator: &'a Locator,
|
||||||
|
) -> NormalizedString<'a> {
|
||||||
|
let raw_content = locator.slice(string.content_range());
|
||||||
|
|
||||||
|
let quotes = self.choose_quotes(string, locator);
|
||||||
|
|
||||||
|
let normalized = normalize_string(raw_content, quotes, string.prefix(), self.normalize_hex);
|
||||||
|
|
||||||
|
NormalizedString {
|
||||||
|
prefix: string.prefix(),
|
||||||
|
content_range: string.content_range(),
|
||||||
|
text: normalized,
|
||||||
|
quotes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct NormalizedString<'a> {
|
||||||
|
prefix: StringPrefix,
|
||||||
|
|
||||||
|
/// The quotes of the normalized string (preferred quotes)
|
||||||
|
quotes: StringQuotes,
|
||||||
|
|
||||||
|
/// The range of the string's content in the source (minus prefix and quotes).
|
||||||
|
content_range: TextRange,
|
||||||
|
|
||||||
|
/// The normalized text
|
||||||
|
text: Cow<'a, str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ranged for NormalizedString<'_> {
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.content_range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Format<PyFormatContext<'_>> for NormalizedString<'_> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
||||||
|
write!(f, [self.prefix, self.quotes])?;
|
||||||
|
match &self.text {
|
||||||
|
Cow::Borrowed(_) => {
|
||||||
|
source_text_slice(self.range()).fmt(f)?;
|
||||||
|
}
|
||||||
|
Cow::Owned(normalized) => {
|
||||||
|
text(normalized).fmt(f)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.quotes.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub(crate) struct StringPrefix: u8 {
|
pub(crate) struct StringPrefix: u8 {
|
||||||
@@ -286,6 +549,175 @@ impl Format<PyFormatContext<'_>> for StringPrefix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Choose the appropriate quote style for a raw string.
|
||||||
|
///
|
||||||
|
/// The preferred quote style is chosen unless the string contains unescaped quotes of the
|
||||||
|
/// preferred style. For example, `r"foo"` is chosen over `r'foo'` if the preferred quote
|
||||||
|
/// style is double quotes.
|
||||||
|
fn choose_quotes_for_raw_string(
|
||||||
|
input: &str,
|
||||||
|
quotes: StringQuotes,
|
||||||
|
preferred_quote: QuoteChar,
|
||||||
|
) -> StringQuotes {
|
||||||
|
let preferred_quote_char = preferred_quote.as_char();
|
||||||
|
let mut chars = input.chars().peekable();
|
||||||
|
let contains_unescaped_configured_quotes = loop {
|
||||||
|
match chars.next() {
|
||||||
|
Some('\\') => {
|
||||||
|
// Ignore escaped characters
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
// `"` or `'`
|
||||||
|
Some(c) if c == preferred_quote_char => {
|
||||||
|
if !quotes.triple {
|
||||||
|
break true;
|
||||||
|
}
|
||||||
|
|
||||||
|
match chars.peek() {
|
||||||
|
// We can't turn `r'''\""'''` into `r"""\"""""`, this would confuse the parser
|
||||||
|
// about where the closing triple quotes start
|
||||||
|
None => break true,
|
||||||
|
Some(next) if *next == preferred_quote_char => {
|
||||||
|
// `""` or `''`
|
||||||
|
chars.next();
|
||||||
|
|
||||||
|
// We can't turn `r'''""'''` into `r""""""""`, nor can we have
|
||||||
|
// `"""` or `'''` respectively inside the string
|
||||||
|
if chars.peek().is_none() || chars.peek() == Some(&preferred_quote_char) {
|
||||||
|
break true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(_) => continue,
|
||||||
|
None => break false,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StringQuotes {
|
||||||
|
triple: quotes.triple,
|
||||||
|
quote_char: if contains_unescaped_configured_quotes {
|
||||||
|
quotes.quote_char
|
||||||
|
} else {
|
||||||
|
preferred_quote
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Choose the appropriate quote style for a string.
|
||||||
|
///
|
||||||
|
/// For single quoted strings, the preferred quote style is used, unless the alternative quote style
|
||||||
|
/// would require fewer escapes.
|
||||||
|
///
|
||||||
|
/// For triple quoted strings, the preferred quote style is always used, unless the string contains
|
||||||
|
/// a triplet of the quote character (e.g., if double quotes are preferred, double quotes will be
|
||||||
|
/// used unless the string contains `"""`).
|
||||||
|
fn choose_quotes_impl(
|
||||||
|
input: &str,
|
||||||
|
quotes: StringQuotes,
|
||||||
|
preferred_quote: QuoteChar,
|
||||||
|
) -> StringQuotes {
|
||||||
|
let quote = if quotes.triple {
|
||||||
|
// True if the string contains a triple quote sequence of the configured quote style.
|
||||||
|
let mut uses_triple_quotes = false;
|
||||||
|
let mut chars = input.chars().peekable();
|
||||||
|
|
||||||
|
while let Some(c) = chars.next() {
|
||||||
|
let preferred_quote_char = preferred_quote.as_char();
|
||||||
|
match c {
|
||||||
|
'\\' => {
|
||||||
|
if matches!(chars.peek(), Some('"' | '\\')) {
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// `"` or `'`
|
||||||
|
c if c == preferred_quote_char => {
|
||||||
|
match chars.peek().copied() {
|
||||||
|
Some(c) if c == preferred_quote_char => {
|
||||||
|
// `""` or `''`
|
||||||
|
chars.next();
|
||||||
|
|
||||||
|
match chars.peek().copied() {
|
||||||
|
Some(c) if c == preferred_quote_char => {
|
||||||
|
// `"""` or `'''`
|
||||||
|
chars.next();
|
||||||
|
uses_triple_quotes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Some(_) => {}
|
||||||
|
None => {
|
||||||
|
// Handle `''' ""'''`. At this point we have consumed both
|
||||||
|
// double quotes, so on the next iteration the iterator is empty
|
||||||
|
// and we'd miss the string ending with a preferred quote
|
||||||
|
uses_triple_quotes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(_) => {
|
||||||
|
// A single quote char, this is ok
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// Trailing quote at the end of the comment
|
||||||
|
uses_triple_quotes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if uses_triple_quotes {
|
||||||
|
// String contains a triple quote sequence of the configured quote style.
|
||||||
|
// Keep the existing quote style.
|
||||||
|
quotes.quote_char
|
||||||
|
} else {
|
||||||
|
preferred_quote
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut single_quotes = 0u32;
|
||||||
|
let mut double_quotes = 0u32;
|
||||||
|
|
||||||
|
for c in input.chars() {
|
||||||
|
match c {
|
||||||
|
'\'' => {
|
||||||
|
single_quotes += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
'"' => {
|
||||||
|
double_quotes += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match preferred_quote {
|
||||||
|
QuoteChar::Single => {
|
||||||
|
if single_quotes > double_quotes {
|
||||||
|
QuoteChar::Double
|
||||||
|
} else {
|
||||||
|
QuoteChar::Single
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QuoteChar::Double => {
|
||||||
|
if double_quotes > single_quotes {
|
||||||
|
QuoteChar::Single
|
||||||
|
} else {
|
||||||
|
QuoteChar::Double
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
StringQuotes {
|
||||||
|
triple: quotes.triple,
|
||||||
|
quote_char: quote,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) struct StringQuotes {
|
pub(crate) struct StringQuotes {
|
||||||
triple: bool,
|
triple: bool,
|
||||||
@@ -389,3 +821,269 @@ impl TryFrom<char> for QuoteChar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds the necessary quote escapes and removes unnecessary escape sequences when quoting `input`
|
||||||
|
/// with the provided [`StringQuotes`] style.
|
||||||
|
///
|
||||||
|
/// Returns the normalized string and whether it contains new lines.
|
||||||
|
pub(crate) fn normalize_string(
|
||||||
|
input: &str,
|
||||||
|
quotes: StringQuotes,
|
||||||
|
prefix: StringPrefix,
|
||||||
|
normalize_hex: bool,
|
||||||
|
) -> Cow<str> {
|
||||||
|
// The normalized string if `input` is not yet normalized.
|
||||||
|
// `output` must remain empty if `input` is already normalized.
|
||||||
|
let mut output = String::new();
|
||||||
|
// Tracks the last index of `input` that has been written to `output`.
|
||||||
|
// If `last_index` is `0` at the end, then the input is already normalized and can be returned as is.
|
||||||
|
let mut last_index = 0;
|
||||||
|
|
||||||
|
let quote = quotes.quote_char;
|
||||||
|
let preferred_quote = quote.as_char();
|
||||||
|
let opposite_quote = quote.invert().as_char();
|
||||||
|
|
||||||
|
let mut chars = input.char_indices().peekable();
|
||||||
|
|
||||||
|
let is_raw = prefix.is_raw_string();
|
||||||
|
let is_fstring = prefix.is_fstring();
|
||||||
|
let mut formatted_value_nesting = 0u32;
|
||||||
|
|
||||||
|
while let Some((index, c)) = chars.next() {
|
||||||
|
if is_fstring && matches!(c, '{' | '}') {
|
||||||
|
if chars.peek().copied().is_some_and(|(_, next)| next == c) {
|
||||||
|
// Skip over the second character of the double braces
|
||||||
|
chars.next();
|
||||||
|
} else if c == '{' {
|
||||||
|
formatted_value_nesting += 1;
|
||||||
|
} else {
|
||||||
|
// Safe to assume that `c == '}'` here because of the matched pattern above
|
||||||
|
formatted_value_nesting = formatted_value_nesting.saturating_sub(1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if c == '\r' {
|
||||||
|
output.push_str(&input[last_index..index]);
|
||||||
|
|
||||||
|
// Skip over the '\r' character, keep the `\n`
|
||||||
|
if chars.peek().copied().is_some_and(|(_, next)| next == '\n') {
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
// Replace the `\r` with a `\n`
|
||||||
|
else {
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
last_index = index + '\r'.len_utf8();
|
||||||
|
} else if !is_raw {
|
||||||
|
if c == '\\' {
|
||||||
|
if let Some((_, next)) = chars.clone().next() {
|
||||||
|
if next == '\\' {
|
||||||
|
// Skip over escaped backslashes
|
||||||
|
chars.next();
|
||||||
|
} else if normalize_hex {
|
||||||
|
if let Some(normalised) = UnicodeEscape::new(next, !prefix.is_byte())
|
||||||
|
.and_then(|escape| {
|
||||||
|
escape.normalize(&input[index + c.len_utf8() + next.len_utf8()..])
|
||||||
|
})
|
||||||
|
{
|
||||||
|
// Length of the `\` plus the length of the escape sequence character (`u` | `U` | `x`)
|
||||||
|
let escape_start_len = '\\'.len_utf8() + next.len_utf8();
|
||||||
|
let escape_start_offset = index + escape_start_len;
|
||||||
|
if let Cow::Owned(normalised) = &normalised {
|
||||||
|
output.push_str(&input[last_index..escape_start_offset]);
|
||||||
|
output.push_str(normalised);
|
||||||
|
last_index = escape_start_offset + normalised.len();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Move the `chars` iterator passed the escape sequence.
|
||||||
|
// Simply reassigning `chars` doesn't work because the indices` would
|
||||||
|
// then be off.
|
||||||
|
for _ in 0..next.len_utf8() + normalised.len() {
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !quotes.triple {
|
||||||
|
#[allow(clippy::if_same_then_else)]
|
||||||
|
if next == opposite_quote && formatted_value_nesting == 0 {
|
||||||
|
// Remove the escape by ending before the backslash and starting again with the quote
|
||||||
|
chars.next();
|
||||||
|
output.push_str(&input[last_index..index]);
|
||||||
|
last_index = index + '\\'.len_utf8();
|
||||||
|
} else if next == preferred_quote {
|
||||||
|
// Quote is already escaped, skip over it.
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if !quotes.triple && c == preferred_quote && formatted_value_nesting == 0 {
|
||||||
|
// Escape the quote
|
||||||
|
output.push_str(&input[last_index..index]);
|
||||||
|
output.push('\\');
|
||||||
|
output.push(c);
|
||||||
|
last_index = index + preferred_quote.len_utf8();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalized = if last_index == 0 {
|
||||||
|
Cow::Borrowed(input)
|
||||||
|
} else {
|
||||||
|
output.push_str(&input[last_index..]);
|
||||||
|
Cow::Owned(output)
|
||||||
|
};
|
||||||
|
|
||||||
|
normalized
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
enum UnicodeEscape {
|
||||||
|
/// A hex escape sequence of either 2 (`\x`), 4 (`\u`) or 8 (`\U`) hex characters.
|
||||||
|
Hex(usize),
|
||||||
|
|
||||||
|
/// An escaped unicode name (`\N{name}`)
|
||||||
|
CharacterName,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnicodeEscape {
|
||||||
|
fn new(first: char, allow_unicode: bool) -> Option<UnicodeEscape> {
|
||||||
|
Some(match first {
|
||||||
|
'x' => UnicodeEscape::Hex(2),
|
||||||
|
'u' if allow_unicode => UnicodeEscape::Hex(4),
|
||||||
|
'U' if allow_unicode => UnicodeEscape::Hex(8),
|
||||||
|
'N' if allow_unicode => UnicodeEscape::CharacterName,
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalises `\u..`, `\U..`, `\x..` and `\N{..}` escape sequences to:
|
||||||
|
///
|
||||||
|
/// * `\u`, `\U'` and `\x`: To use lower case for the characters `a-f`.
|
||||||
|
/// * `\N`: To use uppercase letters
|
||||||
|
fn normalize(self, input: &str) -> Option<Cow<str>> {
|
||||||
|
let mut normalised = String::new();
|
||||||
|
|
||||||
|
let len = match self {
|
||||||
|
UnicodeEscape::Hex(len) => {
|
||||||
|
// It's not a valid escape sequence if the input string has fewer characters
|
||||||
|
// left than required by the escape sequence.
|
||||||
|
if input.len() < len {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index, c) in input.char_indices().take(len) {
|
||||||
|
match c {
|
||||||
|
'0'..='9' | 'a'..='f' => {
|
||||||
|
if !normalised.is_empty() {
|
||||||
|
normalised.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'A'..='F' => {
|
||||||
|
if normalised.is_empty() {
|
||||||
|
normalised.reserve(len);
|
||||||
|
normalised.push_str(&input[..index]);
|
||||||
|
normalised.push(c.to_ascii_lowercase());
|
||||||
|
} else {
|
||||||
|
normalised.push(c.to_ascii_lowercase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// not a valid escape sequence
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len
|
||||||
|
}
|
||||||
|
UnicodeEscape::CharacterName => {
|
||||||
|
let mut char_indices = input.char_indices();
|
||||||
|
|
||||||
|
if !matches!(char_indices.next(), Some((_, '{'))) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if let Some((index, c)) = char_indices.next() {
|
||||||
|
match c {
|
||||||
|
'}' => {
|
||||||
|
if !normalised.is_empty() {
|
||||||
|
normalised.push('}');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name must be at least two characters long.
|
||||||
|
if index < 3 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
break index + '}'.len_utf8();
|
||||||
|
}
|
||||||
|
'0'..='9' | 'A'..='Z' | ' ' | '-' => {
|
||||||
|
if !normalised.is_empty() {
|
||||||
|
normalised.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'a'..='z' => {
|
||||||
|
if normalised.is_empty() {
|
||||||
|
normalised.reserve(c.len_utf8() + '}'.len_utf8());
|
||||||
|
normalised.push_str(&input[..index]);
|
||||||
|
normalised.push(c.to_ascii_uppercase());
|
||||||
|
} else {
|
||||||
|
normalised.push(c.to_ascii_uppercase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Seems like an invalid escape sequence, don't normalise it.
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Unterminated escape sequence, don't normalise it.
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(if normalised.is_empty() {
|
||||||
|
Cow::Borrowed(&input[..len])
|
||||||
|
} else {
|
||||||
|
Cow::Owned(normalised)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::string::{normalize_string, QuoteChar, StringPrefix, StringQuotes, UnicodeEscape};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn normalize_32_escape() {
|
||||||
|
let escape_sequence = UnicodeEscape::new('U', true).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Some(Cow::Owned("0001f60e".to_string())),
|
||||||
|
escape_sequence.normalize("0001F60E")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn normalize_hex_in_byte_string() {
|
||||||
|
let input = r"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
||||||
|
|
||||||
|
let normalized = normalize_string(
|
||||||
|
input,
|
||||||
|
StringQuotes {
|
||||||
|
triple: false,
|
||||||
|
quote_char: QuoteChar::Double,
|
||||||
|
},
|
||||||
|
StringPrefix::BYTE,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(r"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", &normalized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,622 +0,0 @@
|
|||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use ruff_source_file::Locator;
|
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::preview::is_hex_codes_in_unicode_sequences_enabled;
|
|
||||||
use crate::string::{QuoteChar, Quoting, StringPart, StringPrefix, StringQuotes};
|
|
||||||
use crate::QuoteStyle;
|
|
||||||
|
|
||||||
pub(crate) struct StringNormalizer {
|
|
||||||
quoting: Quoting,
|
|
||||||
preferred_quote_style: QuoteStyle,
|
|
||||||
parent_docstring_quote_char: Option<QuoteChar>,
|
|
||||||
normalize_hex: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StringNormalizer {
|
|
||||||
pub(crate) fn from_context(context: &PyFormatContext<'_>) -> Self {
|
|
||||||
Self {
|
|
||||||
quoting: Quoting::default(),
|
|
||||||
preferred_quote_style: QuoteStyle::default(),
|
|
||||||
parent_docstring_quote_char: context.docstring(),
|
|
||||||
normalize_hex: is_hex_codes_in_unicode_sequences_enabled(context),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn with_preferred_quote_style(mut self, quote_style: QuoteStyle) -> Self {
|
|
||||||
self.preferred_quote_style = quote_style;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn with_quoting(mut self, quoting: Quoting) -> Self {
|
|
||||||
self.quoting = quoting;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Computes the strings preferred quotes.
|
|
||||||
pub(crate) fn choose_quotes(&self, string: &StringPart, locator: &Locator) -> StringQuotes {
|
|
||||||
// Per PEP 8, always prefer double quotes for triple-quoted strings.
|
|
||||||
// Except when using quote-style-preserve.
|
|
||||||
let preferred_style = if string.quotes().triple {
|
|
||||||
// ... unless we're formatting a code snippet inside a docstring,
|
|
||||||
// then we specifically want to invert our quote style to avoid
|
|
||||||
// writing out invalid Python.
|
|
||||||
//
|
|
||||||
// It's worth pointing out that we can actually wind up being
|
|
||||||
// somewhat out of sync with PEP8 in this case. Consider this
|
|
||||||
// example:
|
|
||||||
//
|
|
||||||
// def foo():
|
|
||||||
// '''
|
|
||||||
// Something.
|
|
||||||
//
|
|
||||||
// >>> """tricksy"""
|
|
||||||
// '''
|
|
||||||
// pass
|
|
||||||
//
|
|
||||||
// Ideally, this would be reformatted as:
|
|
||||||
//
|
|
||||||
// def foo():
|
|
||||||
// """
|
|
||||||
// Something.
|
|
||||||
//
|
|
||||||
// >>> '''tricksy'''
|
|
||||||
// """
|
|
||||||
// pass
|
|
||||||
//
|
|
||||||
// But the logic here results in the original quoting being
|
|
||||||
// preserved. This is because the quoting style of the outer
|
|
||||||
// docstring is determined, in part, by looking at its contents. In
|
|
||||||
// this case, it notices that it contains a `"""` and thus infers
|
|
||||||
// that using `'''` would overall read better because it avoids
|
|
||||||
// the need to escape the interior `"""`. Except... in this case,
|
|
||||||
// the `"""` is actually part of a code snippet that could get
|
|
||||||
// reformatted to using a different quoting style itself.
|
|
||||||
//
|
|
||||||
// Fixing this would, I believe, require some fairly seismic
|
|
||||||
// changes to how formatting strings works. Namely, we would need
|
|
||||||
// to look for code snippets before normalizing the docstring, and
|
|
||||||
// then figure out the quoting style more holistically by looking
|
|
||||||
// at the various kinds of quotes used in the code snippets and
|
|
||||||
// what reformatting them might look like.
|
|
||||||
//
|
|
||||||
// Overall this is a bit of a corner case and just inverting the
|
|
||||||
// style from what the parent ultimately decided upon works, even
|
|
||||||
// if it doesn't have perfect alignment with PEP8.
|
|
||||||
if let Some(quote) = self.parent_docstring_quote_char {
|
|
||||||
QuoteStyle::from(quote.invert())
|
|
||||||
} else if self.preferred_quote_style.is_preserve() {
|
|
||||||
QuoteStyle::Preserve
|
|
||||||
} else {
|
|
||||||
QuoteStyle::Double
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.preferred_quote_style
|
|
||||||
};
|
|
||||||
|
|
||||||
match self.quoting {
|
|
||||||
Quoting::Preserve => string.quotes(),
|
|
||||||
Quoting::CanChange => {
|
|
||||||
if let Some(preferred_quote) = QuoteChar::from_style(preferred_style) {
|
|
||||||
let raw_content = locator.slice(string.content_range());
|
|
||||||
if string.prefix().is_raw_string() {
|
|
||||||
choose_quotes_for_raw_string(raw_content, string.quotes(), preferred_quote)
|
|
||||||
} else {
|
|
||||||
choose_quotes_impl(raw_content, string.quotes(), preferred_quote)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
string.quotes()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Computes the strings preferred quotes and normalizes its content.
|
|
||||||
pub(crate) fn normalize<'a>(
|
|
||||||
&self,
|
|
||||||
string: &StringPart,
|
|
||||||
locator: &'a Locator,
|
|
||||||
) -> NormalizedString<'a> {
|
|
||||||
let raw_content = locator.slice(string.content_range());
|
|
||||||
|
|
||||||
let quotes = self.choose_quotes(string, locator);
|
|
||||||
|
|
||||||
let normalized = normalize_string(raw_content, quotes, string.prefix(), self.normalize_hex);
|
|
||||||
|
|
||||||
NormalizedString {
|
|
||||||
prefix: string.prefix(),
|
|
||||||
content_range: string.content_range(),
|
|
||||||
text: normalized,
|
|
||||||
quotes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct NormalizedString<'a> {
|
|
||||||
prefix: crate::string::StringPrefix,
|
|
||||||
|
|
||||||
/// The quotes of the normalized string (preferred quotes)
|
|
||||||
quotes: StringQuotes,
|
|
||||||
|
|
||||||
/// The range of the string's content in the source (minus prefix and quotes).
|
|
||||||
content_range: TextRange,
|
|
||||||
|
|
||||||
/// The normalized text
|
|
||||||
text: Cow<'a, str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> NormalizedString<'a> {
|
|
||||||
pub(crate) fn text(&self) -> &Cow<'a, str> {
|
|
||||||
&self.text
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn quotes(&self) -> StringQuotes {
|
|
||||||
self.quotes
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn prefix(&self) -> StringPrefix {
|
|
||||||
self.prefix
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ranged for NormalizedString<'_> {
|
|
||||||
fn range(&self) -> TextRange {
|
|
||||||
self.content_range
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Format<PyFormatContext<'_>> for NormalizedString<'_> {
|
|
||||||
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
|
||||||
ruff_formatter::write!(f, [self.prefix, self.quotes])?;
|
|
||||||
match &self.text {
|
|
||||||
Cow::Borrowed(_) => {
|
|
||||||
source_text_slice(self.range()).fmt(f)?;
|
|
||||||
}
|
|
||||||
Cow::Owned(normalized) => {
|
|
||||||
text(normalized).fmt(f)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.quotes.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Choose the appropriate quote style for a raw string.
|
|
||||||
///
|
|
||||||
/// The preferred quote style is chosen unless the string contains unescaped quotes of the
|
|
||||||
/// preferred style. For example, `r"foo"` is chosen over `r'foo'` if the preferred quote
|
|
||||||
/// style is double quotes.
|
|
||||||
fn choose_quotes_for_raw_string(
|
|
||||||
input: &str,
|
|
||||||
quotes: StringQuotes,
|
|
||||||
preferred_quote: QuoteChar,
|
|
||||||
) -> StringQuotes {
|
|
||||||
let preferred_quote_char = preferred_quote.as_char();
|
|
||||||
let mut chars = input.chars().peekable();
|
|
||||||
let contains_unescaped_configured_quotes = loop {
|
|
||||||
match chars.next() {
|
|
||||||
Some('\\') => {
|
|
||||||
// Ignore escaped characters
|
|
||||||
chars.next();
|
|
||||||
}
|
|
||||||
// `"` or `'`
|
|
||||||
Some(c) if c == preferred_quote_char => {
|
|
||||||
if !quotes.triple {
|
|
||||||
break true;
|
|
||||||
}
|
|
||||||
|
|
||||||
match chars.peek() {
|
|
||||||
// We can't turn `r'''\""'''` into `r"""\"""""`, this would confuse the parser
|
|
||||||
// about where the closing triple quotes start
|
|
||||||
None => break true,
|
|
||||||
Some(next) if *next == preferred_quote_char => {
|
|
||||||
// `""` or `''`
|
|
||||||
chars.next();
|
|
||||||
|
|
||||||
// We can't turn `r'''""'''` into `r""""""""`, nor can we have
|
|
||||||
// `"""` or `'''` respectively inside the string
|
|
||||||
if chars.peek().is_none() || chars.peek() == Some(&preferred_quote_char) {
|
|
||||||
break true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(_) => continue,
|
|
||||||
None => break false,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
StringQuotes {
|
|
||||||
triple: quotes.triple,
|
|
||||||
quote_char: if contains_unescaped_configured_quotes {
|
|
||||||
quotes.quote_char
|
|
||||||
} else {
|
|
||||||
preferred_quote
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Choose the appropriate quote style for a string.
|
|
||||||
///
|
|
||||||
/// For single quoted strings, the preferred quote style is used, unless the alternative quote style
|
|
||||||
/// would require fewer escapes.
|
|
||||||
///
|
|
||||||
/// For triple quoted strings, the preferred quote style is always used, unless the string contains
|
|
||||||
/// a triplet of the quote character (e.g., if double quotes are preferred, double quotes will be
|
|
||||||
/// used unless the string contains `"""`).
|
|
||||||
fn choose_quotes_impl(
|
|
||||||
input: &str,
|
|
||||||
quotes: StringQuotes,
|
|
||||||
preferred_quote: QuoteChar,
|
|
||||||
) -> StringQuotes {
|
|
||||||
let quote = if quotes.triple {
|
|
||||||
// True if the string contains a triple quote sequence of the configured quote style.
|
|
||||||
let mut uses_triple_quotes = false;
|
|
||||||
let mut chars = input.chars().peekable();
|
|
||||||
|
|
||||||
while let Some(c) = chars.next() {
|
|
||||||
let preferred_quote_char = preferred_quote.as_char();
|
|
||||||
match c {
|
|
||||||
'\\' => {
|
|
||||||
if matches!(chars.peek(), Some('"' | '\\')) {
|
|
||||||
chars.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// `"` or `'`
|
|
||||||
c if c == preferred_quote_char => {
|
|
||||||
match chars.peek().copied() {
|
|
||||||
Some(c) if c == preferred_quote_char => {
|
|
||||||
// `""` or `''`
|
|
||||||
chars.next();
|
|
||||||
|
|
||||||
match chars.peek().copied() {
|
|
||||||
Some(c) if c == preferred_quote_char => {
|
|
||||||
// `"""` or `'''`
|
|
||||||
chars.next();
|
|
||||||
uses_triple_quotes = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Some(_) => {}
|
|
||||||
None => {
|
|
||||||
// Handle `''' ""'''`. At this point we have consumed both
|
|
||||||
// double quotes, so on the next iteration the iterator is empty
|
|
||||||
// and we'd miss the string ending with a preferred quote
|
|
||||||
uses_triple_quotes = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(_) => {
|
|
||||||
// A single quote char, this is ok
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// Trailing quote at the end of the comment
|
|
||||||
uses_triple_quotes = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if uses_triple_quotes {
|
|
||||||
// String contains a triple quote sequence of the configured quote style.
|
|
||||||
// Keep the existing quote style.
|
|
||||||
quotes.quote_char
|
|
||||||
} else {
|
|
||||||
preferred_quote
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut single_quotes = 0u32;
|
|
||||||
let mut double_quotes = 0u32;
|
|
||||||
|
|
||||||
for c in input.chars() {
|
|
||||||
match c {
|
|
||||||
'\'' => {
|
|
||||||
single_quotes += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
'"' => {
|
|
||||||
double_quotes += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match preferred_quote {
|
|
||||||
QuoteChar::Single => {
|
|
||||||
if single_quotes > double_quotes {
|
|
||||||
QuoteChar::Double
|
|
||||||
} else {
|
|
||||||
QuoteChar::Single
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QuoteChar::Double => {
|
|
||||||
if double_quotes > single_quotes {
|
|
||||||
QuoteChar::Single
|
|
||||||
} else {
|
|
||||||
QuoteChar::Double
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
StringQuotes {
|
|
||||||
triple: quotes.triple,
|
|
||||||
quote_char: quote,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds the necessary quote escapes and removes unnecessary escape sequences when quoting `input`
|
|
||||||
/// with the provided [`StringQuotes`] style.
|
|
||||||
///
|
|
||||||
/// Returns the normalized string and whether it contains new lines.
|
|
||||||
pub(crate) fn normalize_string(
|
|
||||||
input: &str,
|
|
||||||
quotes: StringQuotes,
|
|
||||||
prefix: StringPrefix,
|
|
||||||
normalize_hex: bool,
|
|
||||||
) -> Cow<str> {
|
|
||||||
// The normalized string if `input` is not yet normalized.
|
|
||||||
// `output` must remain empty if `input` is already normalized.
|
|
||||||
let mut output = String::new();
|
|
||||||
// Tracks the last index of `input` that has been written to `output`.
|
|
||||||
// If `last_index` is `0` at the end, then the input is already normalized and can be returned as is.
|
|
||||||
let mut last_index = 0;
|
|
||||||
|
|
||||||
let quote = quotes.quote_char;
|
|
||||||
let preferred_quote = quote.as_char();
|
|
||||||
let opposite_quote = quote.invert().as_char();
|
|
||||||
|
|
||||||
let mut chars = input.char_indices().peekable();
|
|
||||||
|
|
||||||
let is_raw = prefix.is_raw_string();
|
|
||||||
let is_fstring = prefix.is_fstring();
|
|
||||||
let mut formatted_value_nesting = 0u32;
|
|
||||||
|
|
||||||
while let Some((index, c)) = chars.next() {
|
|
||||||
if is_fstring && matches!(c, '{' | '}') {
|
|
||||||
if chars.peek().copied().is_some_and(|(_, next)| next == c) {
|
|
||||||
// Skip over the second character of the double braces
|
|
||||||
chars.next();
|
|
||||||
} else if c == '{' {
|
|
||||||
formatted_value_nesting += 1;
|
|
||||||
} else {
|
|
||||||
// Safe to assume that `c == '}'` here because of the matched pattern above
|
|
||||||
formatted_value_nesting = formatted_value_nesting.saturating_sub(1);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if c == '\r' {
|
|
||||||
output.push_str(&input[last_index..index]);
|
|
||||||
|
|
||||||
// Skip over the '\r' character, keep the `\n`
|
|
||||||
if chars.peek().copied().is_some_and(|(_, next)| next == '\n') {
|
|
||||||
chars.next();
|
|
||||||
}
|
|
||||||
// Replace the `\r` with a `\n`
|
|
||||||
else {
|
|
||||||
output.push('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
last_index = index + '\r'.len_utf8();
|
|
||||||
} else if !is_raw {
|
|
||||||
if c == '\\' {
|
|
||||||
if let Some((_, next)) = chars.clone().next() {
|
|
||||||
if next == '\\' {
|
|
||||||
// Skip over escaped backslashes
|
|
||||||
chars.next();
|
|
||||||
} else if normalize_hex {
|
|
||||||
if let Some(normalised) = UnicodeEscape::new(next, !prefix.is_byte())
|
|
||||||
.and_then(|escape| {
|
|
||||||
escape.normalize(&input[index + c.len_utf8() + next.len_utf8()..])
|
|
||||||
})
|
|
||||||
{
|
|
||||||
// Length of the `\` plus the length of the escape sequence character (`u` | `U` | `x`)
|
|
||||||
let escape_start_len = '\\'.len_utf8() + next.len_utf8();
|
|
||||||
let escape_start_offset = index + escape_start_len;
|
|
||||||
if let Cow::Owned(normalised) = &normalised {
|
|
||||||
output.push_str(&input[last_index..escape_start_offset]);
|
|
||||||
output.push_str(normalised);
|
|
||||||
last_index = escape_start_offset + normalised.len();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Move the `chars` iterator passed the escape sequence.
|
|
||||||
// Simply reassigning `chars` doesn't work because the indices` would
|
|
||||||
// then be off.
|
|
||||||
for _ in 0..next.len_utf8() + normalised.len() {
|
|
||||||
chars.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !quotes.triple {
|
|
||||||
#[allow(clippy::if_same_then_else)]
|
|
||||||
if next == opposite_quote && formatted_value_nesting == 0 {
|
|
||||||
// Remove the escape by ending before the backslash and starting again with the quote
|
|
||||||
chars.next();
|
|
||||||
output.push_str(&input[last_index..index]);
|
|
||||||
last_index = index + '\\'.len_utf8();
|
|
||||||
} else if next == preferred_quote {
|
|
||||||
// Quote is already escaped, skip over it.
|
|
||||||
chars.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if !quotes.triple && c == preferred_quote && formatted_value_nesting == 0 {
|
|
||||||
// Escape the quote
|
|
||||||
output.push_str(&input[last_index..index]);
|
|
||||||
output.push('\\');
|
|
||||||
output.push(c);
|
|
||||||
last_index = index + preferred_quote.len_utf8();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let normalized = if last_index == 0 {
|
|
||||||
Cow::Borrowed(input)
|
|
||||||
} else {
|
|
||||||
output.push_str(&input[last_index..]);
|
|
||||||
Cow::Owned(output)
|
|
||||||
};
|
|
||||||
|
|
||||||
normalized
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
||||||
enum UnicodeEscape {
|
|
||||||
/// A hex escape sequence of either 2 (`\x`), 4 (`\u`) or 8 (`\U`) hex characters.
|
|
||||||
Hex(usize),
|
|
||||||
|
|
||||||
/// An escaped unicode name (`\N{name}`)
|
|
||||||
CharacterName,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UnicodeEscape {
|
|
||||||
fn new(first: char, allow_unicode: bool) -> Option<UnicodeEscape> {
|
|
||||||
Some(match first {
|
|
||||||
'x' => UnicodeEscape::Hex(2),
|
|
||||||
'u' if allow_unicode => UnicodeEscape::Hex(4),
|
|
||||||
'U' if allow_unicode => UnicodeEscape::Hex(8),
|
|
||||||
'N' if allow_unicode => UnicodeEscape::CharacterName,
|
|
||||||
_ => return None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Normalises `\u..`, `\U..`, `\x..` and `\N{..}` escape sequences to:
|
|
||||||
///
|
|
||||||
/// * `\u`, `\U'` and `\x`: To use lower case for the characters `a-f`.
|
|
||||||
/// * `\N`: To use uppercase letters
|
|
||||||
fn normalize(self, input: &str) -> Option<Cow<str>> {
|
|
||||||
let mut normalised = String::new();
|
|
||||||
|
|
||||||
let len = match self {
|
|
||||||
UnicodeEscape::Hex(len) => {
|
|
||||||
// It's not a valid escape sequence if the input string has fewer characters
|
|
||||||
// left than required by the escape sequence.
|
|
||||||
if input.len() < len {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (index, c) in input.char_indices().take(len) {
|
|
||||||
match c {
|
|
||||||
'0'..='9' | 'a'..='f' => {
|
|
||||||
if !normalised.is_empty() {
|
|
||||||
normalised.push(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'A'..='F' => {
|
|
||||||
if normalised.is_empty() {
|
|
||||||
normalised.reserve(len);
|
|
||||||
normalised.push_str(&input[..index]);
|
|
||||||
normalised.push(c.to_ascii_lowercase());
|
|
||||||
} else {
|
|
||||||
normalised.push(c.to_ascii_lowercase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// not a valid escape sequence
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
len
|
|
||||||
}
|
|
||||||
UnicodeEscape::CharacterName => {
|
|
||||||
let mut char_indices = input.char_indices();
|
|
||||||
|
|
||||||
if !matches!(char_indices.next(), Some((_, '{'))) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if let Some((index, c)) = char_indices.next() {
|
|
||||||
match c {
|
|
||||||
'}' => {
|
|
||||||
if !normalised.is_empty() {
|
|
||||||
normalised.push('}');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name must be at least two characters long.
|
|
||||||
if index < 3 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
break index + '}'.len_utf8();
|
|
||||||
}
|
|
||||||
'0'..='9' | 'A'..='Z' | ' ' | '-' => {
|
|
||||||
if !normalised.is_empty() {
|
|
||||||
normalised.push(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'a'..='z' => {
|
|
||||||
if normalised.is_empty() {
|
|
||||||
normalised.reserve(c.len_utf8() + '}'.len_utf8());
|
|
||||||
normalised.push_str(&input[..index]);
|
|
||||||
normalised.push(c.to_ascii_uppercase());
|
|
||||||
} else {
|
|
||||||
normalised.push(c.to_ascii_uppercase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Seems like an invalid escape sequence, don't normalise it.
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Unterminated escape sequence, don't normalise it.
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(if normalised.is_empty() {
|
|
||||||
Cow::Borrowed(&input[..len])
|
|
||||||
} else {
|
|
||||||
Cow::Owned(normalised)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use crate::string::{QuoteChar, StringPrefix, StringQuotes};
|
|
||||||
|
|
||||||
use super::{normalize_string, UnicodeEscape};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn normalize_32_escape() {
|
|
||||||
let escape_sequence = UnicodeEscape::new('U', true).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
Some(Cow::Owned("0001f60e".to_string())),
|
|
||||||
escape_sequence.normalize("0001F60E")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn normalize_hex_in_byte_string() {
|
|
||||||
let input = r"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
|
||||||
|
|
||||||
let normalized = normalize_string(
|
|
||||||
input,
|
|
||||||
StringQuotes {
|
|
||||||
triple: false,
|
|
||||||
quote_char: QuoteChar::Double,
|
|
||||||
},
|
|
||||||
StringPrefix::BYTE,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(r"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", &normalized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -401,23 +401,22 @@ fn ensure_unchanged_ast(
|
|||||||
Normalizer.visit_module(&mut formatted_ast);
|
Normalizer.visit_module(&mut formatted_ast);
|
||||||
let formatted_ast = ComparableMod::from(&formatted_ast);
|
let formatted_ast = ComparableMod::from(&formatted_ast);
|
||||||
|
|
||||||
// FIXME
|
if formatted_ast != unformatted_ast {
|
||||||
// if formatted_ast != unformatted_ast {
|
let diff = TextDiff::from_lines(
|
||||||
// let diff = TextDiff::from_lines(
|
&format!("{unformatted_ast:#?}"),
|
||||||
// &format!("{unformatted_ast:#?}"),
|
&format!("{formatted_ast:#?}"),
|
||||||
// &format!("{formatted_ast:#?}"),
|
)
|
||||||
// )
|
.unified_diff()
|
||||||
// .unified_diff()
|
.header("Unformatted", "Formatted")
|
||||||
// .header("Unformatted", "Formatted")
|
.to_string();
|
||||||
// .to_string();
|
panic!(
|
||||||
// panic!(
|
r#"Reformatting the unformatted code of {} resulted in AST changes.
|
||||||
// r#"Reformatting the unformatted code of {} resulted in AST changes.
|
---
|
||||||
// ---
|
{diff}
|
||||||
// {diff}
|
"#,
|
||||||
// "#,
|
input_path.display(),
|
||||||
// input_path.display(),
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Header<'a> {
|
struct Header<'a> {
|
||||||
|
|||||||
@@ -0,0 +1,314 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/collections.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
import core, time, a
|
||||||
|
|
||||||
|
from . import A, B, C
|
||||||
|
|
||||||
|
# keeps existing trailing comma
|
||||||
|
from foo import (
|
||||||
|
bar,
|
||||||
|
)
|
||||||
|
|
||||||
|
# also keeps existing structure
|
||||||
|
from foo import (
|
||||||
|
baz,
|
||||||
|
qux,
|
||||||
|
)
|
||||||
|
|
||||||
|
# `as` works as well
|
||||||
|
from foo import (
|
||||||
|
xyzzy as magic,
|
||||||
|
)
|
||||||
|
|
||||||
|
a = {1,2,3,}
|
||||||
|
b = {
|
||||||
|
1,2,
|
||||||
|
3}
|
||||||
|
c = {
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
}
|
||||||
|
x = 1,
|
||||||
|
y = narf(),
|
||||||
|
nested = {(1,2,3),(4,5,6),}
|
||||||
|
nested_no_trailing_comma = {(1,2,3),(4,5,6)}
|
||||||
|
nested_long_lines = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccc", (1, 2, 3), "dddddddddddddddddddddddddddddddddddddddd"]
|
||||||
|
{"oneple": (1,),}
|
||||||
|
{"oneple": (1,)}
|
||||||
|
['ls', 'lsoneple/%s' % (foo,)]
|
||||||
|
x = {"oneple": (1,)}
|
||||||
|
y = {"oneple": (1,),}
|
||||||
|
assert False, ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s" % bar)
|
||||||
|
|
||||||
|
# looping over a 1-tuple should also not get wrapped
|
||||||
|
for x in (1,):
|
||||||
|
pass
|
||||||
|
for (x,) in (1,), (2,), (3,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
[1, 2, 3,]
|
||||||
|
|
||||||
|
division_result_tuple = (6/2,)
|
||||||
|
print("foo %r", (foo.bar,))
|
||||||
|
|
||||||
|
if True:
|
||||||
|
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||||
|
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||||
|
| {pylons.controllers.WSGIController}
|
||||||
|
)
|
||||||
|
|
||||||
|
if True:
|
||||||
|
ec2client.get_waiter('instance_stopped').wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
'Delay': 5,
|
||||||
|
})
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={"Delay": 5,},
|
||||||
|
)
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id], WaiterConfig={"Delay": 5,},
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -54,7 +54,7 @@
|
||||||
|
}
|
||||||
|
assert False, (
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||||
|
- % bar
|
||||||
|
+ % bar
|
||||||
|
)
|
||||||
|
|
||||||
|
# looping over a 1-tuple should also not get wrapped
|
||||||
|
@@ -75,7 +75,7 @@
|
||||||
|
if True:
|
||||||
|
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||||
|
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||||
|
- | {pylons.controllers.WSGIController}
|
||||||
|
+ | {pylons.controllers.WSGIController}
|
||||||
|
)
|
||||||
|
|
||||||
|
if True:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
import core, time, a
|
||||||
|
|
||||||
|
from . import A, B, C
|
||||||
|
|
||||||
|
# keeps existing trailing comma
|
||||||
|
from foo import (
|
||||||
|
bar,
|
||||||
|
)
|
||||||
|
|
||||||
|
# also keeps existing structure
|
||||||
|
from foo import (
|
||||||
|
baz,
|
||||||
|
qux,
|
||||||
|
)
|
||||||
|
|
||||||
|
# `as` works as well
|
||||||
|
from foo import (
|
||||||
|
xyzzy as magic,
|
||||||
|
)
|
||||||
|
|
||||||
|
a = {
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
}
|
||||||
|
b = {1, 2, 3}
|
||||||
|
c = {
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
}
|
||||||
|
x = (1,)
|
||||||
|
y = (narf(),)
|
||||||
|
nested = {
|
||||||
|
(1, 2, 3),
|
||||||
|
(4, 5, 6),
|
||||||
|
}
|
||||||
|
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
|
||||||
|
nested_long_lines = [
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||||
|
"cccccccccccccccccccccccccccccccccccccccc",
|
||||||
|
(1, 2, 3),
|
||||||
|
"dddddddddddddddddddddddddddddddddddddddd",
|
||||||
|
]
|
||||||
|
{
|
||||||
|
"oneple": (1,),
|
||||||
|
}
|
||||||
|
{"oneple": (1,)}
|
||||||
|
["ls", "lsoneple/%s" % (foo,)]
|
||||||
|
x = {"oneple": (1,)}
|
||||||
|
y = {
|
||||||
|
"oneple": (1,),
|
||||||
|
}
|
||||||
|
assert False, (
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||||
|
% bar
|
||||||
|
)
|
||||||
|
|
||||||
|
# looping over a 1-tuple should also not get wrapped
|
||||||
|
for x in (1,):
|
||||||
|
pass
|
||||||
|
for (x,) in (1,), (2,), (3,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
]
|
||||||
|
|
||||||
|
division_result_tuple = (6 / 2,)
|
||||||
|
print("foo %r", (foo.bar,))
|
||||||
|
|
||||||
|
if True:
|
||||||
|
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||||
|
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||||
|
| {pylons.controllers.WSGIController}
|
||||||
|
)
|
||||||
|
|
||||||
|
if True:
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
import core, time, a
|
||||||
|
|
||||||
|
from . import A, B, C
|
||||||
|
|
||||||
|
# keeps existing trailing comma
|
||||||
|
from foo import (
|
||||||
|
bar,
|
||||||
|
)
|
||||||
|
|
||||||
|
# also keeps existing structure
|
||||||
|
from foo import (
|
||||||
|
baz,
|
||||||
|
qux,
|
||||||
|
)
|
||||||
|
|
||||||
|
# `as` works as well
|
||||||
|
from foo import (
|
||||||
|
xyzzy as magic,
|
||||||
|
)
|
||||||
|
|
||||||
|
a = {
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
}
|
||||||
|
b = {1, 2, 3}
|
||||||
|
c = {
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
}
|
||||||
|
x = (1,)
|
||||||
|
y = (narf(),)
|
||||||
|
nested = {
|
||||||
|
(1, 2, 3),
|
||||||
|
(4, 5, 6),
|
||||||
|
}
|
||||||
|
nested_no_trailing_comma = {(1, 2, 3), (4, 5, 6)}
|
||||||
|
nested_long_lines = [
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
|
||||||
|
"cccccccccccccccccccccccccccccccccccccccc",
|
||||||
|
(1, 2, 3),
|
||||||
|
"dddddddddddddddddddddddddddddddddddddddd",
|
||||||
|
]
|
||||||
|
{
|
||||||
|
"oneple": (1,),
|
||||||
|
}
|
||||||
|
{"oneple": (1,)}
|
||||||
|
["ls", "lsoneple/%s" % (foo,)]
|
||||||
|
x = {"oneple": (1,)}
|
||||||
|
y = {
|
||||||
|
"oneple": (1,),
|
||||||
|
}
|
||||||
|
assert False, (
|
||||||
|
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa wraps %s"
|
||||||
|
% bar
|
||||||
|
)
|
||||||
|
|
||||||
|
# looping over a 1-tuple should also not get wrapped
|
||||||
|
for x in (1,):
|
||||||
|
pass
|
||||||
|
for (x,) in (1,), (2,), (3,):
|
||||||
|
pass
|
||||||
|
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
]
|
||||||
|
|
||||||
|
division_result_tuple = (6 / 2,)
|
||||||
|
print("foo %r", (foo.bar,))
|
||||||
|
|
||||||
|
if True:
|
||||||
|
IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING = (
|
||||||
|
Config.IGNORED_TYPES_FOR_ATTRIBUTE_CHECKING
|
||||||
|
| {pylons.controllers.WSGIController}
|
||||||
|
)
|
||||||
|
|
||||||
|
if True:
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
ec2client.get_waiter("instance_stopped").wait(
|
||||||
|
InstanceIds=[instance.id],
|
||||||
|
WaiterConfig={
|
||||||
|
"Delay": 5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ instruction()#comment with bad spacing
|
|||||||
children[0],
|
children[0],
|
||||||
body,
|
body,
|
||||||
children[-1], # type: ignore
|
children[-1], # type: ignore
|
||||||
@@ -72,7 +76,11 @@
|
@@ -72,14 +76,18 @@
|
||||||
body,
|
body,
|
||||||
parameters.children[-1], # )2
|
parameters.children[-1], # )2
|
||||||
]
|
]
|
||||||
@@ -204,7 +204,19 @@ instruction()#comment with bad spacing
|
|||||||
+ ] # type: ignore
|
+ ] # type: ignore
|
||||||
if (
|
if (
|
||||||
self._proc is not None
|
self._proc is not None
|
||||||
# has the child process finished?
|
- # 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
|
||||||
|
+ # 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
|
||||||
@@ -115,7 +123,9 @@
|
@@ -115,7 +123,9 @@
|
||||||
arg3=True,
|
arg3=True,
|
||||||
)
|
)
|
||||||
@@ -228,14 +240,23 @@ instruction()#comment with bad spacing
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -158,7 +171,10 @@
|
@@ -151,14 +164,17 @@
|
||||||
|
[
|
||||||
|
CONFIG_FILE,
|
||||||
|
]
|
||||||
|
- + SHARED_CONFIG_FILES
|
||||||
|
- + USER_CONFIG_FILES
|
||||||
|
+ + SHARED_CONFIG_FILES
|
||||||
|
+ + USER_CONFIG_FILES
|
||||||
|
) # type: Final
|
||||||
|
|
||||||
|
|
||||||
class Test:
|
class Test:
|
||||||
def _init_host(self, parsed) -> None:
|
def _init_host(self, parsed) -> None:
|
||||||
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
|
- if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
|
||||||
+ if (
|
+ if (
|
||||||
+ parsed.hostname is None # type: ignore
|
+ parsed.hostname is None # type: ignore
|
||||||
+ or not parsed.hostname.strip()
|
+ or not parsed.hostname.strip()
|
||||||
+ ):
|
+ ):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -330,11 +351,11 @@ def inline_comments_in_brackets_ruin_everything():
|
|||||||
] # type: ignore
|
] # type: ignore
|
||||||
if (
|
if (
|
||||||
self._proc is not None
|
self._proc is not None
|
||||||
# has the child process finished?
|
# has the child process finished?
|
||||||
and self._returncode is None
|
and self._returncode is None
|
||||||
# the child process has finished, but the
|
# the child process has finished, but the
|
||||||
# transport hasn't been notified yet?
|
# transport hasn't been notified yet?
|
||||||
and self._proc.poll() is None
|
and self._proc.poll() is None
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
# no newline before or after
|
# no newline before or after
|
||||||
@@ -411,8 +432,8 @@ CONFIG_FILES = (
|
|||||||
[
|
[
|
||||||
CONFIG_FILE,
|
CONFIG_FILE,
|
||||||
]
|
]
|
||||||
+ SHARED_CONFIG_FILES
|
+ SHARED_CONFIG_FILES
|
||||||
+ USER_CONFIG_FILES
|
+ USER_CONFIG_FILES
|
||||||
) # type: Final
|
) # type: Final
|
||||||
|
|
||||||
|
|
||||||
@@ -420,7 +441,7 @@ class Test:
|
|||||||
def _init_host(self, parsed) -> None:
|
def _init_host(self, parsed) -> None:
|
||||||
if (
|
if (
|
||||||
parsed.hostname is None # type: ignore
|
parsed.hostname is None # type: ignore
|
||||||
or not parsed.hostname.strip()
|
or not parsed.hostname.strip()
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,23 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
|||||||
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
|
||||||
|
|
||||||
tup = (
|
tup = (
|
||||||
|
@@ -61,11 +59,11 @@
|
||||||
|
|
||||||
|
a = (
|
||||||
|
element
|
||||||
|
- + another_element
|
||||||
|
- + another_element_with_long_name
|
||||||
|
- + element
|
||||||
|
- + another_element
|
||||||
|
- + another_element_with_long_name
|
||||||
|
+ + another_element
|
||||||
|
+ + another_element_with_long_name
|
||||||
|
+ + element
|
||||||
|
+ + another_element
|
||||||
|
+ + another_element_with_long_name
|
||||||
|
) # type: int
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +98,13 @@
|
@@ -100,7 +98,13 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -243,11 +260,11 @@ def f(
|
|||||||
|
|
||||||
a = (
|
a = (
|
||||||
element
|
element
|
||||||
+ another_element
|
+ another_element
|
||||||
+ another_element_with_long_name
|
+ another_element_with_long_name
|
||||||
+ element
|
+ element
|
||||||
+ another_element
|
+ another_element
|
||||||
+ another_element_with_long_name
|
+ another_element_with_long_name
|
||||||
) # type: int
|
) # type: int
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,40 @@ if (
|
|||||||
# b comment
|
# b comment
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
@@ -92,20 +91,20 @@
|
||||||
|
# comment1
|
||||||
|
a
|
||||||
|
# comment2
|
||||||
|
- or (
|
||||||
|
- # comment3
|
||||||
|
- (
|
||||||
|
- # comment4
|
||||||
|
- b
|
||||||
|
- )
|
||||||
|
- # comment5
|
||||||
|
- and
|
||||||
|
- # comment6
|
||||||
|
- c
|
||||||
|
or (
|
||||||
|
- # comment7
|
||||||
|
- d
|
||||||
|
+ # comment3
|
||||||
|
+ (
|
||||||
|
+ # comment4
|
||||||
|
+ b
|
||||||
|
+ )
|
||||||
|
+ # comment5
|
||||||
|
+ and
|
||||||
|
+ # comment6
|
||||||
|
+ c
|
||||||
|
+ or (
|
||||||
|
+ # comment7
|
||||||
|
+ d
|
||||||
|
+ )
|
||||||
|
)
|
||||||
|
- )
|
||||||
|
):
|
||||||
|
print("Foo")
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -244,21 +278,21 @@ if (
|
|||||||
# comment1
|
# comment1
|
||||||
a
|
a
|
||||||
# comment2
|
# comment2
|
||||||
or (
|
|
||||||
# comment3
|
|
||||||
(
|
|
||||||
# comment4
|
|
||||||
b
|
|
||||||
)
|
|
||||||
# comment5
|
|
||||||
and
|
|
||||||
# comment6
|
|
||||||
c
|
|
||||||
or (
|
or (
|
||||||
# comment7
|
# comment3
|
||||||
d
|
(
|
||||||
|
# comment4
|
||||||
|
b
|
||||||
|
)
|
||||||
|
# comment5
|
||||||
|
and
|
||||||
|
# comment6
|
||||||
|
c
|
||||||
|
or (
|
||||||
|
# comment7
|
||||||
|
d
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
):
|
):
|
||||||
print("Foo")
|
print("Foo")
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -193,6 +193,26 @@ class C:
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
|
@@ -22,8 +22,8 @@
|
||||||
|
if (
|
||||||
|
# Rule 1
|
||||||
|
i % 2 == 0
|
||||||
|
- # Rule 2
|
||||||
|
- and i % 3 == 0
|
||||||
|
+ # Rule 2
|
||||||
|
+ and i % 3 == 0
|
||||||
|
):
|
||||||
|
while (
|
||||||
|
# Just a comment
|
||||||
|
@@ -41,7 +41,7 @@
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||||
|
- % (test.name, test.filename, lineno, lname, err)
|
||||||
|
+ % (test.name, test.filename, lineno, lname, err)
|
||||||
|
)
|
||||||
|
|
||||||
|
def omitting_trailers(self) -> None:
|
||||||
@@ -110,19 +110,20 @@
|
@@ -110,19 +110,20 @@
|
||||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||||
), "Not what we expected"
|
), "Not what we expected"
|
||||||
@@ -222,12 +242,12 @@ class C:
|
|||||||
+ key8: value8,
|
+ key8: value8,
|
||||||
+ key9: value9,
|
+ key9: value9,
|
||||||
+ }
|
+ }
|
||||||
+ == expected
|
+ == expected
|
||||||
+ ), "Not what we expected and the message is too long to fit in one line"
|
+ ), "Not what we expected and the message is too long to fit in one line"
|
||||||
|
|
||||||
assert expected(
|
assert expected(
|
||||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||||
@@ -161,9 +162,7 @@
|
@@ -161,21 +162,19 @@
|
||||||
8 STORE_ATTR 0 (x)
|
8 STORE_ATTR 0 (x)
|
||||||
10 LOAD_CONST 0 (None)
|
10 LOAD_CONST 0 (None)
|
||||||
12 RETURN_VALUE
|
12 RETURN_VALUE
|
||||||
@@ -238,6 +258,29 @@ class C:
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||||
|
- == {
|
||||||
|
- key1: value1,
|
||||||
|
- key2: value2,
|
||||||
|
- key3: value3,
|
||||||
|
- key4: value4,
|
||||||
|
- key5: value5,
|
||||||
|
- key6: value6,
|
||||||
|
- key7: value7,
|
||||||
|
- key8: value8,
|
||||||
|
- key9: value9,
|
||||||
|
- }
|
||||||
|
+ == {
|
||||||
|
+ key1: value1,
|
||||||
|
+ key2: value2,
|
||||||
|
+ key3: value3,
|
||||||
|
+ key4: value4,
|
||||||
|
+ key5: value5,
|
||||||
|
+ key6: value6,
|
||||||
|
+ key7: value7,
|
||||||
|
+ key8: value8,
|
||||||
|
+ key9: value9,
|
||||||
|
+ }
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -267,8 +310,8 @@ class C:
|
|||||||
if (
|
if (
|
||||||
# Rule 1
|
# Rule 1
|
||||||
i % 2 == 0
|
i % 2 == 0
|
||||||
# Rule 2
|
# Rule 2
|
||||||
and i % 3 == 0
|
and i % 3 == 0
|
||||||
):
|
):
|
||||||
while (
|
while (
|
||||||
# Just a comment
|
# Just a comment
|
||||||
@@ -286,7 +329,7 @@ class C:
|
|||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||||
% (test.name, test.filename, lineno, lname, err)
|
% (test.name, test.filename, lineno, lname, err)
|
||||||
)
|
)
|
||||||
|
|
||||||
def omitting_trailers(self) -> None:
|
def omitting_trailers(self) -> None:
|
||||||
@@ -367,7 +410,7 @@ class C:
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expected
|
== expected
|
||||||
), "Not what we expected and the message is too long to fit in one line"
|
), "Not what we expected and the message is too long to fit in one line"
|
||||||
|
|
||||||
assert expected(
|
assert expected(
|
||||||
@@ -411,17 +454,17 @@ class C:
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||||
== {
|
== {
|
||||||
key1: value1,
|
key1: value1,
|
||||||
key2: value2,
|
key2: value2,
|
||||||
key3: value3,
|
key3: value3,
|
||||||
key4: value4,
|
key4: value4,
|
||||||
key5: value5,
|
key5: value5,
|
||||||
key6: value6,
|
key6: value6,
|
||||||
key7: value7,
|
key7: value7,
|
||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,26 @@ class C:
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
|
@@ -22,8 +22,8 @@
|
||||||
|
if (
|
||||||
|
# Rule 1
|
||||||
|
i % 2 == 0
|
||||||
|
- # Rule 2
|
||||||
|
- and i % 3 == 0
|
||||||
|
+ # Rule 2
|
||||||
|
+ and i % 3 == 0
|
||||||
|
):
|
||||||
|
while (
|
||||||
|
# Just a comment
|
||||||
|
@@ -41,7 +41,7 @@
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||||
|
- % (test.name, test.filename, lineno, lname, err)
|
||||||
|
+ % (test.name, test.filename, lineno, lname, err)
|
||||||
|
)
|
||||||
|
|
||||||
|
def omitting_trailers(self) -> None:
|
||||||
@@ -110,19 +110,20 @@
|
@@ -110,19 +110,20 @@
|
||||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||||
), "Not what we expected"
|
), "Not what we expected"
|
||||||
@@ -222,12 +242,12 @@ class C:
|
|||||||
+ key8: value8,
|
+ key8: value8,
|
||||||
+ key9: value9,
|
+ key9: value9,
|
||||||
+ }
|
+ }
|
||||||
+ == expected
|
+ == expected
|
||||||
+ ), "Not what we expected and the message is too long to fit in one line"
|
+ ), "Not what we expected and the message is too long to fit in one line"
|
||||||
|
|
||||||
assert expected(
|
assert expected(
|
||||||
value, is_going_to_be="too long to fit in a single line", srsly=True
|
value, is_going_to_be="too long to fit in a single line", srsly=True
|
||||||
@@ -161,9 +162,7 @@
|
@@ -161,21 +162,19 @@
|
||||||
8 STORE_ATTR 0 (x)
|
8 STORE_ATTR 0 (x)
|
||||||
10 LOAD_CONST 0 (None)
|
10 LOAD_CONST 0 (None)
|
||||||
12 RETURN_VALUE
|
12 RETURN_VALUE
|
||||||
@@ -238,6 +258,29 @@ class C:
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||||
|
- == {
|
||||||
|
- key1: value1,
|
||||||
|
- key2: value2,
|
||||||
|
- key3: value3,
|
||||||
|
- key4: value4,
|
||||||
|
- key5: value5,
|
||||||
|
- key6: value6,
|
||||||
|
- key7: value7,
|
||||||
|
- key8: value8,
|
||||||
|
- key9: value9,
|
||||||
|
- }
|
||||||
|
+ == {
|
||||||
|
+ key1: value1,
|
||||||
|
+ key2: value2,
|
||||||
|
+ key3: value3,
|
||||||
|
+ key4: value4,
|
||||||
|
+ key5: value5,
|
||||||
|
+ key6: value6,
|
||||||
|
+ key7: value7,
|
||||||
|
+ key8: value8,
|
||||||
|
+ key9: value9,
|
||||||
|
+ }
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -267,8 +310,8 @@ class C:
|
|||||||
if (
|
if (
|
||||||
# Rule 1
|
# Rule 1
|
||||||
i % 2 == 0
|
i % 2 == 0
|
||||||
# Rule 2
|
# Rule 2
|
||||||
and i % 3 == 0
|
and i % 3 == 0
|
||||||
):
|
):
|
||||||
while (
|
while (
|
||||||
# Just a comment
|
# Just a comment
|
||||||
@@ -286,7 +329,7 @@ class C:
|
|||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||||
% (test.name, test.filename, lineno, lname, err)
|
% (test.name, test.filename, lineno, lname, err)
|
||||||
)
|
)
|
||||||
|
|
||||||
def omitting_trailers(self) -> None:
|
def omitting_trailers(self) -> None:
|
||||||
@@ -367,7 +410,7 @@ class C:
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expected
|
== expected
|
||||||
), "Not what we expected and the message is too long to fit in one line"
|
), "Not what we expected and the message is too long to fit in one line"
|
||||||
|
|
||||||
assert expected(
|
assert expected(
|
||||||
@@ -411,17 +454,17 @@ class C:
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
|
||||||
== {
|
== {
|
||||||
key1: value1,
|
key1: value1,
|
||||||
key2: value2,
|
key2: value2,
|
||||||
key3: value3,
|
key3: value3,
|
||||||
key4: value4,
|
key4: value4,
|
||||||
key5: value5,
|
key5: value5,
|
||||||
key6: value6,
|
key6: value6,
|
||||||
key7: value7,
|
key7: value7,
|
||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -275,6 +275,131 @@ last_call()
|
|||||||
) # note: no trailing comma pre-3.6
|
) # note: no trailing comma pre-3.6
|
||||||
call(*gidgets[:2])
|
call(*gidgets[:2])
|
||||||
call(a, *gidgets[:2])
|
call(a, *gidgets[:2])
|
||||||
|
@@ -277,95 +277,95 @@
|
||||||
|
pass
|
||||||
|
a = (
|
||||||
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
|
- in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
+ in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
)
|
||||||
|
a = (
|
||||||
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
|
- not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
+ not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
)
|
||||||
|
a = (
|
||||||
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
|
- is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
+ is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
)
|
||||||
|
a = (
|
||||||
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
|
- is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
+ is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
threading.current_thread() != threading.main_thread()
|
||||||
|
- and threading.current_thread() != threading.main_thread()
|
||||||
|
- or signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
||||||
|
+ and threading.current_thread() != threading.main_thread()
|
||||||
|
+ or signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
~aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e
|
||||||
|
- | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l**aaaa.m // aaaa.n
|
||||||
|
+ | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l**aaaa.m // aaaa.n
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
~aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e
|
||||||
|
- | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h
|
||||||
|
- ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
|
||||||
|
+ | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h
|
||||||
|
+ ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
if (
|
||||||
|
~aaaaaaaaaaaaaaaa.a
|
||||||
|
- + aaaaaaaaaaaaaaaa.b
|
||||||
|
- - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
|
||||||
|
- | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h
|
||||||
|
- ^ aaaaaaaaaaaaaaaa.i
|
||||||
|
- << aaaaaaaaaaaaaaaa.k
|
||||||
|
- >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
|
||||||
|
+ + aaaaaaaaaaaaaaaa.b
|
||||||
|
+ - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
|
||||||
|
+ | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h
|
||||||
|
+ ^ aaaaaaaaaaaaaaaa.i
|
||||||
|
+ << aaaaaaaaaaaaaaaa.k
|
||||||
|
+ >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
(
|
||||||
|
aaaaaaaaaaaaaaaa
|
||||||
|
- + aaaaaaaaaaaaaaaa
|
||||||
|
- - aaaaaaaaaaaaaaaa
|
||||||
|
- * (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
- / (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
+ + aaaaaaaaaaaaaaaa
|
||||||
|
+ - aaaaaaaaaaaaaaaa
|
||||||
|
+ * (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
+ / (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
)
|
||||||
|
aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa
|
||||||
|
(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- >> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ >> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
)
|
||||||
|
bbbb >> bbbb * bbbb
|
||||||
|
(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
- ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
)
|
||||||
|
last_call()
|
||||||
|
# standalone comment at ENDMARKER
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -559,95 +684,95 @@ for (
|
|||||||
pass
|
pass
|
||||||
a = (
|
a = (
|
||||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
)
|
)
|
||||||
a = (
|
a = (
|
||||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
not in qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
)
|
)
|
||||||
a = (
|
a = (
|
||||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
is qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
)
|
)
|
||||||
a = (
|
a = (
|
||||||
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
is not qqqq.rrrr.ssss.tttt.uuuu.vvvv.xxxx.yyyy.zzzz
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
threading.current_thread() != threading.main_thread()
|
threading.current_thread() != threading.main_thread()
|
||||||
and threading.current_thread() != threading.main_thread()
|
and threading.current_thread() != threading.main_thread()
|
||||||
or signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
or signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
/ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
/ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
~aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e
|
~aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e
|
||||||
| aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l**aaaa.m // aaaa.n
|
| aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l**aaaa.m // aaaa.n
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
~aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e
|
~aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e
|
||||||
| aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h
|
| aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h
|
||||||
^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
|
^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
if (
|
||||||
~aaaaaaaaaaaaaaaa.a
|
~aaaaaaaaaaaaaaaa.a
|
||||||
+ aaaaaaaaaaaaaaaa.b
|
+ aaaaaaaaaaaaaaaa.b
|
||||||
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
|
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
|
||||||
| aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h
|
| aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h
|
||||||
^ aaaaaaaaaaaaaaaa.i
|
^ aaaaaaaaaaaaaaaa.i
|
||||||
<< aaaaaaaaaaaaaaaa.k
|
<< aaaaaaaaaaaaaaaa.k
|
||||||
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
|
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaa
|
||||||
+ aaaaaaaaaaaaaaaa
|
+ aaaaaaaaaaaaaaaa
|
||||||
- aaaaaaaaaaaaaaaa
|
- aaaaaaaaaaaaaaaa
|
||||||
* (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
* (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
/ (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
/ (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
)
|
)
|
||||||
aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
>> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
>> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
)
|
)
|
||||||
bbbb >> bbbb * bbbb
|
bbbb >> bbbb * bbbb
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
)
|
)
|
||||||
last_call()
|
last_call()
|
||||||
# standalone comment at ENDMARKER
|
# standalone comment at ENDMARKER
|
||||||
|
|||||||
@@ -104,12 +104,21 @@ elif unformatted:
|
|||||||
- "=foo.bar.:main",
|
- "=foo.bar.:main",
|
||||||
- # fmt: on
|
- # fmt: on
|
||||||
- ] # Includes an formatted indentation.
|
- ] # Includes an formatted indentation.
|
||||||
+ "foo-bar=foo.bar.:main",
|
+ "foo-bar" "=foo.bar.:main",
|
||||||
+ # fmt: on
|
+ # fmt: on
|
||||||
+ ] # Includes an formatted indentation.
|
+ ] # Includes an formatted indentation.
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -19,7 +18,7 @@
|
||||||
|
"-la",
|
||||||
|
]
|
||||||
|
# fmt: on
|
||||||
|
- + path,
|
||||||
|
+ + path,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
|
||||||
@@ -82,6 +81,6 @@
|
@@ -82,6 +81,6 @@
|
||||||
if x:
|
if x:
|
||||||
return x
|
return x
|
||||||
@@ -128,7 +137,7 @@ setup(
|
|||||||
entry_points={
|
entry_points={
|
||||||
# fmt: off
|
# fmt: off
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
"foo-bar=foo.bar.:main",
|
"foo-bar" "=foo.bar.:main",
|
||||||
# fmt: on
|
# fmt: on
|
||||||
] # Includes an formatted indentation.
|
] # Includes an formatted indentation.
|
||||||
},
|
},
|
||||||
@@ -143,7 +152,7 @@ run(
|
|||||||
"-la",
|
"-la",
|
||||||
]
|
]
|
||||||
# fmt: on
|
# fmt: on
|
||||||
+ path,
|
+ path,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ else:
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,7 +1,7 @@
|
@@ -1,8 +1,8 @@
|
||||||
a, b, c = 3, 4, 5
|
a, b, c = 3, 4, 5
|
||||||
if (
|
if (
|
||||||
a == 3
|
a == 3
|
||||||
- and b != 9 # fmt: skip
|
- and b != 9 # fmt: skip
|
||||||
+ and b != 9 # fmt: skip
|
- and c is not None
|
||||||
and c is not None
|
+ and b != 9 # fmt: skip
|
||||||
|
+ and c is not None
|
||||||
):
|
):
|
||||||
print("I'm good!")
|
print("I'm good!")
|
||||||
|
else:
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -38,8 +40,8 @@ else:
|
|||||||
a, b, c = 3, 4, 5
|
a, b, c = 3, 4, 5
|
||||||
if (
|
if (
|
||||||
a == 3
|
a == 3
|
||||||
and b != 9 # fmt: skip
|
and b != 9 # fmt: skip
|
||||||
and c is not None
|
and c is not None
|
||||||
):
|
):
|
||||||
print("I'm good!")
|
print("I'm good!")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -0,0 +1,343 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/function_trailing_comma.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
def f(a,):
|
||||||
|
d = {'key': 'value',}
|
||||||
|
tup = (1,)
|
||||||
|
|
||||||
|
def f2(a,b,):
|
||||||
|
d = {'key': 'value', 'key2': 'value2',}
|
||||||
|
tup = (1,2,)
|
||||||
|
|
||||||
|
def f(a:int=1,):
|
||||||
|
call(arg={'explode': 'this',})
|
||||||
|
call2(arg=[1,2,3],)
|
||||||
|
x = {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
}["a"]
|
||||||
|
if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
||||||
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
]:
|
||||||
|
json = {"k": {"k2": {"k3": [1,]}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
|
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||||
|
def some_function_with_a_really_long_name() -> (
|
||||||
|
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_method_with_a_really_long_name(very_long_parameter_so_yeah: str, another_long_parameter: int) -> (
|
||||||
|
another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> (
|
||||||
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too)
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> ((also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
|
))
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure inner one-element tuple won't explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||||
|
)
|
||||||
|
|
||||||
|
# Inner trailing comma causes outer to explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1, (one, two,), argument4, argument5, argument6
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -38,16 +38,16 @@
|
||||||
|
}["a"]
|
||||||
|
if (
|
||||||
|
a
|
||||||
|
- == {
|
||||||
|
- "a": 1,
|
||||||
|
- "b": 2,
|
||||||
|
- "c": 3,
|
||||||
|
- "d": 4,
|
||||||
|
- "e": 5,
|
||||||
|
- "f": 6,
|
||||||
|
- "g": 7,
|
||||||
|
- "h": 8,
|
||||||
|
- }["a"]
|
||||||
|
+ == {
|
||||||
|
+ "a": 1,
|
||||||
|
+ "b": 2,
|
||||||
|
+ "c": 3,
|
||||||
|
+ "d": 4,
|
||||||
|
+ "e": 5,
|
||||||
|
+ "f": 6,
|
||||||
|
+ "g": 7,
|
||||||
|
+ "h": 8,
|
||||||
|
+ }["a"]
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
def f(
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
}
|
||||||
|
tup = (1,)
|
||||||
|
|
||||||
|
|
||||||
|
def f2(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
"key2": "value2",
|
||||||
|
}
|
||||||
|
tup = (
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def f(
|
||||||
|
a: int = 1,
|
||||||
|
):
|
||||||
|
call(
|
||||||
|
arg={
|
||||||
|
"explode": "this",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
call2(
|
||||||
|
arg=[1, 2, 3],
|
||||||
|
)
|
||||||
|
x = {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
}["a"]
|
||||||
|
if (
|
||||||
|
a
|
||||||
|
== {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
"c": 3,
|
||||||
|
"d": 4,
|
||||||
|
"e": 5,
|
||||||
|
"f": 6,
|
||||||
|
"g": 7,
|
||||||
|
"h": 8,
|
||||||
|
}["a"]
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||||
|
Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
|
||||||
|
):
|
||||||
|
json = {
|
||||||
|
"k": {
|
||||||
|
"k2": {
|
||||||
|
"k3": [
|
||||||
|
1,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
|
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||||
|
def some_function_with_a_really_long_name() -> (
|
||||||
|
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_method_with_a_really_long_name(
|
||||||
|
very_long_parameter_so_yeah: str, another_long_parameter: int
|
||||||
|
) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> (
|
||||||
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
|
)
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> (
|
||||||
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
|
)
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure inner one-element tuple won't explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||||
|
)
|
||||||
|
|
||||||
|
# Inner trailing comma causes outer to explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1,
|
||||||
|
(
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
),
|
||||||
|
argument4,
|
||||||
|
argument5,
|
||||||
|
argument6,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
def f(
|
||||||
|
a,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
}
|
||||||
|
tup = (1,)
|
||||||
|
|
||||||
|
|
||||||
|
def f2(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
"key2": "value2",
|
||||||
|
}
|
||||||
|
tup = (
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def f(
|
||||||
|
a: int = 1,
|
||||||
|
):
|
||||||
|
call(
|
||||||
|
arg={
|
||||||
|
"explode": "this",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
call2(
|
||||||
|
arg=[1, 2, 3],
|
||||||
|
)
|
||||||
|
x = {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
}["a"]
|
||||||
|
if (
|
||||||
|
a
|
||||||
|
== {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
"c": 3,
|
||||||
|
"d": 4,
|
||||||
|
"e": 5,
|
||||||
|
"f": 6,
|
||||||
|
"g": 7,
|
||||||
|
"h": 8,
|
||||||
|
}["a"]
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||||
|
Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
|
||||||
|
):
|
||||||
|
json = {
|
||||||
|
"k": {
|
||||||
|
"k2": {
|
||||||
|
"k3": [
|
||||||
|
1,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
|
# Relevant bug report: https://github.com/psf/black/issues/2381.
|
||||||
|
def some_function_with_a_really_long_name() -> (
|
||||||
|
returning_a_deeply_nested_import_of_a_type_i_suppose
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_method_with_a_really_long_name(
|
||||||
|
very_long_parameter_so_yeah: str, another_long_parameter: int
|
||||||
|
) -> another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> (
|
||||||
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
|
)
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def func() -> (
|
||||||
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
|
)
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure inner one-element tuple won't explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1, (one_element_tuple,), argument4, argument5, argument6
|
||||||
|
)
|
||||||
|
|
||||||
|
# Inner trailing comma causes outer to explode
|
||||||
|
some_module.some_function(
|
||||||
|
argument1,
|
||||||
|
(
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
),
|
||||||
|
argument4,
|
||||||
|
argument5,
|
||||||
|
argument6,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/import_spacing.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""The asyncio package, tracking PEP 3156."""
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
from logging import (
|
||||||
|
WARNING
|
||||||
|
)
|
||||||
|
from logging import (
|
||||||
|
ERROR,
|
||||||
|
)
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# This relies on each of the submodules having an __all__ variable.
|
||||||
|
from .base_events import *
|
||||||
|
from .coroutines import *
|
||||||
|
from .events import * # comment here
|
||||||
|
|
||||||
|
from .futures import *
|
||||||
|
from .locks import * # comment here
|
||||||
|
from .protocols import *
|
||||||
|
|
||||||
|
from ..runners import * # comment here
|
||||||
|
from ..queues import *
|
||||||
|
from ..streams import *
|
||||||
|
|
||||||
|
from some_library import (
|
||||||
|
Just, Enough, Libraries, To, Fit, In, This, Nice, Split, Which, We, No, Longer, Use
|
||||||
|
)
|
||||||
|
from name_of_a_company.extremely_long_project_name.component.ttypes import CuteLittleServiceHandlerFactoryyy
|
||||||
|
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||||
|
|
||||||
|
from .a.b.c.subprocess import *
|
||||||
|
from . import (tasks)
|
||||||
|
from . import (A, B, C)
|
||||||
|
from . import SomeVeryLongNameAndAllOfItsAdditionalLetters1, \
|
||||||
|
SomeVeryLongNameAndAllOfItsAdditionalLetters2
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
base_events.__all__
|
||||||
|
+ coroutines.__all__
|
||||||
|
+ events.__all__
|
||||||
|
+ futures.__all__
|
||||||
|
+ locks.__all__
|
||||||
|
+ protocols.__all__
|
||||||
|
+ runners.__all__
|
||||||
|
+ queues.__all__
|
||||||
|
+ streams.__all__
|
||||||
|
+ tasks.__all__
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -52,13 +52,13 @@
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
base_events.__all__
|
||||||
|
- + coroutines.__all__
|
||||||
|
- + events.__all__
|
||||||
|
- + futures.__all__
|
||||||
|
- + locks.__all__
|
||||||
|
- + protocols.__all__
|
||||||
|
- + runners.__all__
|
||||||
|
- + queues.__all__
|
||||||
|
- + streams.__all__
|
||||||
|
- + tasks.__all__
|
||||||
|
+ + coroutines.__all__
|
||||||
|
+ + events.__all__
|
||||||
|
+ + futures.__all__
|
||||||
|
+ + locks.__all__
|
||||||
|
+ + protocols.__all__
|
||||||
|
+ + runners.__all__
|
||||||
|
+ + queues.__all__
|
||||||
|
+ + streams.__all__
|
||||||
|
+ + tasks.__all__
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""The asyncio package, tracking PEP 3156."""
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
from logging import WARNING
|
||||||
|
from logging import (
|
||||||
|
ERROR,
|
||||||
|
)
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# This relies on each of the submodules having an __all__ variable.
|
||||||
|
from .base_events import *
|
||||||
|
from .coroutines import *
|
||||||
|
from .events import * # comment here
|
||||||
|
|
||||||
|
from .futures import *
|
||||||
|
from .locks import * # comment here
|
||||||
|
from .protocols import *
|
||||||
|
|
||||||
|
from ..runners import * # comment here
|
||||||
|
from ..queues import *
|
||||||
|
from ..streams import *
|
||||||
|
|
||||||
|
from some_library import (
|
||||||
|
Just,
|
||||||
|
Enough,
|
||||||
|
Libraries,
|
||||||
|
To,
|
||||||
|
Fit,
|
||||||
|
In,
|
||||||
|
This,
|
||||||
|
Nice,
|
||||||
|
Split,
|
||||||
|
Which,
|
||||||
|
We,
|
||||||
|
No,
|
||||||
|
Longer,
|
||||||
|
Use,
|
||||||
|
)
|
||||||
|
from name_of_a_company.extremely_long_project_name.component.ttypes import (
|
||||||
|
CuteLittleServiceHandlerFactoryyy,
|
||||||
|
)
|
||||||
|
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||||
|
|
||||||
|
from .a.b.c.subprocess import *
|
||||||
|
from . import tasks
|
||||||
|
from . import A, B, C
|
||||||
|
from . import (
|
||||||
|
SomeVeryLongNameAndAllOfItsAdditionalLetters1,
|
||||||
|
SomeVeryLongNameAndAllOfItsAdditionalLetters2,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
base_events.__all__
|
||||||
|
+ coroutines.__all__
|
||||||
|
+ events.__all__
|
||||||
|
+ futures.__all__
|
||||||
|
+ locks.__all__
|
||||||
|
+ protocols.__all__
|
||||||
|
+ runners.__all__
|
||||||
|
+ queues.__all__
|
||||||
|
+ streams.__all__
|
||||||
|
+ tasks.__all__
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""The asyncio package, tracking PEP 3156."""
|
||||||
|
|
||||||
|
# flake8: noqa
|
||||||
|
|
||||||
|
from logging import WARNING
|
||||||
|
from logging import (
|
||||||
|
ERROR,
|
||||||
|
)
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# This relies on each of the submodules having an __all__ variable.
|
||||||
|
from .base_events import *
|
||||||
|
from .coroutines import *
|
||||||
|
from .events import * # comment here
|
||||||
|
|
||||||
|
from .futures import *
|
||||||
|
from .locks import * # comment here
|
||||||
|
from .protocols import *
|
||||||
|
|
||||||
|
from ..runners import * # comment here
|
||||||
|
from ..queues import *
|
||||||
|
from ..streams import *
|
||||||
|
|
||||||
|
from some_library import (
|
||||||
|
Just,
|
||||||
|
Enough,
|
||||||
|
Libraries,
|
||||||
|
To,
|
||||||
|
Fit,
|
||||||
|
In,
|
||||||
|
This,
|
||||||
|
Nice,
|
||||||
|
Split,
|
||||||
|
Which,
|
||||||
|
We,
|
||||||
|
No,
|
||||||
|
Longer,
|
||||||
|
Use,
|
||||||
|
)
|
||||||
|
from name_of_a_company.extremely_long_project_name.component.ttypes import (
|
||||||
|
CuteLittleServiceHandlerFactoryyy,
|
||||||
|
)
|
||||||
|
from name_of_a_company.extremely_long_project_name.extremely_long_component_name.ttypes import *
|
||||||
|
|
||||||
|
from .a.b.c.subprocess import *
|
||||||
|
from . import tasks
|
||||||
|
from . import A, B, C
|
||||||
|
from . import (
|
||||||
|
SomeVeryLongNameAndAllOfItsAdditionalLetters1,
|
||||||
|
SomeVeryLongNameAndAllOfItsAdditionalLetters2,
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
base_events.__all__
|
||||||
|
+ coroutines.__all__
|
||||||
|
+ events.__all__
|
||||||
|
+ futures.__all__
|
||||||
|
+ locks.__all__
|
||||||
|
+ protocols.__all__
|
||||||
|
+ runners.__all__
|
||||||
|
+ queues.__all__
|
||||||
|
+ streams.__all__
|
||||||
|
+ tasks.__all__
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -304,7 +304,52 @@ long_unmergable_string_with_pragma = (
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -165,13 +165,9 @@
|
@@ -40,11 +40,11 @@
|
||||||
|
sooo="soooo", x=2
|
||||||
|
),
|
||||||
|
"A %s %s"
|
||||||
|
- % (
|
||||||
|
- "formatted",
|
||||||
|
- "string",
|
||||||
|
- ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
||||||
|
- % ("soooo", 2),
|
||||||
|
+ % (
|
||||||
|
+ "formatted",
|
||||||
|
+ "string",
|
||||||
|
+ ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
||||||
|
+ % ("soooo", 2),
|
||||||
|
}
|
||||||
|
|
||||||
|
func_with_keywords(
|
||||||
|
@@ -123,7 +123,7 @@
|
||||||
|
|
||||||
|
old_fmt_string1 = (
|
||||||
|
"While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
||||||
|
- % ("formatting", "code")
|
||||||
|
+ % ("formatting", "code")
|
||||||
|
)
|
||||||
|
|
||||||
|
old_fmt_string2 = "This is a %s %s %s %s" % (
|
||||||
|
@@ -135,12 +135,12 @@
|
||||||
|
|
||||||
|
old_fmt_string3 = (
|
||||||
|
"Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
||||||
|
- % (
|
||||||
|
- "really really really really really",
|
||||||
|
- "old",
|
||||||
|
- "way to format strings!",
|
||||||
|
- "Use f-strings instead!",
|
||||||
|
- )
|
||||||
|
+ % (
|
||||||
|
+ "really really really really really",
|
||||||
|
+ "old",
|
||||||
|
+ "way to format strings!",
|
||||||
|
+ "Use f-strings instead!",
|
||||||
|
+ )
|
||||||
|
)
|
||||||
|
|
||||||
|
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
|
||||||
|
@@ -165,36 +165,32 @@
|
||||||
|
|
||||||
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
|
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
|
||||||
|
|
||||||
@@ -320,21 +365,50 @@ long_unmergable_string_with_pragma = (
|
|||||||
"formatting"
|
"formatting"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -263,11 +259,11 @@
|
assert some_type_of_boolean_expression, (
|
||||||
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
||||||
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
- % "formatting"
|
||||||
|
+ % "formatting"
|
||||||
|
)
|
||||||
|
|
||||||
-short_string = "Hi" " there."
|
assert some_type_of_boolean_expression, (
|
||||||
+short_string = "Hi there."
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
||||||
|
- % ("string", "formatting")
|
||||||
|
+ % ("string", "formatting")
|
||||||
|
)
|
||||||
|
|
||||||
-func_call(short_string=("Hi" " there."))
|
some_function_call(
|
||||||
+func_call(short_string=("Hi there."))
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
|
- + added
|
||||||
|
- + " to a variable and then added to another string."
|
||||||
|
+ + added
|
||||||
|
+ + " to a variable and then added to another string."
|
||||||
|
)
|
||||||
|
|
||||||
-raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
|
some_function_call(
|
||||||
+raw_strings = r"Don't get merged unless they are all raw."
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
|
- + added
|
||||||
|
- + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
||||||
|
+ + added
|
||||||
|
+ + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
||||||
|
"and a second argument",
|
||||||
|
and_a_third,
|
||||||
|
)
|
||||||
|
@@ -249,10 +245,10 @@
|
||||||
|
|
||||||
|
annotated_variable: Final = (
|
||||||
def foo():
|
"This is a large "
|
||||||
|
- + STRING
|
||||||
|
- + " that has been "
|
||||||
|
- + CONCATENATED
|
||||||
|
- + "using the '+' operator."
|
||||||
|
+ + STRING
|
||||||
|
+ + " that has been "
|
||||||
|
+ + CONCATENATED
|
||||||
|
+ + "using the '+' operator."
|
||||||
|
)
|
||||||
|
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
||||||
|
annotated_variable: Literal[
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -382,11 +456,11 @@ D4 = {
|
|||||||
sooo="soooo", x=2
|
sooo="soooo", x=2
|
||||||
),
|
),
|
||||||
"A %s %s"
|
"A %s %s"
|
||||||
% (
|
% (
|
||||||
"formatted",
|
"formatted",
|
||||||
"string",
|
"string",
|
||||||
): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
||||||
% ("soooo", 2),
|
% ("soooo", 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
func_with_keywords(
|
func_with_keywords(
|
||||||
@@ -465,7 +539,7 @@ fmt_string2 = "But what about when the string is {} but {}".format(
|
|||||||
|
|
||||||
old_fmt_string1 = (
|
old_fmt_string1 = (
|
||||||
"While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
"While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
||||||
% ("formatting", "code")
|
% ("formatting", "code")
|
||||||
)
|
)
|
||||||
|
|
||||||
old_fmt_string2 = "This is a %s %s %s %s" % (
|
old_fmt_string2 = "This is a %s %s %s %s" % (
|
||||||
@@ -477,12 +551,12 @@ old_fmt_string2 = "This is a %s %s %s %s" % (
|
|||||||
|
|
||||||
old_fmt_string3 = (
|
old_fmt_string3 = (
|
||||||
"Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
"Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
||||||
% (
|
% (
|
||||||
"really really really really really",
|
"really really really really really",
|
||||||
"old",
|
"old",
|
||||||
"way to format strings!",
|
"way to format strings!",
|
||||||
"Use f-strings instead!",
|
"Use f-strings instead!",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
|
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
|
||||||
@@ -515,24 +589,24 @@ assert some_type_of_boolean_expression, "Followed by a really really really long
|
|||||||
|
|
||||||
assert some_type_of_boolean_expression, (
|
assert some_type_of_boolean_expression, (
|
||||||
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
||||||
% "formatting"
|
% "formatting"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert some_type_of_boolean_expression, (
|
assert some_type_of_boolean_expression, (
|
||||||
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
||||||
% ("string", "formatting")
|
% ("string", "formatting")
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
+ added
|
+ added
|
||||||
+ " to a variable and then added to another string."
|
+ " to a variable and then added to another string."
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
+ added
|
+ added
|
||||||
+ " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
+ " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
||||||
"and a second argument",
|
"and a second argument",
|
||||||
and_a_third,
|
and_a_third,
|
||||||
)
|
)
|
||||||
@@ -587,10 +661,10 @@ func_with_bad_parens(
|
|||||||
|
|
||||||
annotated_variable: Final = (
|
annotated_variable: Final = (
|
||||||
"This is a large "
|
"This is a large "
|
||||||
+ STRING
|
+ STRING
|
||||||
+ " that has been "
|
+ " that has been "
|
||||||
+ CONCATENATED
|
+ CONCATENATED
|
||||||
+ "using the '+' operator."
|
+ "using the '+' operator."
|
||||||
)
|
)
|
||||||
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
||||||
annotated_variable: Literal[
|
annotated_variable: Literal[
|
||||||
@@ -601,11 +675,11 @@ backslashes = "This is a really long string with \"embedded\" double quotes and
|
|||||||
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
||||||
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
||||||
|
|
||||||
short_string = "Hi there."
|
short_string = "Hi" " there."
|
||||||
|
|
||||||
func_call(short_string=("Hi there."))
|
func_call(short_string=("Hi" " there."))
|
||||||
|
|
||||||
raw_strings = r"Don't get merged unless they are all raw."
|
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
|
||||||
|
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
|
|||||||
@@ -95,7 +95,96 @@ def f(
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -63,7 +63,7 @@
|
@@ -1,17 +1,17 @@
|
||||||
|
# This has always worked
|
||||||
|
z = (
|
||||||
|
Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
)
|
||||||
|
|
||||||
|
# "AnnAssign"s now also work
|
||||||
|
z: (
|
||||||
|
Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
)
|
||||||
|
z: Short | Short2 | Short3 | Short4
|
||||||
|
z: int
|
||||||
|
@@ -20,9 +20,9 @@
|
||||||
|
|
||||||
|
z: (
|
||||||
|
Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
- | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
+ | Loooooooooooooooooooooooong
|
||||||
|
) = 7
|
||||||
|
z: Short | Short2 | Short3 | Short4 = 8
|
||||||
|
z: int = 2.3
|
||||||
|
@@ -31,39 +31,39 @@
|
||||||
|
# In case I go for not enforcing parantheses, this might get improved at the same time
|
||||||
|
x = (
|
||||||
|
z
|
||||||
|
- == 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999,
|
||||||
|
+ == 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999,
|
||||||
|
y
|
||||||
|
- == 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999,
|
||||||
|
+ == 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999,
|
||||||
|
)
|
||||||
|
|
||||||
|
x = (
|
||||||
|
z
|
||||||
|
- == (
|
||||||
|
- 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999
|
||||||
|
- | 9999999999999999999999999999999999999999
|
||||||
|
- ),
|
||||||
|
+ == (
|
||||||
|
+ 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999
|
||||||
|
+ | 9999999999999999999999999999999999999999
|
||||||
|
+ ),
|
||||||
|
y
|
||||||
|
- == (
|
||||||
|
- 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999
|
||||||
|
- + 9999999999999999999999999999999999999999
|
||||||
|
- ),
|
||||||
|
+ == (
|
||||||
|
+ 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999
|
||||||
|
+ + 9999999999999999999999999999999999999999
|
||||||
|
+ ),
|
||||||
|
)
|
||||||
|
|
||||||
|
# handle formatting of "tname"s in parameter list
|
||||||
|
|
||||||
|
|
||||||
# remove unnecessary paren
|
# remove unnecessary paren
|
||||||
@@ -110,14 +199,12 @@ def f(
|
|||||||
i: int,
|
i: int,
|
||||||
- x: (
|
- x: (
|
||||||
- Loooooooooooooooooooooooong
|
- Loooooooooooooooooooooooong
|
||||||
- | Looooooooooooooooong
|
+ x: Loooooooooooooooooooooooong
|
||||||
- | Looooooooooooooooooooong
|
| Looooooooooooooooong
|
||||||
|
| Looooooooooooooooooooong
|
||||||
- | Looooooong
|
- | Looooooong
|
||||||
- ),
|
- ),
|
||||||
+ x: Loooooooooooooooooooooooong
|
+ | Looooooong,
|
||||||
+ | Looooooooooooooooong
|
|
||||||
+ | Looooooooooooooooooooong
|
|
||||||
+ | Looooooong,
|
|
||||||
*,
|
*,
|
||||||
s: str,
|
s: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -138,17 +225,17 @@ def f(
|
|||||||
# This has always worked
|
# This has always worked
|
||||||
z = (
|
z = (
|
||||||
Loooooooooooooooooooooooong
|
Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
)
|
)
|
||||||
|
|
||||||
# "AnnAssign"s now also work
|
# "AnnAssign"s now also work
|
||||||
z: (
|
z: (
|
||||||
Loooooooooooooooooooooooong
|
Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
)
|
)
|
||||||
z: Short | Short2 | Short3 | Short4
|
z: Short | Short2 | Short3 | Short4
|
||||||
z: int
|
z: int
|
||||||
@@ -157,9 +244,9 @@ z: int
|
|||||||
|
|
||||||
z: (
|
z: (
|
||||||
Loooooooooooooooooooooooong
|
Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
| Loooooooooooooooooooooooong
|
| Loooooooooooooooooooooooong
|
||||||
) = 7
|
) = 7
|
||||||
z: Short | Short2 | Short3 | Short4 = 8
|
z: Short | Short2 | Short3 | Short4 = 8
|
||||||
z: int = 2.3
|
z: int = 2.3
|
||||||
@@ -168,32 +255,32 @@ z: int = foo()
|
|||||||
# In case I go for not enforcing parantheses, this might get improved at the same time
|
# In case I go for not enforcing parantheses, this might get improved at the same time
|
||||||
x = (
|
x = (
|
||||||
z
|
z
|
||||||
== 9999999999999999999999999999999999999999
|
== 9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999
|
| 9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999
|
| 9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999,
|
| 9999999999999999999999999999999999999999,
|
||||||
y
|
y
|
||||||
== 9999999999999999999999999999999999999999
|
== 9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999
|
+ 9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999
|
+ 9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999,
|
+ 9999999999999999999999999999999999999999,
|
||||||
)
|
)
|
||||||
|
|
||||||
x = (
|
x = (
|
||||||
z
|
z
|
||||||
== (
|
== (
|
||||||
9999999999999999999999999999999999999999
|
9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999
|
| 9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999
|
| 9999999999999999999999999999999999999999
|
||||||
| 9999999999999999999999999999999999999999
|
| 9999999999999999999999999999999999999999
|
||||||
),
|
),
|
||||||
y
|
y
|
||||||
== (
|
== (
|
||||||
9999999999999999999999999999999999999999
|
9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999
|
+ 9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999
|
+ 9999999999999999999999999999999999999999
|
||||||
+ 9999999999999999999999999999999999999999
|
+ 9999999999999999999999999999999999999999
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# handle formatting of "tname"s in parameter list
|
# handle formatting of "tname"s in parameter list
|
||||||
@@ -210,9 +297,9 @@ def foo(i: (int,)) -> None: ...
|
|||||||
def foo(
|
def foo(
|
||||||
i: int,
|
i: int,
|
||||||
x: Loooooooooooooooooooooooong
|
x: Loooooooooooooooooooooooong
|
||||||
| Looooooooooooooooong
|
| Looooooooooooooooong
|
||||||
| Looooooooooooooooooooong
|
| Looooooooooooooooooooong
|
||||||
| Looooooong,
|
| Looooooong,
|
||||||
*,
|
*,
|
||||||
s: str,
|
s: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/pep_604.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_very_long_name_function() -> my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | my_module.EvenMoreType | None:
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -6,9 +6,9 @@
|
||||||
|
|
||||||
|
def some_very_long_name_function() -> (
|
||||||
|
my_module.Asdf
|
||||||
|
- | my_module.AnotherType
|
||||||
|
- | my_module.YetAnotherType
|
||||||
|
- | my_module.EvenMoreType
|
||||||
|
- | None
|
||||||
|
+ | my_module.AnotherType
|
||||||
|
+ | my_module.YetAnotherType
|
||||||
|
+ | my_module.EvenMoreType
|
||||||
|
+ | None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
def some_very_long_name_function() -> (
|
||||||
|
my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_very_long_name_function() -> (
|
||||||
|
my_module.Asdf
|
||||||
|
| my_module.AnotherType
|
||||||
|
| my_module.YetAnotherType
|
||||||
|
| my_module.EvenMoreType
|
||||||
|
| None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
def some_very_long_name_function() -> (
|
||||||
|
my_module.Asdf | my_module.AnotherType | my_module.YetAnotherType | None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def some_very_long_name_function() -> (
|
||||||
|
my_module.Asdf
|
||||||
|
| my_module.AnotherType
|
||||||
|
| my_module.YetAnotherType
|
||||||
|
| my_module.EvenMoreType
|
||||||
|
| None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -13,12 +13,14 @@ importA;()<<0**0#
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -2,5 +2,5 @@
|
@@ -1,6 +1,6 @@
|
||||||
|
importA
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
<< 0
|
- << 0
|
||||||
- ** 0
|
- ** 0
|
||||||
+ **0
|
+ << 0
|
||||||
|
+ **0
|
||||||
) #
|
) #
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -28,8 +30,8 @@ importA;()<<0**0#
|
|||||||
importA
|
importA
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
<< 0
|
<< 0
|
||||||
**0
|
**0
|
||||||
) #
|
) #
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -85,21 +85,18 @@ class Random:
|
|||||||
- a_very_long_variable * and_a_very_long_function_call() / 100000.0
|
- a_very_long_variable * and_a_very_long_function_call() / 100000.0
|
||||||
- )
|
- )
|
||||||
+ "a key in my dict": a_very_long_variable
|
+ "a key in my dict": a_very_long_variable
|
||||||
+ * and_a_very_long_function_call()
|
+ * and_a_very_long_function_call()
|
||||||
+ / 100000.0
|
+ / 100000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
my_dict = {
|
my_dict = {
|
||||||
- "a key in my dict": (
|
- "a key in my dict": (
|
||||||
- a_very_long_variable
|
- a_very_long_variable
|
||||||
- * and_a_very_long_function_call()
|
|
||||||
- * and_another_long_func()
|
|
||||||
- / 100000.0
|
|
||||||
- )
|
|
||||||
+ "a key in my dict": a_very_long_variable
|
+ "a key in my dict": a_very_long_variable
|
||||||
+ * and_a_very_long_function_call()
|
* and_a_very_long_function_call()
|
||||||
+ * and_another_long_func()
|
* and_another_long_func()
|
||||||
+ / 100000.0
|
/ 100000.0
|
||||||
|
- )
|
||||||
}
|
}
|
||||||
|
|
||||||
my_dict = {
|
my_dict = {
|
||||||
@@ -140,15 +137,15 @@ my_dict = {
|
|||||||
|
|
||||||
my_dict = {
|
my_dict = {
|
||||||
"a key in my dict": a_very_long_variable
|
"a key in my dict": a_very_long_variable
|
||||||
* and_a_very_long_function_call()
|
* and_a_very_long_function_call()
|
||||||
/ 100000.0
|
/ 100000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
my_dict = {
|
my_dict = {
|
||||||
"a key in my dict": a_very_long_variable
|
"a key in my dict": a_very_long_variable
|
||||||
* and_a_very_long_function_call()
|
* and_a_very_long_function_call()
|
||||||
* and_another_long_func()
|
* and_another_long_func()
|
||||||
/ 100000.0
|
/ 100000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
my_dict = {
|
my_dict = {
|
||||||
|
|||||||
@@ -439,11 +439,11 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
- "This is a really really really long string that has to go inside of a"
|
- "This is a really really really long string that has to go inside of a"
|
||||||
- " dictionary. It is %s bad (#%d)." % ("soooo", 2)
|
- " dictionary. It is %s bad (#%d)." % ("soooo", 2)
|
||||||
- ),
|
- ),
|
||||||
+ % (
|
+ % (
|
||||||
+ "formatted",
|
+ "formatted",
|
||||||
+ "string",
|
+ "string",
|
||||||
+ ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
+ ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
||||||
+ % ("soooo", 2),
|
+ % ("soooo", 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
D5 = { # Test for https://github.com/psf/black/issues/3261
|
D5 = { # Test for https://github.com/psf/black/issues/3261
|
||||||
@@ -622,22 +622,29 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
- "While we are on the topic of %s, we should also note that old-style formatting"
|
- "While we are on the topic of %s, we should also note that old-style formatting"
|
||||||
- " must also be preserved, since some %s still uses it." % ("formatting", "code")
|
- " must also be preserved, since some %s still uses it." % ("formatting", "code")
|
||||||
+ "While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
+ "While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
||||||
+ % ("formatting", "code")
|
+ % ("formatting", "code")
|
||||||
)
|
)
|
||||||
|
|
||||||
old_fmt_string2 = "This is a %s %s %s %s" % (
|
old_fmt_string2 = "This is a %s %s %s %s" % (
|
||||||
@@ -271,8 +201,7 @@
|
@@ -271,36 +201,23 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
old_fmt_string3 = (
|
old_fmt_string3 = (
|
||||||
- "Whereas only the strings after the percent sign were long in the last example,"
|
- "Whereas only the strings after the percent sign were long in the last example,"
|
||||||
- " this example uses a long initial string as well. This is another %s %s %s %s"
|
- " this example uses a long initial string as well. This is another %s %s %s %s"
|
||||||
|
- % (
|
||||||
|
- "really really really really really",
|
||||||
|
- "old",
|
||||||
|
- "way to format strings!",
|
||||||
|
- "Use f-strings instead!",
|
||||||
|
- )
|
||||||
+ "Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
+ "Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
||||||
% (
|
+ % (
|
||||||
"really really really really really",
|
+ "really really really really really",
|
||||||
"old",
|
+ "old",
|
||||||
@@ -281,26 +210,14 @@
|
+ "way to format strings!",
|
||||||
)
|
+ "Use f-strings instead!",
|
||||||
|
+ )
|
||||||
)
|
)
|
||||||
|
|
||||||
-fstring = (
|
-fstring = (
|
||||||
@@ -688,33 +695,37 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
- "Followed by a really really really long string that is used to provide context to"
|
- "Followed by a really really really long string that is used to provide context to"
|
||||||
- " the AssertionError exception, which uses dynamic string %s." % "formatting"
|
- " the AssertionError exception, which uses dynamic string %s." % "formatting"
|
||||||
+ "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
+ "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
||||||
+ % "formatting"
|
+ % "formatting"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert some_type_of_boolean_expression, (
|
assert some_type_of_boolean_expression, (
|
||||||
- "Followed by a really really really long string that is used to provide context to"
|
- "Followed by a really really really long string that is used to provide context to"
|
||||||
- " the AssertionError exception, which uses dynamic %s %s."
|
- " the AssertionError exception, which uses dynamic %s %s."
|
||||||
|
- % ("string", "formatting")
|
||||||
+ "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
+ "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
||||||
% ("string", "formatting")
|
+ % ("string", "formatting")
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
- "With a reallly generic name and with a really really long string that is, at some"
|
- "With a reallly generic name and with a really really long string that is, at some"
|
||||||
- " point down the line, "
|
- " point down the line, "
|
||||||
|
- + added
|
||||||
|
- + " to a variable and then added to another string."
|
||||||
+ "With a reallly generic name and with a really really long string that is, at some point down the line, "
|
+ "With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
+ added
|
+ + added
|
||||||
+ " to a variable and then added to another string."
|
+ + " to a variable and then added to another string."
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
- "With a reallly generic name and with a really really long string that is, at some"
|
- "With a reallly generic name and with a really really long string that is, at some"
|
||||||
- " point down the line, "
|
- " point down the line, "
|
||||||
+ "With a reallly generic name and with a really really long string that is, at some point down the line, "
|
- + added
|
||||||
+ added
|
|
||||||
- + " to a variable and then added to another string. But then what happens when the"
|
- + " to a variable and then added to another string. But then what happens when the"
|
||||||
- " final string is also supppppperrrrr long?! Well then that second (realllllllly"
|
- " final string is also supppppperrrrr long?! Well then that second (realllllllly"
|
||||||
- " long) string should be split too.",
|
- " long) string should be split too.",
|
||||||
+ + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
+ "With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
|
+ + added
|
||||||
|
+ + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
||||||
"and a second argument",
|
"and a second argument",
|
||||||
and_a_third,
|
and_a_third,
|
||||||
)
|
)
|
||||||
@@ -772,7 +783,7 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
@@ -397,7 +306,7 @@
|
@@ -397,61 +306,38 @@
|
||||||
func_with_bad_parens(
|
func_with_bad_parens(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
@@ -781,14 +792,21 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
z,
|
z,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -408,50 +317,27 @@
|
annotated_variable: Final = (
|
||||||
+ CONCATENATED
|
"This is a large "
|
||||||
+ "using the '+' operator."
|
- + STRING
|
||||||
)
|
- + " that has been "
|
||||||
|
- + CONCATENATED
|
||||||
|
- + "using the '+' operator."
|
||||||
|
-)
|
||||||
-annotated_variable: Final = (
|
-annotated_variable: Final = (
|
||||||
- "This is a large string that has a type annotation attached to it. A type"
|
- "This is a large string that has a type annotation attached to it. A type"
|
||||||
- " annotation should NOT stop a long string from being wrapped."
|
- " annotation should NOT stop a long string from being wrapped."
|
||||||
-)
|
+ + STRING
|
||||||
|
+ + " that has been "
|
||||||
|
+ + CONCATENATED
|
||||||
|
+ + "using the '+' operator."
|
||||||
|
)
|
||||||
+annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
+annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
||||||
annotated_variable: Literal["fakse_literal"] = (
|
annotated_variable: Literal["fakse_literal"] = (
|
||||||
- "This is a large string that has a type annotation attached to it. A type"
|
- "This is a large string that has a type annotation attached to it. A type"
|
||||||
@@ -813,13 +831,13 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
+backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
+backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
||||||
+backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
+backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
||||||
|
|
||||||
short_string = "Hi there."
|
-short_string = "Hi there."
|
||||||
|
+short_string = "Hi" " there."
|
||||||
|
|
||||||
-func_call(short_string="Hi there.")
|
-func_call(short_string="Hi there.")
|
||||||
+func_call(short_string=("Hi there."))
|
+func_call(short_string=("Hi" " there."))
|
||||||
|
|
||||||
-raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
|
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
|
||||||
+raw_strings = r"Don't get merged unless they are all raw."
|
|
||||||
|
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
@@ -910,15 +928,16 @@ log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share
|
|||||||
- + ", \n".join(
|
- + ", \n".join(
|
||||||
- " (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
- " (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
||||||
- for attrname, visit_name in names
|
- for attrname, visit_name in names
|
||||||
+ (" return [\n")
|
- )
|
||||||
+ + (
|
|
||||||
+ ", \n".join(
|
|
||||||
+ " (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
|
||||||
+ for attrname, visit_name in names
|
|
||||||
+ )
|
|
||||||
)
|
|
||||||
- + "\n ]\n"
|
- + "\n ]\n"
|
||||||
+ + ("\n ]\n")
|
+ (" return [\n")
|
||||||
|
+ + (
|
||||||
|
+ ", \n".join(
|
||||||
|
+ " (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
||||||
|
+ for attrname, visit_name in names
|
||||||
|
+ )
|
||||||
|
+ )
|
||||||
|
+ + ("\n ]\n")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1028,11 +1047,11 @@ D4 = {
|
|||||||
sooo="soooo", x=2
|
sooo="soooo", x=2
|
||||||
),
|
),
|
||||||
"A %s %s"
|
"A %s %s"
|
||||||
% (
|
% (
|
||||||
"formatted",
|
"formatted",
|
||||||
"string",
|
"string",
|
||||||
): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
|
||||||
% ("soooo", 2),
|
% ("soooo", 2),
|
||||||
}
|
}
|
||||||
|
|
||||||
D5 = { # Test for https://github.com/psf/black/issues/3261
|
D5 = { # Test for https://github.com/psf/black/issues/3261
|
||||||
@@ -1178,7 +1197,7 @@ fmt_string2 = "But what about when the string is {} but {}".format(
|
|||||||
|
|
||||||
old_fmt_string1 = (
|
old_fmt_string1 = (
|
||||||
"While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
"While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it."
|
||||||
% ("formatting", "code")
|
% ("formatting", "code")
|
||||||
)
|
)
|
||||||
|
|
||||||
old_fmt_string2 = "This is a %s %s %s %s" % (
|
old_fmt_string2 = "This is a %s %s %s %s" % (
|
||||||
@@ -1190,12 +1209,12 @@ old_fmt_string2 = "This is a %s %s %s %s" % (
|
|||||||
|
|
||||||
old_fmt_string3 = (
|
old_fmt_string3 = (
|
||||||
"Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
"Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s"
|
||||||
% (
|
% (
|
||||||
"really really really really really",
|
"really really really really really",
|
||||||
"old",
|
"old",
|
||||||
"way to format strings!",
|
"way to format strings!",
|
||||||
"Use f-strings instead!",
|
"Use f-strings instead!",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
|
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
|
||||||
@@ -1228,24 +1247,24 @@ assert some_type_of_boolean_expression, "Followed by a really really really long
|
|||||||
|
|
||||||
assert some_type_of_boolean_expression, (
|
assert some_type_of_boolean_expression, (
|
||||||
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
|
||||||
% "formatting"
|
% "formatting"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert some_type_of_boolean_expression, (
|
assert some_type_of_boolean_expression, (
|
||||||
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
"Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
|
||||||
% ("string", "formatting")
|
% ("string", "formatting")
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
+ added
|
+ added
|
||||||
+ " to a variable and then added to another string."
|
+ " to a variable and then added to another string."
|
||||||
)
|
)
|
||||||
|
|
||||||
some_function_call(
|
some_function_call(
|
||||||
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
"With a reallly generic name and with a really really long string that is, at some point down the line, "
|
||||||
+ added
|
+ added
|
||||||
+ " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
+ " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.",
|
||||||
"and a second argument",
|
"and a second argument",
|
||||||
and_a_third,
|
and_a_third,
|
||||||
)
|
)
|
||||||
@@ -1300,10 +1319,10 @@ func_with_bad_parens(
|
|||||||
|
|
||||||
annotated_variable: Final = (
|
annotated_variable: Final = (
|
||||||
"This is a large "
|
"This is a large "
|
||||||
+ STRING
|
+ STRING
|
||||||
+ " that has been "
|
+ " that has been "
|
||||||
+ CONCATENATED
|
+ CONCATENATED
|
||||||
+ "using the '+' operator."
|
+ "using the '+' operator."
|
||||||
)
|
)
|
||||||
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
|
||||||
annotated_variable: Literal["fakse_literal"] = (
|
annotated_variable: Literal["fakse_literal"] = (
|
||||||
@@ -1314,11 +1333,11 @@ backslashes = "This is a really long string with \"embedded\" double quotes and
|
|||||||
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
|
||||||
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
|
||||||
|
|
||||||
short_string = "Hi there."
|
short_string = "Hi" " there."
|
||||||
|
|
||||||
func_call(short_string=("Hi there."))
|
func_call(short_string=("Hi" " there."))
|
||||||
|
|
||||||
raw_strings = r"Don't get merged unless they are all raw."
|
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
|
||||||
|
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
@@ -1372,13 +1391,13 @@ dict_with_lambda_values = {
|
|||||||
# Complex string concatenations with a method call in the middle.
|
# Complex string concatenations with a method call in the middle.
|
||||||
code = (
|
code = (
|
||||||
(" return [\n")
|
(" return [\n")
|
||||||
+ (
|
+ (
|
||||||
", \n".join(
|
", \n".join(
|
||||||
" (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
" (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
|
||||||
for attrname, visit_name in names
|
for attrname, visit_name in names
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
+ ("\n ]\n")
|
||||||
+ ("\n ]\n")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -99,18 +99,19 @@ msg += "This long string should not be split at any point ever since it is just
|
|||||||
some_string_inside_a_variable
|
some_string_inside_a_variable
|
||||||
- + "Some string that is just long enough to cause a split to take"
|
- + "Some string that is just long enough to cause a split to take"
|
||||||
- " place.............",
|
- " place.............",
|
||||||
+ + "Some string that is just long enough to cause a split to take place.............",
|
+ + "Some string that is just long enough to cause a split to take place.............",
|
||||||
xyz,
|
xyz,
|
||||||
- "Some really long string that needs to get split eventually but I'm running out of"
|
- "Some really long string that needs to get split eventually but I'm running out of"
|
||||||
- " things to say"
|
- " things to say"
|
||||||
|
- + some_string_inside_a_variable,
|
||||||
+ "Some really long string that needs to get split eventually but I'm running out of things to say"
|
+ "Some really long string that needs to get split eventually but I'm running out of things to say"
|
||||||
+ some_string_inside_a_variable,
|
+ + some_string_inside_a_variable,
|
||||||
)
|
)
|
||||||
addition_inside_tuple = (
|
addition_inside_tuple = (
|
||||||
some_string_inside_a_variable
|
some_string_inside_a_variable
|
||||||
- + "Some string that is just long enough to cause a split to take"
|
- + "Some string that is just long enough to cause a split to take"
|
||||||
- " place.............."
|
- " place.............."
|
||||||
+ + "Some string that is just long enough to cause a split to take place.............."
|
+ + "Some string that is just long enough to cause a split to take place.............."
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
"Hi there. This is areally really reallllly long string that needs to be split!!!"
|
"Hi there. This is areally really reallllly long string that needs to be split!!!"
|
||||||
@@ -131,20 +132,21 @@ msg += "This long string should not be split at any point ever since it is just
|
|||||||
str(result)
|
str(result)
|
||||||
- == "This long string should be split at some point right close to or around"
|
- == "This long string should be split at some point right close to or around"
|
||||||
- " hereeeeeee"
|
- " hereeeeeee"
|
||||||
+ == "This long string should be split at some point right close to or around hereeeeeee"
|
+ == "This long string should be split at some point right close to or around hereeeeeee"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
str(result)
|
str(result)
|
||||||
- < "This long string should be split at some point right close to or around"
|
- < "This long string should be split at some point right close to or around"
|
||||||
- " hereeeeee"
|
- " hereeeeee"
|
||||||
+ < "This long string should be split at some point right close to or around hereeeeee"
|
+ < "This long string should be split at some point right close to or around hereeeeee"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"A format string: %s"
|
"A format string: %s"
|
||||||
- % "This long string should be split at some point right close to or around"
|
- % "This long string should be split at some point right close to or around"
|
||||||
- " hereeeeeee"
|
- " hereeeeeee"
|
||||||
+ % "This long string should be split at some point right close to or around hereeeeeee"
|
- != result
|
||||||
!= result
|
+ % "This long string should be split at some point right close to or around hereeeeeee"
|
||||||
|
+ != result
|
||||||
)
|
)
|
||||||
msg += (
|
msg += (
|
||||||
"This long string should be wrapped in parens at some point right around hereeeee"
|
"This long string should be wrapped in parens at some point right around hereeeee"
|
||||||
@@ -193,14 +195,14 @@ some_variable = (
|
|||||||
)
|
)
|
||||||
addition_inside_tuple = (
|
addition_inside_tuple = (
|
||||||
some_string_inside_a_variable
|
some_string_inside_a_variable
|
||||||
+ "Some string that is just long enough to cause a split to take place.............",
|
+ "Some string that is just long enough to cause a split to take place.............",
|
||||||
xyz,
|
xyz,
|
||||||
"Some really long string that needs to get split eventually but I'm running out of things to say"
|
"Some really long string that needs to get split eventually but I'm running out of things to say"
|
||||||
+ some_string_inside_a_variable,
|
+ some_string_inside_a_variable,
|
||||||
)
|
)
|
||||||
addition_inside_tuple = (
|
addition_inside_tuple = (
|
||||||
some_string_inside_a_variable
|
some_string_inside_a_variable
|
||||||
+ "Some string that is just long enough to cause a split to take place.............."
|
+ "Some string that is just long enough to cause a split to take place.............."
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
"Hi there. This is areally really reallllly long string that needs to be split!!!"
|
"Hi there. This is areally really reallllly long string that needs to be split!!!"
|
||||||
@@ -216,16 +218,16 @@ return (
|
|||||||
return f"{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaaa"
|
return f"{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaaa"
|
||||||
assert (
|
assert (
|
||||||
str(result)
|
str(result)
|
||||||
== "This long string should be split at some point right close to or around hereeeeeee"
|
== "This long string should be split at some point right close to or around hereeeeeee"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
str(result)
|
str(result)
|
||||||
< "This long string should be split at some point right close to or around hereeeeee"
|
< "This long string should be split at some point right close to or around hereeeeee"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
"A format string: %s"
|
"A format string: %s"
|
||||||
% "This long string should be split at some point right close to or around hereeeeeee"
|
% "This long string should be split at some point right close to or around hereeeeeee"
|
||||||
!= result
|
!= result
|
||||||
)
|
)
|
||||||
msg += (
|
msg += (
|
||||||
"This long string should be wrapped in parens at some point right around hereeeee"
|
"This long string should be wrapped in parens at some point right around hereeeee"
|
||||||
|
|||||||
@@ -660,7 +660,7 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- " on one line at alllll." % "formatting",
|
- " on one line at alllll." % "formatting",
|
||||||
+ (
|
+ (
|
||||||
+ "A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll."
|
+ "A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll."
|
||||||
+ % "formatting"
|
+ % "formatting"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -669,7 +669,7 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- " one line at alllll." % ("formatting", "string"),
|
- " one line at alllll." % ("formatting", "string"),
|
||||||
+ (
|
+ (
|
||||||
+ "A long string with {}. This {} is so long that it is ridiculous. It can't fit on one line at alllll."
|
+ "A long string with {}. This {} is so long that it is ridiculous. It can't fit on one line at alllll."
|
||||||
+ % ("formatting", "string")
|
+ % ("formatting", "string")
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -688,17 +688,17 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- xxxx.xxxxxxxxxxxxxx(xx),
|
- xxxx.xxxxxxxxxxxxxx(xx),
|
||||||
+ (
|
+ (
|
||||||
+ "xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
|
+ "xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
|
||||||
+ % (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
|
+ % (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
|
||||||
+ )
|
|
||||||
+ + (
|
|
||||||
+ " %.3f (%s) to %.3f (%s).\n"
|
|
||||||
+ % (
|
|
||||||
+ xxxx.xxxxxxxxx,
|
|
||||||
+ xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
|
|
||||||
+ x,
|
|
||||||
+ xxxx.xxxxxxxxxxxxxx(xx),
|
|
||||||
+ )
|
|
||||||
)
|
)
|
||||||
|
+ + (
|
||||||
|
+ " %.3f (%s) to %.3f (%s).\n"
|
||||||
|
+ % (
|
||||||
|
+ xxxx.xxxxxxxxx,
|
||||||
|
+ xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
|
||||||
|
+ x,
|
||||||
|
+ xxxx.xxxxxxxxxxxxxx(xx),
|
||||||
|
+ )
|
||||||
|
+ )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -777,9 +777,9 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- + "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx"
|
- + "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx"
|
||||||
- .xxxxxx(xxxxxx_xxxxxx_xxx)
|
- .xxxxxx(xxxxxx_xxxxxx_xxx)
|
||||||
+ "xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx "
|
+ "xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx "
|
||||||
+ + "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx".xxxxxx(
|
+ + "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx".xxxxxx(
|
||||||
+ xxxxxx_xxxxxx_xxx
|
+ xxxxxx_xxxxxx_xxx
|
||||||
+ )
|
+ )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -832,7 +832,7 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
|
|
||||||
some_commented_string = ( # This comment stays at the top.
|
some_commented_string = ( # This comment stays at the top.
|
||||||
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
|
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
|
||||||
@@ -279,36 +280,25 @@
|
@@ -279,37 +280,26 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
lpar_and_rpar_have_comments = func_call( # LPAR Comment
|
lpar_and_rpar_have_comments = func_call( # LPAR Comment
|
||||||
@@ -852,32 +852,33 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- f" {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
- f" {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
||||||
-)
|
-)
|
||||||
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
||||||
|
+
|
||||||
|
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
||||||
|
|
||||||
-cmd_fstring = (
|
-cmd_fstring = (
|
||||||
- "sudo -E deluge-console info --detailed --sort-reverse=time_added"
|
- "sudo -E deluge-console info --detailed --sort-reverse=time_added"
|
||||||
- f" {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
- f" {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
||||||
-)
|
-)
|
||||||
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
|
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {{'' if ID is None else ID}} | perl -nE 'print if /^{field}:/'"
|
||||||
|
|
||||||
-cmd_fstring = (
|
-cmd_fstring = (
|
||||||
- "sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is"
|
- "sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is"
|
||||||
- f" None else ID}} | perl -nE 'print if /^{field}:/'"
|
- f" None else ID}} | perl -nE 'print if /^{field}:/'"
|
||||||
-)
|
-)
|
||||||
+cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {{'' if ID is None else ID}} | perl -nE 'print if /^{field}:/'"
|
|
||||||
|
|
||||||
+fstring = f"This string really doesn't need to be an {{{{fstring}}}}, but this one most certainly, absolutely {does}."
|
+fstring = f"This string really doesn't need to be an {{{{fstring}}}}, but this one most certainly, absolutely {does}."
|
||||||
+
|
|
||||||
fstring = (
|
fstring = (
|
||||||
- "This string really doesn't need to be an {{fstring}}, but this one most"
|
- "This string really doesn't need to be an {{fstring}}, but this one most"
|
||||||
- f" certainly, absolutely {does}."
|
- f" certainly, absolutely {does}."
|
||||||
+ f"We have to remember to escape {braces}." " Like {these}." f" But not {this}."
|
+ f"We have to remember to escape {braces}." " Like {these}." f" But not {this}."
|
||||||
)
|
)
|
||||||
-
|
|
||||||
-fstring = f"We have to remember to escape {braces}. Like {{these}}. But not {this}."
|
|
||||||
|
|
||||||
|
-fstring = f"We have to remember to escape {braces}. Like {{these}}. But not {this}."
|
||||||
|
-
|
||||||
|
|
||||||
class A:
|
class A:
|
||||||
@@ -364,10 +354,7 @@
|
class B:
|
||||||
|
@@ -364,11 +354,8 @@
|
||||||
def foo():
|
def foo():
|
||||||
if not hasattr(module, name):
|
if not hasattr(module, name):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@@ -885,10 +886,12 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- " serialize things like inner classes. Please move the object into"
|
- " serialize things like inner classes. Please move the object into"
|
||||||
- " the main module body to use migrations.\nFor more information,"
|
- " the main module body to use migrations.\nFor more information,"
|
||||||
- " see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
- " see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
||||||
|
- % (name, module_name, get_docs_version())
|
||||||
+ "Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
+ "Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
||||||
% (name, module_name, get_docs_version())
|
+ % (name, module_name, get_docs_version())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -382,23 +369,19 @@
|
@@ -382,23 +369,19 @@
|
||||||
|
|
||||||
class Step(StepBase):
|
class Step(StepBase):
|
||||||
@@ -927,10 +930,19 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk"
|
- r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk"
|
||||||
- r" '{print $2}'); do kill $pid; done" % (i)
|
- r" '{print $2}'); do kill $pid; done" % (i)
|
||||||
+ r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
|
+ r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
|
||||||
+ % (i)
|
+ % (i)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -423,7 +406,7 @@
|
||||||
|
def G():
|
||||||
|
assert (
|
||||||
|
c_float(val[0][0] / val[0][1]).value
|
||||||
|
- == c_float(value[0][0] / value[0][1]).value
|
||||||
|
+ == c_float(value[0][0] / value[0][1]).value
|
||||||
|
), "%s didn't roundtrip" % tag
|
||||||
|
|
||||||
|
|
||||||
@@ -432,9 +415,7 @@
|
@@ -432,9 +415,7 @@
|
||||||
assert xxxxxxx_xxxx in [
|
assert xxxxxxx_xxxx in [
|
||||||
x.xxxxx.xxxxxx.xxxxx.xxxxxx,
|
x.xxxxx.xxxxxx.xxxxx.xxxxxx,
|
||||||
@@ -1036,14 +1048,14 @@ s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:
|
|||||||
- in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
|
- in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
|
||||||
- " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$',"
|
- " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$',"
|
||||||
- " 'ykangaroo$']"
|
- " 'ykangaroo$']"
|
||||||
+ in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
+ in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
str(suffix_arr)
|
str(suffix_arr)
|
||||||
- not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
|
- not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
|
||||||
- " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$',"
|
- " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$',"
|
||||||
- " 'rykangaroo$', 'ykangaroo$']"
|
- " 'rykangaroo$', 'ykangaroo$']"
|
||||||
+ not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
+ not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
||||||
)
|
)
|
||||||
message = (
|
message = (
|
||||||
f"1. Go to Google Developers Console and log in with your Google account."
|
f"1. Go to Google Developers Console and log in with your Google account."
|
||||||
@@ -1323,14 +1335,14 @@ func_call_where_string_arg_has_method_call_and_bad_parens(
|
|||||||
func_call_where_string_arg_has_old_fmt_and_bad_parens(
|
func_call_where_string_arg_has_old_fmt_and_bad_parens(
|
||||||
(
|
(
|
||||||
"A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll."
|
"A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll."
|
||||||
% "formatting"
|
% "formatting"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
func_call_where_string_arg_has_old_fmt_and_bad_parens(
|
func_call_where_string_arg_has_old_fmt_and_bad_parens(
|
||||||
(
|
(
|
||||||
"A long string with {}. This {} is so long that it is ridiculous. It can't fit on one line at alllll."
|
"A long string with {}. This {} is so long that it is ridiculous. It can't fit on one line at alllll."
|
||||||
% ("formatting", "string")
|
% ("formatting", "string")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1341,17 +1353,17 @@ class A:
|
|||||||
xxxx.xxxxxxx.xxxxx(
|
xxxx.xxxxxxx.xxxxx(
|
||||||
(
|
(
|
||||||
"xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
|
"xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
|
||||||
% (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
|
% (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
" %.3f (%s) to %.3f (%s).\n"
|
" %.3f (%s) to %.3f (%s).\n"
|
||||||
% (
|
% (
|
||||||
xxxx.xxxxxxxxx,
|
xxxx.xxxxxxxxx,
|
||||||
xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
|
xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
|
||||||
x,
|
x,
|
||||||
xxxx.xxxxxxxxxxxxxx(xx),
|
xxxx.xxxxxxxxxxxxxx(xx),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1401,9 +1413,9 @@ class A:
|
|||||||
if True:
|
if True:
|
||||||
xxxxx_xxxxxxxxxxxx(
|
xxxxx_xxxxxxxxxxxx(
|
||||||
"xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx "
|
"xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx "
|
||||||
+ "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx".xxxxxx(
|
+ "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx".xxxxxx(
|
||||||
xxxxxx_xxxxxx_xxx
|
xxxxxx_xxxxxx_xxx
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1554,7 +1566,7 @@ class A:
|
|||||||
if not hasattr(module, name):
|
if not hasattr(module, name):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
"Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
||||||
% (name, module_name, get_docs_version())
|
% (name, module_name, get_docs_version())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1592,7 +1604,7 @@ if __name__ == "__main__":
|
|||||||
for i in range(4, 8):
|
for i in range(4, 8):
|
||||||
cmd = (
|
cmd = (
|
||||||
r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
|
r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
|
||||||
% (i)
|
% (i)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1605,7 +1617,7 @@ def A():
|
|||||||
def G():
|
def G():
|
||||||
assert (
|
assert (
|
||||||
c_float(val[0][0] / val[0][1]).value
|
c_float(val[0][0] / val[0][1]).value
|
||||||
== c_float(value[0][0] / value[0][1]).value
|
== c_float(value[0][0] / value[0][1]).value
|
||||||
), "%s didn't roundtrip" % tag
|
), "%s didn't roundtrip" % tag
|
||||||
|
|
||||||
|
|
||||||
@@ -1725,11 +1737,11 @@ assert str(suffix_arr) > (
|
|||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
str(suffix_arr)
|
str(suffix_arr)
|
||||||
in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
str(suffix_arr)
|
str(suffix_arr)
|
||||||
not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
|
||||||
)
|
)
|
||||||
message = (
|
message = (
|
||||||
f"1. Go to Google Developers Console and log in with your Google account."
|
f"1. Go to Google Developers Console and log in with your Google account."
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """dove
|
+ """dove
|
||||||
+ coo"""
|
+ coo"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -212,7 +212,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """dove
|
+ """dove
|
||||||
+coo"""
|
+coo"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -222,7 +222,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """cow
|
+ """cow
|
||||||
+ moo"""
|
+ moo"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
"dogsay",
|
"dogsay",
|
||||||
)
|
)
|
||||||
@@ -234,7 +234,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """crow
|
+ """crow
|
||||||
+ caw"""
|
+ caw"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -244,7 +244,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """cat
|
+ """cat
|
||||||
+ meow"""
|
+ meow"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
{"dog", "say"},
|
{"dog", "say"},
|
||||||
)
|
)
|
||||||
@@ -256,7 +256,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """horse
|
+ """horse
|
||||||
+ neigh"""
|
+ neigh"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -267,7 +267,7 @@ this_will_also_become_one_line = ( # comment
|
|||||||
+ textwrap.dedent(
|
+ textwrap.dedent(
|
||||||
+ """pig
|
+ """pig
|
||||||
+ oink"""
|
+ oink"""
|
||||||
+ % "cowabunga"
|
+ % "cowabunga"
|
||||||
+ ),
|
+ ),
|
||||||
)
|
)
|
||||||
textwrap.dedent("""A one-line triple-quoted string.""")
|
textwrap.dedent("""A one-line triple-quoted string.""")
|
||||||
@@ -391,7 +391,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""dove
|
"""dove
|
||||||
coo"""
|
coo"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -400,7 +400,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""dove
|
"""dove
|
||||||
coo"""
|
coo"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -408,7 +408,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""cow
|
"""cow
|
||||||
moo"""
|
moo"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
"dogsay",
|
"dogsay",
|
||||||
)
|
)
|
||||||
@@ -418,7 +418,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""crow
|
"""crow
|
||||||
caw"""
|
caw"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -426,7 +426,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""cat
|
"""cat
|
||||||
meow"""
|
meow"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
{"dog", "say"},
|
{"dog", "say"},
|
||||||
)
|
)
|
||||||
@@ -436,7 +436,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""horse
|
"""horse
|
||||||
neigh"""
|
neigh"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
call(
|
call(
|
||||||
@@ -445,7 +445,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""pig
|
"""pig
|
||||||
oink"""
|
oink"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
textwrap.dedent("""A one-line triple-quoted string.""")
|
textwrap.dedent("""A one-line triple-quoted string.""")
|
||||||
|
|||||||
@@ -0,0 +1,354 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_power_op_spacing.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
a = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
b = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
c = 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1 ** 1
|
||||||
|
d = 1**1 ** 1**1 ** 1**1 ** 1**1 ** 1**1**1 ** 1 ** 1**1 ** 1**1**1**1**1 ** 1 ** 1**1**1 **1**1** 1 ** 1 ** 1
|
||||||
|
e = 𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟
|
||||||
|
f = 𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟
|
||||||
|
|
||||||
|
a = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
b = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
c = 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0 ** 1.0
|
||||||
|
d = 1.0**1.0 ** 1.0**1.0 ** 1.0**1.0 ** 1.0**1.0 ** 1.0**1.0**1.0 ** 1.0 ** 1.0**1.0 ** 1.0**1.0**1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -1,83 +1,83 @@
|
||||||
|
a = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
b = (
|
||||||
|
1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
- ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
+ ** 1
|
||||||
|
)
|
||||||
|
c = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
d = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
e = 𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟
|
||||||
|
f = (
|
||||||
|
𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
- ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
+ ** 𨉟
|
||||||
|
)
|
||||||
|
|
||||||
|
a = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
b = (
|
||||||
|
1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
- ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
+ ** 1.0
|
||||||
|
)
|
||||||
|
c = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
d = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
a = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
b = (
|
||||||
|
1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
)
|
||||||
|
c = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
d = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
e = 𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟
|
||||||
|
f = (
|
||||||
|
𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
)
|
||||||
|
|
||||||
|
a = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
b = (
|
||||||
|
1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
)
|
||||||
|
c = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
d = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
a = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
b = (
|
||||||
|
1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
** 1
|
||||||
|
)
|
||||||
|
c = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
d = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
|
||||||
|
e = 𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟**𨉟
|
||||||
|
f = (
|
||||||
|
𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
** 𨉟
|
||||||
|
)
|
||||||
|
|
||||||
|
a = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
b = (
|
||||||
|
1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
** 1.0
|
||||||
|
)
|
||||||
|
c = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
d = 1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0**1.0
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +129,15 @@ a = (
|
|||||||
|
|
||||||
some_kind_of_table[
|
some_kind_of_table[
|
||||||
some_key # type: ignore # noqa: E501
|
some_key # type: ignore # noqa: E501
|
||||||
|
@@ -79,7 +77,7 @@
|
||||||
|
# Right side of assignment contains un-nested pairs of inner parens.
|
||||||
|
some_kind_of_instance.some_kind_of_map[a_key] = (
|
||||||
|
isinstance(some_var, SomeClass)
|
||||||
|
- and table.something_and_something != table.something_else
|
||||||
|
+ and table.something_and_something != table.something_else
|
||||||
|
) or (
|
||||||
|
isinstance(some_other_var, BaseClass) and table.something != table.some_other_thing
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
@@ -213,7 +222,7 @@ xxxxxxxxx_yyy_zzzzzzzz[
|
|||||||
# Right side of assignment contains un-nested pairs of inner parens.
|
# Right side of assignment contains un-nested pairs of inner parens.
|
||||||
some_kind_of_instance.some_kind_of_map[a_key] = (
|
some_kind_of_instance.some_kind_of_map[a_key] = (
|
||||||
isinstance(some_var, SomeClass)
|
isinstance(some_var, SomeClass)
|
||||||
and table.something_and_something != table.something_else
|
and table.something_and_something != table.something_else
|
||||||
) or (
|
) or (
|
||||||
isinstance(some_other_var, BaseClass) and table.something != table.some_other_thing
|
isinstance(some_other_var, BaseClass) and table.something != table.some_other_thing
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -127,6 +127,24 @@ def foo(a,b) -> tuple[int, int, int,]:
|
|||||||
return 2 * a
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
@@ -45,7 +53,7 @@
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
+ | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
@@ -64,7 +72,7 @@
|
||||||
|
c: int,
|
||||||
|
) -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
- | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
+ | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
@@ -124,5 +132,9 @@
|
@@ -124,5 +132,9 @@
|
||||||
# this is broken - the trailing comma is transferred to the param list. Fixed in preview
|
# this is broken - the trailing comma is transferred to the param list. Fixed in preview
|
||||||
def foo(
|
def foo(
|
||||||
@@ -198,7 +216,7 @@ def foo() -> (
|
|||||||
|
|
||||||
def foo() -> (
|
def foo() -> (
|
||||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
):
|
):
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
@@ -217,7 +235,7 @@ def foo(
|
|||||||
c: int,
|
c: int,
|
||||||
) -> (
|
) -> (
|
||||||
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
):
|
):
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ assert (
|
|||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -2,7 +2,7 @@
|
@@ -1,8 +1,8 @@
|
||||||
|
importA
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
<< 0
|
- << 0
|
||||||
- ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
- ** 101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||||
+ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
+ << 0
|
||||||
|
+ **101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||||
) #
|
) #
|
||||||
|
|
||||||
assert sort_by_dependency(
|
assert sort_by_dependency(
|
||||||
@@ -70,8 +72,8 @@ assert (
|
|||||||
importA
|
importA
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
<< 0
|
<< 0
|
||||||
**101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
**101234234242352525425252352352525234890264906820496920680926538059059209922523523525
|
||||||
) #
|
) #
|
||||||
|
|
||||||
assert sort_by_dependency(
|
assert sort_by_dependency(
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/trailing_comma_optional_parens1.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
if e1234123412341234.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
|
||||||
|
_winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if x:
|
||||||
|
if y:
|
||||||
|
new_id = max(Vegetable.objects.order_by('-id')[0].id,
|
||||||
|
Mineral.objects.order_by('-id')[0].id) + 1
|
||||||
|
|
||||||
|
class X:
|
||||||
|
def get_help_text(self):
|
||||||
|
return ngettext(
|
||||||
|
"Your password must contain at least %(min_length)d character.",
|
||||||
|
"Your password must contain at least %(min_length)d characters.",
|
||||||
|
self.min_length,
|
||||||
|
) % {'min_length': self.min_length}
|
||||||
|
|
||||||
|
class A:
|
||||||
|
def b(self):
|
||||||
|
if self.connection.mysql_is_mariadb and (
|
||||||
|
10,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
) < self.connection.mysql_version < (10, 5, 2):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -11,7 +11,7 @@
|
||||||
|
Vegetable.objects.order_by("-id")[0].id,
|
||||||
|
Mineral.objects.order_by("-id")[0].id,
|
||||||
|
)
|
||||||
|
- + 1
|
||||||
|
+ + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
if e1234123412341234.winerror not in (
|
||||||
|
_winapi.ERROR_SEM_TIMEOUT,
|
||||||
|
_winapi.ERROR_PIPE_BUSY,
|
||||||
|
) or _check_timeout(t):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if x:
|
||||||
|
if y:
|
||||||
|
new_id = (
|
||||||
|
max(
|
||||||
|
Vegetable.objects.order_by("-id")[0].id,
|
||||||
|
Mineral.objects.order_by("-id")[0].id,
|
||||||
|
)
|
||||||
|
+ 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class X:
|
||||||
|
def get_help_text(self):
|
||||||
|
return ngettext(
|
||||||
|
"Your password must contain at least %(min_length)d character.",
|
||||||
|
"Your password must contain at least %(min_length)d characters.",
|
||||||
|
self.min_length,
|
||||||
|
) % {"min_length": self.min_length}
|
||||||
|
|
||||||
|
|
||||||
|
class A:
|
||||||
|
def b(self):
|
||||||
|
if self.connection.mysql_is_mariadb and (
|
||||||
|
10,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
) < self.connection.mysql_version < (10, 5, 2):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
if e1234123412341234.winerror not in (
|
||||||
|
_winapi.ERROR_SEM_TIMEOUT,
|
||||||
|
_winapi.ERROR_PIPE_BUSY,
|
||||||
|
) or _check_timeout(t):
|
||||||
|
pass
|
||||||
|
|
||||||
|
if x:
|
||||||
|
if y:
|
||||||
|
new_id = (
|
||||||
|
max(
|
||||||
|
Vegetable.objects.order_by("-id")[0].id,
|
||||||
|
Mineral.objects.order_by("-id")[0].id,
|
||||||
|
)
|
||||||
|
+ 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class X:
|
||||||
|
def get_help_text(self):
|
||||||
|
return ngettext(
|
||||||
|
"Your password must contain at least %(min_length)d character.",
|
||||||
|
"Your password must contain at least %(min_length)d characters.",
|
||||||
|
self.min_length,
|
||||||
|
) % {"min_length": self.min_length}
|
||||||
|
|
||||||
|
|
||||||
|
class A:
|
||||||
|
def b(self):
|
||||||
|
if self.connection.mysql_is_mariadb and (
|
||||||
|
10,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
) < self.connection.mysql_version < (10, 5, 2):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/cases/trailing_comma_optional_parens3.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```python
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
return _(
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
|
||||||
|
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
|
||||||
|
) % {"reported_username": reported_username, "report_reason": report_reason}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Differences
|
||||||
|
|
||||||
|
```diff
|
||||||
|
--- Black
|
||||||
|
+++ Ruff
|
||||||
|
@@ -3,6 +3,6 @@
|
||||||
|
if True:
|
||||||
|
return _(
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
|
||||||
|
- + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
|
||||||
|
+ + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
|
||||||
|
) % {"reported_username": reported_username, "report_reason": report_reason}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ruff Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
return _(
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
|
||||||
|
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
|
||||||
|
) % {"reported_username": reported_username, "report_reason": report_reason}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Black Output
|
||||||
|
|
||||||
|
```python
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
if True:
|
||||||
|
return _(
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas "
|
||||||
|
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
|
||||||
|
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
|
||||||
|
) % {"reported_username": reported_username, "report_reason": report_reason}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +56,12 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
|||||||
|
|
||||||
|
|
||||||
# Example from https://github.com/psf/black/issues/3229
|
# Example from https://github.com/psf/black/issues/3229
|
||||||
@@ -43,8 +41,6 @@
|
@@ -39,12 +37,10 @@
|
||||||
|
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||||
|
assert (
|
||||||
|
long_module.long_class.long_func().another_func()
|
||||||
|
- == long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||||
|
+ == long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3414.
|
# Regression test for https://github.com/psf/black/issues/3414.
|
||||||
@@ -112,7 +117,7 @@ def refresh_token(self, device_family, refresh_token, api_key):
|
|||||||
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
# https://github.com/psf/black/pull/3370 causes an infinite recursion.
|
||||||
assert (
|
assert (
|
||||||
long_module.long_class.long_func().another_func()
|
long_module.long_class.long_func().another_func()
|
||||||
== long_module.long_class.long_func()["some_key"].another_func(arg1)
|
== long_module.long_class.long_func()["some_key"].another_func(arg1)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Regression test for https://github.com/psf/black/issues/3414.
|
# Regression test for https://github.com/psf/black/issues/3414.
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ class IndentMeSome:
|
|||||||
|
|
||||||
|
|
||||||
class IgnoreImplicitlyConcatenatedStrings:
|
class IgnoreImplicitlyConcatenatedStrings:
|
||||||
""""""
|
"""""" ""
|
||||||
|
|
||||||
|
|
||||||
def docstring_that_ends_with_quote_and_a_line_break1():
|
def docstring_that_ends_with_quote_and_a_line_break1():
|
||||||
@@ -432,7 +432,7 @@ class IndentMeSome:
|
|||||||
|
|
||||||
|
|
||||||
class IgnoreImplicitlyConcatenatedStrings:
|
class IgnoreImplicitlyConcatenatedStrings:
|
||||||
""""""
|
"""""" ""
|
||||||
|
|
||||||
|
|
||||||
def docstring_that_ends_with_quote_and_a_line_break1():
|
def docstring_that_ends_with_quote_and_a_line_break1():
|
||||||
@@ -608,7 +608,7 @@ class IndentMeSome:
|
|||||||
|
|
||||||
|
|
||||||
class IgnoreImplicitlyConcatenatedStrings:
|
class IgnoreImplicitlyConcatenatedStrings:
|
||||||
""""""
|
"""""" ""
|
||||||
|
|
||||||
|
|
||||||
def docstring_that_ends_with_quote_and_a_line_break1():
|
def docstring_that_ends_with_quote_and_a_line_break1():
|
||||||
@@ -784,7 +784,7 @@ class IndentMeSome:
|
|||||||
|
|
||||||
|
|
||||||
class IgnoreImplicitlyConcatenatedStrings:
|
class IgnoreImplicitlyConcatenatedStrings:
|
||||||
""""""
|
"""""" ""
|
||||||
|
|
||||||
|
|
||||||
def docstring_that_ends_with_quote_and_a_line_break1():
|
def docstring_that_ends_with_quote_and_a_line_break1():
|
||||||
@@ -960,7 +960,7 @@ class IndentMeSome:
|
|||||||
|
|
||||||
|
|
||||||
class IgnoreImplicitlyConcatenatedStrings:
|
class IgnoreImplicitlyConcatenatedStrings:
|
||||||
""""""
|
"""""" ''
|
||||||
|
|
||||||
|
|
||||||
def docstring_that_ends_with_quote_and_a_line_break1():
|
def docstring_that_ends_with_quote_and_a_line_break1():
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ x6 = (
|
|||||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
||||||
result = (
|
result = (
|
||||||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||||
+ 1
|
+ 1
|
||||||
).bit_length()
|
).bit_length()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -78,20 +78,20 @@ result = await self.request(
|
|||||||
|
|
||||||
result = await (
|
result = await (
|
||||||
1
|
1
|
||||||
+ f(
|
+ f(
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await (
|
result = await (
|
||||||
1
|
1
|
||||||
+ f(
|
+ f(
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Optional parentheses.
|
# Optional parentheses.
|
||||||
|
|||||||
@@ -430,28 +430,28 @@ if True:
|
|||||||
```python
|
```python
|
||||||
(
|
(
|
||||||
aaaaaaaa
|
aaaaaaaa
|
||||||
+ # trailing operator comment
|
+ # trailing operator comment
|
||||||
b # trailing right comment
|
b # trailing right comment
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
(
|
(
|
||||||
aaaaaaaa # trailing left comment
|
aaaaaaaa # trailing left comment
|
||||||
+ # trailing operator comment
|
+ # trailing operator comment
|
||||||
# leading right comment
|
# leading right comment
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
# leading left most comment
|
# leading left most comment
|
||||||
aaaaaaaa
|
aaaaaaaa
|
||||||
+ # trailing operator comment
|
+ # trailing operator comment
|
||||||
# leading b comment
|
# leading b comment
|
||||||
b # trailing b comment
|
b # trailing b comment
|
||||||
# trailing b ownline comment
|
# trailing b ownline comment
|
||||||
+ # trailing second operator comment
|
+ # trailing second operator comment
|
||||||
# leading c comment
|
# leading c comment
|
||||||
c # trailing c comment
|
c # trailing c comment
|
||||||
# trailing own line comment
|
# trailing own line comment
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -497,21 +497,24 @@ aaaaaaaaaaaaaa + {
|
|||||||
# Wraps it in parentheses if it needs to break both left and right
|
# Wraps it in parentheses if it needs to break both left and right
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ [bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eee]
|
+ [bbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc, dddddddddddddddd, eee]
|
||||||
) # comment
|
) # comment
|
||||||
|
|
||||||
|
|
||||||
# But only for expressions that have a statement parent.
|
# But only for expressions that have a statement parent.
|
||||||
not (
|
not (
|
||||||
aaaaaaaaaaaaaa
|
aaaaaaaaaaaaaa
|
||||||
+ {a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}
|
+ {
|
||||||
|
a
|
||||||
|
for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
|
}
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
a
|
a
|
||||||
+ [
|
+ [
|
||||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
]
|
]
|
||||||
in c
|
in c
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -524,13 +527,13 @@ not (
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaa
|
||||||
+
|
+
|
||||||
# has the child process finished?
|
# has the child process finished?
|
||||||
bbbbbbbbbbbbbbb
|
bbbbbbbbbbbbbbb
|
||||||
+
|
+
|
||||||
# the child process has finished, but the
|
# the child process has finished, but the
|
||||||
# transport hasn't been notified yet?
|
# transport hasn't been notified yet?
|
||||||
ccccccccccc
|
ccccccccccc
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -553,7 +556,7 @@ if (
|
|||||||
dddddddddddddddddddd,
|
dddddddddddddddddddd,
|
||||||
eeeeeeeeee,
|
eeeeeeeeee,
|
||||||
]
|
]
|
||||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -569,13 +572,13 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
& [
|
& [
|
||||||
aaaaaaaaaaaaa,
|
aaaaaaaaaaaaa,
|
||||||
bbbbbbbbbbbbbbbbbbbb,
|
bbbbbbbbbbbbbbbbbbbb,
|
||||||
cccccccccccccccccccc,
|
cccccccccccccccccccc,
|
||||||
dddddddddddddddddddd,
|
dddddddddddddddddddd,
|
||||||
eeeeeeeeee,
|
eeeeeeeeee,
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -674,9 +677,9 @@ if (
|
|||||||
iiiiiiiiiiiiiiii,
|
iiiiiiiiiiiiiiii,
|
||||||
jjjjjjjjjjjjj,
|
jjjjjjjjjjjjj,
|
||||||
]
|
]
|
||||||
&
|
&
|
||||||
# comment
|
# comment
|
||||||
a + b
|
a + b
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -693,14 +696,14 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
|||||||
# Keeps parenthesized left hand sides
|
# Keeps parenthesized left hand sides
|
||||||
(
|
(
|
||||||
log(self.price / self.strike)
|
log(self.price / self.strike)
|
||||||
+ (self.risk_free - self.div_cont + 0.5 * (self.sigma**2)) * self.exp_time
|
+ (self.risk_free - self.div_cont + 0.5 * (self.sigma**2)) * self.exp_time
|
||||||
) / self.sigmaT
|
) / self.sigmaT
|
||||||
|
|
||||||
# Stability with end-of-line comments between empty tuples and bin op
|
# Stability with end-of-line comments between empty tuples and bin op
|
||||||
x = (
|
x = (
|
||||||
()
|
()
|
||||||
- ( #
|
- ( #
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
x = (
|
x = (
|
||||||
() - () #
|
() - () #
|
||||||
@@ -729,10 +732,10 @@ expected_content = (
|
|||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
"""
|
"""
|
||||||
# Needs parentheses
|
# Needs parentheses
|
||||||
% (
|
% (
|
||||||
self.base_url,
|
self.base_url,
|
||||||
date.today(),
|
date.today(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_content = (
|
expected_content = (
|
||||||
@@ -742,12 +745,12 @@ expected_content = (
|
|||||||
</sitemap>
|
</sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
"""
|
"""
|
||||||
%
|
%
|
||||||
# Needs parentheses
|
# Needs parentheses
|
||||||
(
|
(
|
||||||
self.base_url,
|
self.base_url,
|
||||||
date.today(),
|
date.today(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -768,8 +771,8 @@ expected_content = (
|
|||||||
</sitemap>
|
</sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
"""
|
"""
|
||||||
+ sssssssssssssssssssssssssssssssssssssssssooooo
|
+ sssssssssssssssssssssssssssssssssssssssssooooo
|
||||||
* looooooooooooooooooooooooooooooongggggggggggg
|
* looooooooooooooooooooooooooooooongggggggggggg
|
||||||
)
|
)
|
||||||
|
|
||||||
call(
|
call(
|
||||||
@@ -796,10 +799,10 @@ expected_content = (
|
|||||||
</sitemap>
|
</sitemap>
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
"""
|
"""
|
||||||
% (
|
% (
|
||||||
# Needs parentheses
|
# Needs parentheses
|
||||||
self.base_url
|
self.base_url
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Skip FString content when determining whether to omit optional parentheses or not.0
|
# Skip FString content when determining whether to omit optional parentheses or not.0
|
||||||
@@ -807,7 +810,7 @@ expected_content = (
|
|||||||
# (Call expressions at the beginning don't count as parenthesized because they don't start with parens).
|
# (Call expressions at the beginning don't count as parenthesized because they don't start with parens).
|
||||||
assert (
|
assert (
|
||||||
format.format_event(spec)
|
format.format_event(spec)
|
||||||
== f'Event("_remove_cookie", {{key:`testkey`,options:{json.dumps(options)}}})'
|
== f'Event("_remove_cookie", {{key:`testkey`,options:{json.dumps(options)}}})'
|
||||||
)
|
)
|
||||||
# Avoid parentheses for this example because it starts with a tuple expression.
|
# Avoid parentheses for this example because it starts with a tuple expression.
|
||||||
assert (
|
assert (
|
||||||
@@ -817,62 +820,62 @@ assert (
|
|||||||
|
|
||||||
rowuses = [
|
rowuses = [
|
||||||
(1 << j) # column ordinal
|
(1 << j) # column ordinal
|
||||||
| (1 << (n + i - j + n - 1)) # NW-SE ordinal
|
| (1 << (n + i - j + n - 1)) # NW-SE ordinal
|
||||||
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
|
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
|
||||||
for j in rangen
|
for j in rangen
|
||||||
]
|
]
|
||||||
|
|
||||||
rowuses = [
|
rowuses = [
|
||||||
(1 << j) # column ordinal
|
(1 << j) # column ordinal
|
||||||
|
|
|
|
||||||
# comment
|
# comment
|
||||||
(1 << (n + i - j + n - 1)) # NW-SE ordinal
|
(1 << (n + i - j + n - 1)) # NW-SE ordinal
|
||||||
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
|
| (1 << (n + 2 * n - 1 + i + j)) # NE-SW ordinal
|
||||||
for j in rangen
|
for j in rangen
|
||||||
]
|
]
|
||||||
|
|
||||||
skip_bytes = (
|
skip_bytes = (
|
||||||
header.timecnt * 5 # Transition times and types
|
header.timecnt * 5 # Transition times and types
|
||||||
+ header.typecnt * 6 # Local time type records
|
+ header.typecnt * 6 # Local time type records
|
||||||
+ header.charcnt # Time zone designations
|
+ header.charcnt # Time zone designations
|
||||||
+ header.leapcnt * 8 # Leap second records
|
+ header.leapcnt * 8 # Leap second records
|
||||||
+ header.isstdcnt # Standard/wall indicators
|
+ header.isstdcnt # Standard/wall indicators
|
||||||
+ header.isutcnt # UT/local indicators
|
+ header.isutcnt # UT/local indicators
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(1 + 2) # test
|
(1 + 2) # test
|
||||||
or (3 + 4) # other
|
or (3 + 4) # other
|
||||||
or (4 + 5) # more
|
or (4 + 5) # more
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(1 and 2) # test
|
(1 and 2) # test
|
||||||
+ (3 and 4) # other
|
+ (3 and 4) # other
|
||||||
+ (4 and 5) # more
|
+ (4 and 5) # more
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(1 + 2) # test
|
(1 + 2) # test
|
||||||
< (3 + 4) # other
|
< (3 + 4) # other
|
||||||
> (4 + 5) # more
|
> (4 + 5) # more
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
z = (
|
z = (
|
||||||
a
|
a
|
||||||
+
|
+
|
||||||
# a: extracts this comment
|
# a: extracts this comment
|
||||||
# b: and this comment
|
# b: and this comment
|
||||||
(
|
(
|
||||||
# c: formats it as part of the expression
|
# c: formats it as part of the expression
|
||||||
x and y
|
x and y
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
z = (
|
z = (
|
||||||
@@ -882,7 +885,7 @@ z = (
|
|||||||
)
|
)
|
||||||
# b: extracts this comment
|
# b: extracts this comment
|
||||||
# c: and this comment
|
# c: and this comment
|
||||||
+ a
|
+ a
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test for https://github.com/astral-sh/ruff/issues/7431
|
# Test for https://github.com/astral-sh/ruff/issues/7431
|
||||||
|
|||||||
@@ -252,8 +252,8 @@ def test():
|
|||||||
),
|
),
|
||||||
"post_processed": (
|
"post_processed": (
|
||||||
collected["post_processed"]
|
collected["post_processed"]
|
||||||
and ", %s post-processed" % post_processed_count
|
and ", %s post-processed" % post_processed_count
|
||||||
or ""
|
or ""
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,11 +398,11 @@ c = (
|
|||||||
"dddddddddddddddddddddddddd" % aaaaaaaaaaaa + x
|
"dddddddddddddddddddddddddd" % aaaaaaaaaaaa + x
|
||||||
)
|
)
|
||||||
|
|
||||||
"abc" + "de" + "fg" + "hij"
|
"a" "b" "c" + "d" "e" + "f" "g" + "h" "i" "j"
|
||||||
|
|
||||||
|
|
||||||
class EC2REPATH:
|
class EC2REPATH:
|
||||||
f.write("Pathway name" + "\tDatabase Identifier" + "\tSource database" + "\n")
|
f.write("Pathway name" + "\t" "Database Identifier" + "\t" "Source database" + "\n")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,37 +198,37 @@ if (self._proc
|
|||||||
if (
|
if (
|
||||||
self._proc
|
self._proc
|
||||||
# has the child process finished?
|
# has the child process finished?
|
||||||
and self._returncode
|
and self._returncode
|
||||||
# the child process has finished, but the
|
# the child process has finished, but the
|
||||||
# transport hasn't been notified yet?
|
# transport hasn't been notified yet?
|
||||||
and self._proc.poll()
|
and self._proc.poll()
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self._proc
|
self._proc
|
||||||
and self._returncode
|
and self._returncode
|
||||||
and self._proc.poll()
|
and self._proc.poll()
|
||||||
and self._proc
|
and self._proc
|
||||||
and self._returncode
|
and self._returncode
|
||||||
and self._proc.poll()
|
and self._proc.poll()
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
and aaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaa
|
||||||
and aaaaaaaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaaaaaaa
|
||||||
and aaaaaaaaaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
and aaaaaaaaaaaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
|
||||||
and aaaaaaaaaaaaaaaaa
|
and aaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -254,61 +254,61 @@ if [
|
|||||||
# Break right only applies for boolean operations with a left and right side
|
# Break right only applies for boolean operations with a left and right side
|
||||||
if (
|
if (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
and bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
and ccccccccccccccccc
|
and ccccccccccccccccc
|
||||||
and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
|
and [dddddddddddddd, eeeeeeeeee, fffffffffffffff]
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Regression test for https://github.com/astral-sh/ruff/issues/6068
|
# Regression test for https://github.com/astral-sh/ruff/issues/6068
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
or numpy
|
or numpy
|
||||||
and isinstance(ccccccccccc, dddddd)
|
and isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
and numpy
|
and numpy
|
||||||
or isinstance(ccccccccccc, dddddd)
|
or isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
and isinstance(ccccccccccc, dddddd)
|
and isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
or isinstance(ccccccccccc, dddddd)
|
or isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
or (
|
or (
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
)
|
)
|
||||||
and isinstance(ccccccccccc, dddddd)
|
and isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
isinstance(aaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)
|
||||||
and (
|
and (
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
+ yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
)
|
)
|
||||||
or isinstance(ccccccccccc, dddddd)
|
or isinstance(ccccccccccc, dddddd)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -322,8 +322,8 @@ def test():
|
|||||||
if "_continue" in request.POST or (
|
if "_continue" in request.POST or (
|
||||||
# Redirecting after "Save as new".
|
# Redirecting after "Save as new".
|
||||||
"_saveasnew" in request.POST
|
"_saveasnew" in request.POST
|
||||||
and self.save_as_continue
|
and self.save_as_continue
|
||||||
and self.has_change_permission(request, obj)
|
and self.has_change_permission(request, obj)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ if True:
|
|||||||
if True:
|
if True:
|
||||||
if (
|
if (
|
||||||
self.validate_max
|
self.validate_max
|
||||||
and self.total_form_count() - len(self.deleted_forms) > self.max_num
|
and self.total_form_count() - len(self.deleted_forms) > self.max_num
|
||||||
) or self.management_form.cleaned_data[
|
) or self.management_form.cleaned_data[
|
||||||
TOTAL_FORM_COUNT
|
TOTAL_FORM_COUNT
|
||||||
] > self.absolute_max:
|
] > self.absolute_max:
|
||||||
@@ -343,15 +343,18 @@ if True:
|
|||||||
if True:
|
if True:
|
||||||
if (
|
if (
|
||||||
reference_field_name is None
|
reference_field_name is None
|
||||||
or
|
or
|
||||||
# Unspecified to_field(s).
|
# Unspecified to_field(s).
|
||||||
to_fields is None
|
to_fields is None
|
||||||
or
|
or
|
||||||
# Reference to primary key.
|
# Reference to primary key.
|
||||||
(None in to_fields and (reference_field is None or reference_field.primary_key))
|
(
|
||||||
or
|
None in to_fields
|
||||||
# Reference to field.
|
and (reference_field is None or reference_field.primary_key)
|
||||||
reference_field_name in to_fields
|
)
|
||||||
|
or
|
||||||
|
# Reference to field.
|
||||||
|
reference_field_name in to_fields
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -359,9 +362,9 @@ if True:
|
|||||||
field = opts.get_field(name)
|
field = opts.get_field(name)
|
||||||
if (
|
if (
|
||||||
field.is_relation
|
field.is_relation
|
||||||
and
|
and
|
||||||
# Generic foreign keys OR reverse relations
|
# Generic foreign keys OR reverse relations
|
||||||
((field.many_to_one and not field.related_model) or field.one_to_many)
|
((field.many_to_one and not field.related_model) or field.one_to_many)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -369,35 +372,35 @@ if (
|
|||||||
if True:
|
if True:
|
||||||
return (
|
return (
|
||||||
filtered.exists()
|
filtered.exists()
|
||||||
and
|
and
|
||||||
# It may happen that the object is deleted from the DB right after
|
# It may happen that the object is deleted from the DB right after
|
||||||
# this check, causing the subsequent UPDATE to return zero matching
|
# this check, causing the subsequent UPDATE to return zero matching
|
||||||
# rows. The same result can occur in some rare cases when the
|
# rows. The same result can occur in some rare cases when the
|
||||||
# database returns zero despite the UPDATE being executed
|
# database returns zero despite the UPDATE being executed
|
||||||
# successfully (a row is matched and updated). In order to
|
# successfully (a row is matched and updated). In order to
|
||||||
# distinguish these two cases, the object's existence in the
|
# distinguish these two cases, the object's existence in the
|
||||||
# database is again checked for if the UPDATE query returns 0.
|
# database is again checked for if the UPDATE query returns 0.
|
||||||
(filtered._update(values) > 0 or filtered.exists())
|
(filtered._update(values) > 0 or filtered.exists())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self._proc is not None
|
self._proc is not None
|
||||||
# has the child process finished?
|
# has the child process finished?
|
||||||
and self._returncode is None
|
and self._returncode is None
|
||||||
# the child process has finished, but the
|
# the child process has finished, but the
|
||||||
# transport hasn't been notified yet?
|
# transport hasn't been notified yet?
|
||||||
and self._proc.poll() is None
|
and self._proc.poll() is None
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self._proc
|
self._proc
|
||||||
# has the child process finished?
|
# has the child process finished?
|
||||||
* self._returncode
|
* self._returncode
|
||||||
# the child process has finished, but the
|
# the child process has finished, but the
|
||||||
# transport hasn't been notified yet?
|
# transport hasn't been notified yet?
|
||||||
+ self._proc.poll()
|
+ self._proc.poll()
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ f(
|
|||||||
100000 - 100000000000
|
100000 - 100000000000
|
||||||
),
|
),
|
||||||
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad"
|
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad"
|
||||||
+ "asdfasdfa",
|
+ "asdfasdfa",
|
||||||
these_arguments_have_values_that_need_to_break_because_they_are_too_long3=session,
|
these_arguments_have_values_that_need_to_break_because_they_are_too_long3=session,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -543,14 +543,14 @@ f( # a
|
|||||||
# f
|
# f
|
||||||
*args2
|
*args2
|
||||||
# g
|
# g
|
||||||
** # h
|
** # h
|
||||||
kwargs,
|
kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
||||||
result = (
|
result = (
|
||||||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||||
+ 1
|
+ 1
|
||||||
)()
|
)()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -201,14 +201,14 @@ a not in b
|
|||||||
|
|
||||||
(
|
(
|
||||||
a
|
a
|
||||||
==
|
==
|
||||||
# comment
|
# comment
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
|
|
||||||
(
|
(
|
||||||
a # comment
|
a # comment
|
||||||
== b
|
== b
|
||||||
)
|
)
|
||||||
|
|
||||||
a < b > c == d
|
a < b > c == d
|
||||||
@@ -270,25 +270,25 @@ return 1 == 2 and (
|
|||||||
self_meta_data,
|
self_meta_data,
|
||||||
self_schedule,
|
self_schedule,
|
||||||
)
|
)
|
||||||
== (
|
== (
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
other_default,
|
other_default,
|
||||||
othr_selected,
|
othr_selected,
|
||||||
othr_auto_generated,
|
othr_auto_generated,
|
||||||
othr_parameters,
|
othr_parameters,
|
||||||
othr_meta_data,
|
othr_meta_data,
|
||||||
othr_schedule,
|
othr_schedule,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
a
|
a
|
||||||
+ [
|
+ [
|
||||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
]
|
]
|
||||||
>= c
|
>= c
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ return 1 == 2 and (
|
|||||||
def f():
|
def f():
|
||||||
return (
|
return (
|
||||||
unicodedata.normalize("NFKC", s1).casefold()
|
unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== unicodedata.normalize("NFKC", s2).casefold()
|
== unicodedata.normalize("NFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -336,7 +336,7 @@ ct_match = (aaaaaaaaaaaaaaaa) == self.get_content_type(
|
|||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
aaaaaaaaaaact_id
|
aaaaaaaaaaact_id
|
||||||
== self.get_content_type[obj, rel_obj, using, instance._state.db].id
|
== self.get_content_type[obj, rel_obj, using, instance._state.db].id
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = {aaaaaaaaaaaaaaaa} == self.get_content_type[
|
ct_match = {aaaaaaaaaaaaaaaa} == self.get_content_type[
|
||||||
@@ -351,10 +351,10 @@ ct_match = (aaaaaaaaaaaaaaaa) == self.get_content_type[
|
|||||||
|
|
||||||
c = (
|
c = (
|
||||||
1 # 1
|
1 # 1
|
||||||
>
|
>
|
||||||
# 2
|
# 2
|
||||||
3 # 3 # 4
|
3 # 3 # 4
|
||||||
> 5 # 5
|
> 5 # 5
|
||||||
# 6
|
# 6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -224,18 +224,18 @@ query = {
|
|||||||
|
|
||||||
{
|
{
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ [
|
+ [
|
||||||
dddddddddddddddddd,
|
dddddddddddddddddd,
|
||||||
eeeeeeeeeeeeeeeeeee,
|
eeeeeeeeeeeeeeeeeee,
|
||||||
]: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
]: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
||||||
eeeeeeeeeeeeeeeeeeeeee,
|
eeeeeeeeeeeeeeeeeeeeee,
|
||||||
fffffffffffffffffffffffff,
|
fffffffffffffffffffffffff,
|
||||||
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
||||||
if fffffffffffffffffffffffffffffffffffffffffff
|
if fffffffffffffffffffffffffffffffffffffffffff
|
||||||
< gggggggggggggggggggggggggggggggggggggggggggggg
|
< gggggggggggggggggggggggggggggggggggggggggggggg
|
||||||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
if gggggggggggggggggggggggggggggggggggggggggggg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -219,9 +219,9 @@ def something():
|
|||||||
NamedValuesListIterable
|
NamedValuesListIterable
|
||||||
if named
|
if named
|
||||||
else FlatValuesListIterable
|
else FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
if flat
|
if flat
|
||||||
else ValuesListIterable
|
else ValuesListIterable
|
||||||
)
|
)
|
||||||
@@ -233,9 +233,9 @@ def something():
|
|||||||
if named
|
if named
|
||||||
else (
|
else (
|
||||||
FlatValuesListIterable
|
FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
+ FlatValuesListIterable
|
+ FlatValuesListIterable
|
||||||
if flat
|
if flat
|
||||||
else ValuesListIterable
|
else ValuesListIterable
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -152,15 +152,15 @@ aaaaaaaaaaaaaaaaaaaaa = [
|
|||||||
|
|
||||||
[
|
[
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ [dddddddddddddddddd, eeeeeeeeeeeeeeeeeee]
|
+ [dddddddddddddddddd, eeeeeeeeeeeeeeeeeee]
|
||||||
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
||||||
eeeeeeeeeeeeeeeeeeeeee,
|
eeeeeeeeeeeeeeeeeeeeee,
|
||||||
fffffffffffffffffffffffff,
|
fffffffffffffffffffffffff,
|
||||||
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
||||||
if fffffffffffffffffffffffffffffffffffffffffff
|
if fffffffffffffffffffffffffffffffffffffffffff
|
||||||
< gggggggggggggggggggggggggggggggggggggggggggggg
|
< gggggggggggggggggggggggggggggggggggggggggggggg
|
||||||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
if gggggggggggggggggggggggggggggggggggggggggggg
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ aaaaaaaaaaaaaaaaaaaaa = [
|
|||||||
[
|
[
|
||||||
1
|
1
|
||||||
for components in b # pylint: disable=undefined-loop-variable # integer 1 may only have decimal 01-09
|
for components in b # pylint: disable=undefined-loop-variable # integer 1 may only have decimal 01-09
|
||||||
+ c # negative decimal
|
+ c # negative decimal
|
||||||
]
|
]
|
||||||
|
|
||||||
# Parenthesized targets and iterators.
|
# Parenthesized targets and iterators.
|
||||||
|
|||||||
@@ -100,15 +100,15 @@ selected_choices = {
|
|||||||
|
|
||||||
{
|
{
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ [dddddddddddddddddd, eeeeeeeeeeeeeeeeeee]
|
+ [dddddddddddddddddd, eeeeeeeeeeeeeeeeeee]
|
||||||
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
for ccccccccccccccccccccccccccccccccccccccc, ddddddddddddddddddd, [
|
||||||
eeeeeeeeeeeeeeeeeeeeee,
|
eeeeeeeeeeeeeeeeeeeeee,
|
||||||
fffffffffffffffffffffffff,
|
fffffffffffffffffffffffff,
|
||||||
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
] in eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffggggggggggggggggggggghhhhhhhhhhhhhhothermoreeand_even_moreddddddddddddddddddddd
|
||||||
if fffffffffffffffffffffffffffffffffffffffffff
|
if fffffffffffffffffffffffffffffffffffffffffff
|
||||||
< gggggggggggggggggggggggggggggggggggggggggggggg
|
< gggggggggggggggggggggggggggggggggggggggggggggg
|
||||||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
if gggggggggggggggggggggggggggggggggggggggggggg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ g2 = "g"[(1):(2):(3)]
|
|||||||
def f():
|
def f():
|
||||||
return (
|
return (
|
||||||
package_version is not None
|
package_version is not None
|
||||||
and package_version.split(".")[:2] == package_info.version.split(".")[:2]
|
and package_version.split(".")[:2] == package_info.version.split(".")[:2]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,12 +101,12 @@ response = await sync_to_async(
|
|||||||
# Expressions with empty parentheses.
|
# Expressions with empty parentheses.
|
||||||
ct_match = (
|
ct_match = (
|
||||||
unicodedata.normalize("NFKC", s1).casefold()
|
unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
unicodedata.normalize("NFKC", s1).casefold(1)
|
unicodedata.normalize("NFKC", s1).casefold(1)
|
||||||
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = unicodedata.normalize("NFKC", s1).casefold(0) == unicodedata.normalize(
|
ct_match = unicodedata.normalize("NFKC", s1).casefold(0) == unicodedata.normalize(
|
||||||
@@ -121,19 +121,19 @@ ct_match = (
|
|||||||
unicodedata.normalize("NFKC", s1).casefold(
|
unicodedata.normalize("NFKC", s1).casefold(
|
||||||
# foo
|
# foo
|
||||||
)
|
)
|
||||||
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold(
|
== unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold(
|
||||||
# foo
|
# foo
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
[].unicodedata.normalize("NFKC", s1).casefold()
|
[].unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== [].unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== [].unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
[].unicodedata.normalize("NFKC", s1).casefold()
|
[].unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== [1].unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== [1].unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = [1].unicodedata.normalize("NFKC", s1).casefold() == [].unicodedata.normalize(
|
ct_match = [1].unicodedata.normalize("NFKC", s1).casefold() == [].unicodedata.normalize(
|
||||||
@@ -146,12 +146,12 @@ ct_match = [1].unicodedata.normalize("NFKC", s1).casefold() == [
|
|||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
{}.unicodedata.normalize("NFKC", s1).casefold()
|
{}.unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== {}.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== {}.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = (
|
ct_match = (
|
||||||
{}.unicodedata.normalize("NFKC", s1).casefold()
|
{}.unicodedata.normalize("NFKC", s1).casefold()
|
||||||
== {1}.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
== {1}.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()
|
||||||
)
|
)
|
||||||
|
|
||||||
ct_match = {1}.unicodedata.normalize("NFKC", s1).casefold() == {}.unicodedata.normalize(
|
ct_match = {1}.unicodedata.normalize("NFKC", s1).casefold() == {}.unicodedata.normalize(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ result = (
|
|||||||
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
# Regression test for: https://github.com/astral-sh/ruff/issues/7370
|
||||||
result = (
|
result = (
|
||||||
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
f(111111111111111111111111111111111111111111111111111111111111111111111111111111111)
|
||||||
+ 1
|
+ 1
|
||||||
)[0]
|
)[0]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ def foo():
|
|||||||
```python
|
```python
|
||||||
if (
|
if (
|
||||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ b = 10
|
|||||||
if not (
|
if not (
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -229,14 +229,14 @@ if not (
|
|||||||
if ~(
|
if ~(
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if -(
|
if -(
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -244,14 +244,14 @@ if -(
|
|||||||
if +(
|
if +(
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -259,14 +259,14 @@ if (
|
|||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ if (
|
|||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -286,21 +286,21 @@ if (
|
|||||||
not (
|
not (
|
||||||
# comment
|
# comment
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (
|
if not (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (
|
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (
|
||||||
not (
|
not (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
@@ -308,9 +308,9 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (
|
|||||||
if (
|
if (
|
||||||
not (
|
not (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
)
|
)
|
||||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ if (
|
|||||||
|
|
||||||
if ( # comment
|
if ( # comment
|
||||||
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -327,14 +327,14 @@ if ( # comment
|
|||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ if (
|
|||||||
if (
|
if (
|
||||||
# comment
|
# comment
|
||||||
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -355,8 +355,8 @@ if not a:
|
|||||||
# Regression test for: https://github.com/astral-sh/ruff/issues/5338
|
# Regression test for: https://github.com/astral-sh/ruff/issues/5338
|
||||||
if (
|
if (
|
||||||
a
|
a
|
||||||
and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ if True:
|
|||||||
if True:
|
if True:
|
||||||
if not yn_question(
|
if not yn_question(
|
||||||
Fore.RED
|
Fore.RED
|
||||||
+ "WARNING: Removing listed files. Do you really want to continue. yes/n)? "
|
+ "WARNING: Removing listed files. Do you really want to continue. yes/n)? "
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ aaaaaaaa = (
|
|||||||
|
|
||||||
aaaaaaaa = (
|
aaaaaaaa = (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ def foo():
|
|||||||
|
|
||||||
yield (
|
yield (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
+ ccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -259,20 +259,20 @@ result = yield
|
|||||||
|
|
||||||
result = yield (
|
result = yield (
|
||||||
1
|
1
|
||||||
+ f(
|
+ f(
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
result = yield (
|
result = yield (
|
||||||
1
|
1
|
||||||
+ f(
|
+ f(
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
print((yield x))
|
print((yield x))
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ call(
|
|||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
"""dove
|
"""dove
|
||||||
coo"""
|
coo"""
|
||||||
% "cowabunga"
|
% "cowabunga"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -298,13 +298,13 @@ c1 = (
|
|||||||
).filter(
|
).filter(
|
||||||
entry__pub_date__year=2008,
|
entry__pub_date__year=2008,
|
||||||
)
|
)
|
||||||
+ Blog.objects.filter(
|
+ Blog.objects.filter(
|
||||||
entry__headline__contains="McCartney",
|
entry__headline__contains="McCartney",
|
||||||
)
|
)
|
||||||
.limit_results[:10]
|
.limit_results[:10]
|
||||||
.filter(
|
.filter(
|
||||||
entry__pub_date__year=2010,
|
entry__pub_date__year=2010,
|
||||||
)
|
)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
# Test different cases with trailing end of line comments:
|
# Test different cases with trailing end of line comments:
|
||||||
@@ -378,10 +378,10 @@ if (
|
|||||||
pass
|
pass
|
||||||
h2 = (
|
h2 = (
|
||||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ ccccccccccccccccccccccccc()
|
+ ccccccccccccccccccccccccc()
|
||||||
.dddddddddddddddddddddd()
|
.dddddddddddddddddddddd()
|
||||||
.eeeeeeeeee()
|
.eeeeeeeeee()
|
||||||
.ffffffffffffffffffffff()
|
.ffffffffffffffffffffff()
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parentheses aren't allowed on statement level, don't use fluent style here
|
# Parentheses aren't allowed on statement level, don't use fluent style here
|
||||||
|
|||||||
@@ -87,12 +87,12 @@ call(
|
|||||||
|
|
||||||
a = (
|
a = (
|
||||||
a
|
a
|
||||||
+ b
|
+ b
|
||||||
+ c
|
+ c
|
||||||
+ d
|
+ d
|
||||||
+ ( # Hello
|
+ ( # Hello
|
||||||
e + f + g
|
e + f + g
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
a = int( # type: ignore
|
a = int( # type: ignore
|
||||||
@@ -106,23 +106,23 @@ a = int( # type: ignore
|
|||||||
# Stability and correctness checks
|
# Stability and correctness checks
|
||||||
b1 = (
|
b1 = (
|
||||||
()
|
()
|
||||||
- ( #
|
- ( #
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
- ( #
|
- ( #
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
b2 = (
|
b2 = (
|
||||||
()
|
()
|
||||||
- f( #
|
- f( #
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
()
|
()
|
||||||
- f( #
|
- f( #
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
b3 = (
|
b3 = (
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ def f():
|
|||||||
)
|
)
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
cccccccc.ccccccccccccc.cccccccc
|
cccccccc.ccccccccccccc.cccccccc
|
||||||
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
)
|
)
|
||||||
|
|
||||||
self._cache: dict[
|
self._cache: dict[
|
||||||
@@ -211,7 +211,7 @@ def f():
|
|||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
cccccccc.ccccccccccccc(d).cccccccc + e
|
cccccccc.ccccccccccccc(d).cccccccc + e
|
||||||
@@ -57,9 +56,9 @@
|
@@ -57,9 +56,9 @@
|
||||||
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
)
|
)
|
||||||
|
|
||||||
- self._cache: dict[
|
- self._cache: dict[
|
||||||
@@ -300,7 +300,7 @@ def f():
|
|||||||
)
|
)
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (
|
||||||
cccccccc.ccccccccccccc.cccccccc
|
cccccccc.ccccccccccccc.cccccccc
|
||||||
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
+ eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
)
|
)
|
||||||
|
|
||||||
self._cache: dict[DependencyCacheKey, list[list[DependencyPackage]]] = (
|
self._cache: dict[DependencyCacheKey, list[list[DependencyPackage]]] = (
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ def format_range_after_inserted_parens ():
|
|||||||
def needs_parentheses( ) -> bool:
|
def needs_parentheses( ) -> bool:
|
||||||
return (
|
return (
|
||||||
item.sizing_mode is None
|
item.sizing_mode is None
|
||||||
and item.width_policy == "auto"
|
and item.width_policy == "auto"
|
||||||
and item.height_policy == "automatic"
|
and item.height_policy == "automatic"
|
||||||
)
|
)
|
||||||
|
|
||||||
def no_longer_needs_parentheses( ) -> bool:
|
def no_longer_needs_parentheses( ) -> bool:
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ def test():
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expected
|
== expected
|
||||||
), "Not what we expected and the message is too long to fit ineeeeee one line"
|
), "Not what we expected and the message is too long to fit ineeeeee one line"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@@ -238,7 +238,7 @@ def test():
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expected
|
== expected
|
||||||
), "Not what we expected and the message is too long to fit in one lineeeee"
|
), "Not what we expected and the message is too long to fit in one lineeeee"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@@ -253,7 +253,7 @@ def test():
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expected
|
== expected
|
||||||
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeee"
|
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeee"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@@ -268,7 +268,7 @@ def test():
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
== expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
), "Not what we expected and the message is too long to fit in one lin"
|
), "Not what we expected and the message is too long to fit in one lin"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
@@ -283,7 +283,7 @@ def test():
|
|||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
== expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
== expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeeeee"
|
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeeeee"
|
||||||
|
|
||||||
assert expected == {
|
assert expected == {
|
||||||
@@ -300,47 +300,47 @@ def test():
|
|||||||
|
|
||||||
assert (
|
assert (
|
||||||
expected
|
expected
|
||||||
== {
|
== {
|
||||||
key1: value1,
|
key1: value1,
|
||||||
key2: value2,
|
key2: value2,
|
||||||
key3: value3,
|
key3: value3,
|
||||||
key4: value4,
|
key4: value4,
|
||||||
key5: value5,
|
key5: value5,
|
||||||
key6: value6,
|
key6: value6,
|
||||||
key7: value7,
|
key7: value7,
|
||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeeeeeeee"
|
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeeeeeeee"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
== {
|
== {
|
||||||
key1: value1,
|
key1: value1,
|
||||||
key2: value2,
|
key2: value2,
|
||||||
key3: value3,
|
key3: value3,
|
||||||
key4: value4,
|
key4: value4,
|
||||||
key5: value5,
|
key5: value5,
|
||||||
key6: value6,
|
key6: value6,
|
||||||
key7: value7,
|
key7: value7,
|
||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
), "Not what we expected and the message is too long to fit in one lin"
|
), "Not what we expected and the message is too long to fit in one lin"
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
expectedeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
||||||
== {
|
== {
|
||||||
key1: value1,
|
key1: value1,
|
||||||
key2: value2,
|
key2: value2,
|
||||||
key3: value3,
|
key3: value3,
|
||||||
key4: value4,
|
key4: value4,
|
||||||
key5: value5,
|
key5: value5,
|
||||||
key6: value6,
|
key6: value6,
|
||||||
key7: value7,
|
key7: value7,
|
||||||
key8: value8,
|
key8: value8,
|
||||||
key9: value9,
|
key9: value9,
|
||||||
}
|
}
|
||||||
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeee"
|
), "Not what we expected and the message is too long to fit in one lineeeeeeeeeeeeeee"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ def main() -> None:
|
|||||||
some_very_long_variable_name_abcdefghijk = (
|
some_very_long_variable_name_abcdefghijk = (
|
||||||
some_very_long_variable_name_abcdefghijk[
|
some_very_long_variable_name_abcdefghijk[
|
||||||
some_very_long_variable_name_abcdefghijk.some_very_long_attribute_name
|
some_very_long_variable_name_abcdefghijk.some_very_long_attribute_name
|
||||||
== "This is a very long string abcdefghijk"
|
== "This is a very long string abcdefghijk"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ tree_depth += 1
|
|||||||
|
|
||||||
greeting += (
|
greeting += (
|
||||||
"This is very long, formal greeting for whomever is name here. Dear %s, it will break the line"
|
"This is very long, formal greeting for whomever is name here. Dear %s, it will break the line"
|
||||||
% len(name)
|
% len(name)
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -270,10 +270,10 @@ class Test((Aaaa)):
|
|||||||
|
|
||||||
class Test(
|
class Test(
|
||||||
aaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ cccccccccccccccccccccccc
|
+ cccccccccccccccccccccccc
|
||||||
+ dddddddddddddddddddddd
|
+ dddddddddddddddddddddd
|
||||||
+ eeeeeeeee,
|
+ eeeeeeeee,
|
||||||
ffffffffffffffffff,
|
ffffffffffffffffff,
|
||||||
gggggggggggggggggg,
|
gggggggggggggggggg,
|
||||||
):
|
):
|
||||||
@@ -282,9 +282,9 @@ class Test(
|
|||||||
|
|
||||||
class Test(
|
class Test(
|
||||||
aaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccc
|
+ bbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccc
|
||||||
+ dddddddddddddddddddddd
|
+ dddddddddddddddddddddd
|
||||||
+ eeeeeeeee,
|
+ eeeeeeeee,
|
||||||
ffffffffffffffffff,
|
ffffffffffffffffff,
|
||||||
gggggggggggggggggg,
|
gggggggggggggggggg,
|
||||||
):
|
):
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ def kwarg_with_leading_comments(
|
|||||||
def argument_with_long_default(
|
def argument_with_long_default(
|
||||||
a,
|
a,
|
||||||
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||||
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
||||||
h=[],
|
h=[],
|
||||||
):
|
):
|
||||||
...
|
...
|
||||||
@@ -514,8 +514,8 @@ def argument_with_long_default(
|
|||||||
def argument_with_long_type_annotation(
|
def argument_with_long_type_annotation(
|
||||||
a,
|
a,
|
||||||
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
b: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||||
h=[],
|
h=[],
|
||||||
):
|
):
|
||||||
...
|
...
|
||||||
@@ -1064,7 +1064,7 @@ def function_with_one_argument_and_a_keyword_separator(
|
|||||||
def argument_with_long_default(
|
def argument_with_long_default(
|
||||||
@@ -75,8 +71,7 @@
|
@@ -75,8 +71,7 @@
|
||||||
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
b=ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||||
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
+ [dddddddddddddddddddd, eeeeeeeeeeeeeeeeeeee, ffffffffffffffffffffffff],
|
||||||
h=[],
|
h=[],
|
||||||
-):
|
-):
|
||||||
- ...
|
- ...
|
||||||
@@ -1073,8 +1073,8 @@ def function_with_one_argument_and_a_keyword_separator(
|
|||||||
|
|
||||||
def argument_with_long_type_annotation(
|
def argument_with_long_type_annotation(
|
||||||
@@ -85,12 +80,10 @@
|
@@ -85,12 +80,10 @@
|
||||||
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
| yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
|
||||||
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
| zzzzzzzzzzzzzzzzzzz = [0, 1, 2, 3],
|
||||||
h=[],
|
h=[],
|
||||||
-):
|
-):
|
||||||
- ...
|
- ...
|
||||||
|
|||||||
@@ -181,17 +181,17 @@ x6: VeryLongClassNameWithAwkwardGenericSubtype[
|
|||||||
x7: CustomTrainingJob | CustomContainerTrainingJob | CustomPythonPackageTrainingJob
|
x7: CustomTrainingJob | CustomContainerTrainingJob | CustomPythonPackageTrainingJob
|
||||||
x8: (
|
x8: (
|
||||||
None
|
None
|
||||||
| datasets.ImageDataset
|
| datasets.ImageDataset
|
||||||
| datasets.TabularDataset
|
| datasets.TabularDataset
|
||||||
| datasets.TextDataset
|
| datasets.TextDataset
|
||||||
| datasets.VideoDataset
|
| datasets.VideoDataset
|
||||||
) = None
|
) = None
|
||||||
|
|
||||||
x9: None | (
|
x9: None | (
|
||||||
datasets.ImageDataset
|
datasets.ImageDataset
|
||||||
| datasets.TabularDataset
|
| datasets.TabularDataset
|
||||||
| datasets.TextDataset
|
| datasets.TextDataset
|
||||||
| datasets.VideoDataset
|
| datasets.VideoDataset
|
||||||
) = None
|
) = None
|
||||||
|
|
||||||
|
|
||||||
@@ -199,11 +199,11 @@ x10: (
|
|||||||
aaaaaaaaaaaaaaaaaaaaaaaa[
|
aaaaaaaaaaaaaaaaaaaaaaaa[
|
||||||
bbbbbbbbbbb,
|
bbbbbbbbbbb,
|
||||||
Subscript
|
Subscript
|
||||||
| None
|
| None
|
||||||
| datasets.ImageDataset
|
| datasets.ImageDataset
|
||||||
| datasets.TabularDataset
|
| datasets.TabularDataset
|
||||||
| datasets.TextDataset
|
| datasets.TextDataset
|
||||||
| datasets.VideoDataset,
|
| datasets.VideoDataset,
|
||||||
],
|
],
|
||||||
bbb[other],
|
bbb[other],
|
||||||
) = None
|
) = None
|
||||||
@@ -334,13 +334,13 @@ nested_comment: None | [
|
|||||||
-] | Other | More | AndMore | None = None
|
-] | Other | More | AndMore | None = None
|
||||||
+x1: (
|
+x1: (
|
||||||
+ A[b]
|
+ A[b]
|
||||||
+ | EventHandler
|
+ | EventHandler
|
||||||
+ | EventSpec
|
+ | EventSpec
|
||||||
+ | list[EventHandler | EventSpec]
|
+ | list[EventHandler | EventSpec]
|
||||||
+ | Other
|
+ | Other
|
||||||
+ | More
|
+ | More
|
||||||
+ | AndMore
|
+ | AndMore
|
||||||
+ | None
|
+ | None
|
||||||
+) = None
|
+) = None
|
||||||
|
|
||||||
-x2: "VeryLongClassNameWithAwkwardGenericSubtype[int] |" "VeryLongClassNameWithAwkwardGenericSubtype[str]"
|
-x2: "VeryLongClassNameWithAwkwardGenericSubtype[int] |" "VeryLongClassNameWithAwkwardGenericSubtype[str]"
|
||||||
@@ -363,13 +363,13 @@ nested_comment: None | [
|
|||||||
-] | Other = None
|
-] | Other = None
|
||||||
+x12: (
|
+x12: (
|
||||||
+ None
|
+ None
|
||||||
+ | [
|
+ | [
|
||||||
+ datasets.ImageDataset,
|
+ datasets.ImageDataset,
|
||||||
+ datasets.TabularDataset,
|
+ datasets.TabularDataset,
|
||||||
+ datasets.TextDataset,
|
+ datasets.TextDataset,
|
||||||
+ datasets.VideoDataset,
|
+ datasets.VideoDataset,
|
||||||
+ ]
|
+ ]
|
||||||
+ | Other
|
+ | Other
|
||||||
+) = None
|
+) = None
|
||||||
|
|
||||||
|
|
||||||
@@ -396,13 +396,13 @@ nested_comment: None | [
|
|||||||
+ datasets.TextDataset,
|
+ datasets.TextDataset,
|
||||||
+ datasets.VideoDataset,
|
+ datasets.VideoDataset,
|
||||||
+ ]
|
+ ]
|
||||||
+ | [
|
+ | [
|
||||||
+ datasets.ImageDataset,
|
+ datasets.ImageDataset,
|
||||||
+ datasets.TabularDataset,
|
+ datasets.TabularDataset,
|
||||||
+ datasets.TextDataset,
|
+ datasets.TextDataset,
|
||||||
+ datasets.VideoDataset,
|
+ datasets.VideoDataset,
|
||||||
+ ]
|
+ ]
|
||||||
+ | Other
|
+ | Other
|
||||||
+) = None
|
+) = None
|
||||||
|
|
||||||
-x16: None | Literal[
|
-x16: None | Literal[
|
||||||
@@ -416,15 +416,15 @@ nested_comment: None | [
|
|||||||
-] = None
|
-] = None
|
||||||
+x16: (
|
+x16: (
|
||||||
+ None
|
+ None
|
||||||
+ | Literal[
|
+ | Literal[
|
||||||
+ "split",
|
+ "split",
|
||||||
+ "a bit longer",
|
+ "a bit longer",
|
||||||
+ "records",
|
+ "records",
|
||||||
+ "index",
|
+ "index",
|
||||||
+ "table",
|
+ "table",
|
||||||
+ "columns",
|
+ "columns",
|
||||||
+ "values",
|
+ "values",
|
||||||
+ ]
|
+ ]
|
||||||
+) = None
|
+) = None
|
||||||
|
|
||||||
x17: None | [
|
x17: None | [
|
||||||
|
|||||||
@@ -137,29 +137,29 @@ raise OsError(
|
|||||||
|
|
||||||
raise (
|
raise (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ cccccccccccccccccccccc
|
+ cccccccccccccccccccccc
|
||||||
+ ddddddddddddddddddddddddd
|
+ ddddddddddddddddddddddddd
|
||||||
)
|
)
|
||||||
raise (
|
raise (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ (cccccccccccccccccccccc + ddddddddddddddddddddddddd)
|
+ (cccccccccccccccccccccc + ddddddddddddddddddddddddd)
|
||||||
)
|
)
|
||||||
raise (
|
raise (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ cccccccccccccccccccccc
|
+ cccccccccccccccccccccc
|
||||||
+ ddddddddddddddddddddddddd
|
+ ddddddddddddddddddddddddd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
raise ( # hey
|
raise ( # hey
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
# Holala
|
# Holala
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbb # stay
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbb # stay
|
||||||
+ cccccccccccccccccccccc
|
+ cccccccccccccccccccccc
|
||||||
+ ddddddddddddddddddddddddd # where I'm going
|
+ ddddddddddddddddddddddddd # where I'm going
|
||||||
# I don't know
|
# I don't know
|
||||||
) # whaaaaat
|
) # whaaaaat
|
||||||
# the end
|
# the end
|
||||||
@@ -180,13 +180,13 @@ raise aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflak
|
|||||||
|
|
||||||
raise (
|
raise (
|
||||||
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
||||||
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
||||||
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
|
||||||
)
|
)
|
||||||
|
|
||||||
raise aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfk < (
|
raise aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfk < (
|
||||||
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajl
|
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajl
|
||||||
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashd
|
< aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashd
|
||||||
) # the other end
|
) # the other end
|
||||||
# sneaky comment
|
# sneaky comment
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ return (
|
|||||||
def f():
|
def f():
|
||||||
return (
|
return (
|
||||||
self.get_filename()
|
self.get_filename()
|
||||||
+ ".csv"
|
+ ".csv"
|
||||||
+ "text/csv"
|
+ "text/csv"
|
||||||
+ output.getvalue().encode("utf-8----------------"),
|
+ output.getvalue().encode("utf-8----------------"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -100,9 +100,9 @@ def f():
|
|||||||
def f():
|
def f():
|
||||||
return (
|
return (
|
||||||
self.get_filename()
|
self.get_filename()
|
||||||
+ ".csv"
|
+ ".csv"
|
||||||
+ "text/csv"
|
+ "text/csv"
|
||||||
+ output.getvalue().encode("utf-8----------------"),
|
+ output.getvalue().encode("utf-8----------------"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -486,9 +486,9 @@ def xxxxxxxxxxxxxxxxxxxxxxxxxxxx(
|
|||||||
|
|
||||||
def double() -> (
|
def double() -> (
|
||||||
first_item
|
first_item
|
||||||
and foo.bar.baz().bop(
|
and foo.bar.baz().bop(
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
return 2 * a
|
return 2 * a
|
||||||
|
|
||||||
@@ -530,9 +530,24 @@ def double(
|
|||||||
a: int,
|
a: int,
|
||||||
) -> (
|
) -> (
|
||||||
int
|
int
|
||||||
| list[
|
| list[
|
||||||
int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int
|
int,
|
||||||
] # Hello
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
] # Hello
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ type Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|||||||
type X = Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
|
type X = Ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
|
||||||
type X = (
|
type X = (
|
||||||
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
| Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
| Bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
| Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
| Ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
|
||||||
)
|
)
|
||||||
type XXXXXXXXXXXXX = (
|
type XXXXXXXXXXXXX = (
|
||||||
Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt # with comment
|
Tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt # with comment
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ while (
|
|||||||
|
|
||||||
while (
|
while (
|
||||||
some_condition(unformatted, args) # trailing some condition
|
some_condition(unformatted, args) # trailing some condition
|
||||||
and anotherCondition
|
and anotherCondition
|
||||||
or aThirdCondition # trailing third condition
|
or aThirdCondition # trailing third condition
|
||||||
): # comment
|
): # comment
|
||||||
print("Do something")
|
print("Do something")
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -487,9 +487,9 @@ with (
|
|||||||
dddddddddddddddddddddddddddddddd,
|
dddddddddddddddddddddddddddddddd,
|
||||||
] as example1,
|
] as example1,
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ cccccccccccccccccccccccccccc
|
+ cccccccccccccccccccccccccccc
|
||||||
+ ddddddddddddddddd as example2,
|
+ ddddddddddddddddd as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
@@ -623,14 +623,14 @@ with (
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
||||||
c as d,
|
c as d,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with (
|
with (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
||||||
c as d,
|
c as d,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
@@ -649,8 +649,8 @@ if True:
|
|||||||
if True:
|
if True:
|
||||||
with (
|
with (
|
||||||
anyio.CancelScope(shield=True)
|
anyio.CancelScope(shield=True)
|
||||||
and B
|
and B
|
||||||
and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
|
and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -677,7 +677,7 @@ with Child(aaaaaaaaa, bbbbbbbbbbbbbbb, cccccc), Document(
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
- + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
- + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
||||||
+ (
|
+ (
|
||||||
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ ) as b,
|
+ ) as b,
|
||||||
@@ -867,9 +867,9 @@ with (
|
|||||||
dddddddddddddddddddddddddddddddd,
|
dddddddddddddddddddddddddddddddd,
|
||||||
] as example1,
|
] as example1,
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
+ cccccccccccccccccccccccccccc
|
+ cccccccccccccccccccccccccccc
|
||||||
+ ddddddddddddddddd as example2,
|
+ ddddddddddddddddd as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
CtxManager2() as example2,
|
CtxManager2() as example2,
|
||||||
@@ -884,9 +884,9 @@ with (
|
|||||||
dddddddddddddddddddddddddddddddd,
|
dddddddddddddddddddddddddddddddd,
|
||||||
] as example1,
|
] as example1,
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
* cccccccccccccccccccccccccccc
|
* cccccccccccccccccccccccccccc
|
||||||
+ ddddddddddddddddd as example2,
|
+ ddddddddddddddddd as example2,
|
||||||
CtxManager222222222222222() as example2,
|
CtxManager222222222222222() as example2,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
@@ -1016,7 +1016,7 @@ with (
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -1030,7 +1030,7 @@ with (
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as b,
|
||||||
c as d,
|
c as d,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
@@ -1057,8 +1057,8 @@ if True:
|
|||||||
if True:
|
if True:
|
||||||
with (
|
with (
|
||||||
anyio.CancelScope(shield=True)
|
anyio.CancelScope(shield=True)
|
||||||
and B
|
and B
|
||||||
and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
|
and [aaaaaaaa, bbbbbbbbbbbbb, cccccccccc, dddddddddddd, eeeeeeeeeeeee]
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ source_type = Python
|
|||||||
# Fits with tab width 2
|
# Fits with tab width 2
|
||||||
(
|
(
|
||||||
1
|
1
|
||||||
+ " 012345678901234567890123456789012345678901234567890123456789012345678901234567"
|
+ " 012345678901234567890123456789012345678901234567890123456789012345678901234567"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fits with tab width 4
|
# Fits with tab width 4
|
||||||
@@ -91,13 +91,13 @@ source_type = Python
|
|||||||
# Fits with tab width 2
|
# Fits with tab width 2
|
||||||
(
|
(
|
||||||
1
|
1
|
||||||
+ " 012345678901234567890123456789012345678901234567890123456789012345678901234567"
|
+ " 012345678901234567890123456789012345678901234567890123456789012345678901234567"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fits with tab width 4
|
# Fits with tab width 4
|
||||||
(
|
(
|
||||||
1
|
1
|
||||||
+ " 0123456789012345678901234567890123456789012345678901234567890123456789012345"
|
+ " 0123456789012345678901234567890123456789012345678901234567890123456789012345"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fits with tab width 8
|
# Fits with tab width 8
|
||||||
|
|||||||
Reference in New Issue
Block a user