mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Format ExpressionStarred
nodes (#5654)
This commit is contained in:
parent
9f486fa841
commit
987111f5fb
16 changed files with 192 additions and 581 deletions
15
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/starred.py
vendored
Normal file
15
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/starred.py
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
* # Trailing star comment
|
||||||
|
[
|
||||||
|
# Leading value commnt
|
||||||
|
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||||
|
] # trailing value comment
|
||||||
|
)
|
||||||
|
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
* ( # Leading value commnt
|
||||||
|
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||||
|
) # trailing value comment
|
||||||
|
)
|
|
@ -87,11 +87,12 @@
|
||||||
//!
|
//!
|
||||||
//! It is possible to add an additional optional label to [`SourceComment`] If ever the need arises to distinguish two *dangling comments* in the formatting logic,
|
//! It is possible to add an additional optional label to [`SourceComment`] If ever the need arises to distinguish two *dangling comments* in the formatting logic,
|
||||||
|
|
||||||
|
use ruff_text_size::TextRange;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use rustpython_parser::ast::Mod;
|
use rustpython_parser::ast::{Mod, Ranged};
|
||||||
|
|
||||||
pub(crate) use format::{
|
pub(crate) use format::{
|
||||||
dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
|
dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
|
||||||
|
@ -114,7 +115,7 @@ mod placement;
|
||||||
mod visitor;
|
mod visitor;
|
||||||
|
|
||||||
/// A comment in the source document.
|
/// A comment in the source document.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub(crate) struct SourceComment {
|
pub(crate) struct SourceComment {
|
||||||
/// The location of the comment in the source document.
|
/// The location of the comment in the source document.
|
||||||
slice: SourceCodeSlice,
|
slice: SourceCodeSlice,
|
||||||
|
@ -155,15 +156,20 @@ impl SourceComment {
|
||||||
pub(crate) fn is_unformatted(&self) -> bool {
|
pub(crate) fn is_unformatted(&self) -> bool {
|
||||||
!self.is_formatted()
|
!self.is_formatted()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl SourceComment {
|
|
||||||
/// Returns a nice debug representation that prints the source code for every comment (and not just the range).
|
/// Returns a nice debug representation that prints the source code for every comment (and not just the range).
|
||||||
pub(crate) fn debug<'a>(&'a self, source_code: SourceCode<'a>) -> DebugComment<'a> {
|
pub(crate) fn debug<'a>(&'a self, source_code: SourceCode<'a>) -> DebugComment<'a> {
|
||||||
DebugComment::new(self, source_code)
|
DebugComment::new(self, source_code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ranged for SourceComment {
|
||||||
|
#[inline]
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.slice.range()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The position of a comment in the source text.
|
/// The position of a comment in the source text.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub(crate) enum CommentLinePosition {
|
pub(crate) enum CommentLinePosition {
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub(super) fn place_comment<'a>(
|
||||||
handle_slice_comments,
|
handle_slice_comments,
|
||||||
handle_attribute_comment,
|
handle_attribute_comment,
|
||||||
handle_expr_if_comment,
|
handle_expr_if_comment,
|
||||||
|
handle_trailing_expression_starred_star_end_of_line_comment,
|
||||||
];
|
];
|
||||||
for handler in HANDLERS {
|
for handler in HANDLERS {
|
||||||
comment = match handler(comment, locator) {
|
comment = match handler(comment, locator) {
|
||||||
|
@ -1215,6 +1216,21 @@ fn handle_expr_if_comment<'a>(
|
||||||
CommentPlacement::Default(comment)
|
CommentPlacement::Default(comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_trailing_expression_starred_star_end_of_line_comment<'a>(
|
||||||
|
comment: DecoratedComment<'a>,
|
||||||
|
_locator: &Locator,
|
||||||
|
) -> CommentPlacement<'a> {
|
||||||
|
if comment.line_position().is_own_line() || comment.following_node().is_none() {
|
||||||
|
return CommentPlacement::Default(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
let AnyNodeRef::ExprStarred(starred) = comment.enclosing_node() else {
|
||||||
|
return CommentPlacement::Default(comment);
|
||||||
|
};
|
||||||
|
|
||||||
|
CommentPlacement::leading(starred.as_any_node_ref(), comment)
|
||||||
|
}
|
||||||
|
|
||||||
/// Looks for a token in the range that contains no other tokens except for parentheses outside
|
/// Looks for a token in the range that contains no other tokens except for parentheses outside
|
||||||
/// the expression ranges
|
/// the expression ranges
|
||||||
fn find_only_token_in_range(range: TextRange, locator: &Locator, token_kind: TokenKind) -> Token {
|
fn find_only_token_in_range(range: TextRange, locator: &Locator, token_kind: TokenKind) -> Token {
|
||||||
|
|
|
@ -454,6 +454,13 @@ impl<'a> DecoratedComment<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Ranged for DecoratedComment<'_> {
|
||||||
|
#[inline]
|
||||||
|
fn range(&self) -> TextRange {
|
||||||
|
self.slice.range()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<DecoratedComment<'_>> for SourceComment {
|
impl From<DecoratedComment<'_>> for SourceComment {
|
||||||
fn from(decorated: DecoratedComment) -> Self {
|
fn from(decorated: DecoratedComment) -> Self {
|
||||||
Self::new(decorated.slice, decorated.line_position)
|
Self::new(decorated.slice, decorated.line_position)
|
||||||
|
|
|
@ -1,22 +1,32 @@
|
||||||
|
use rustpython_parser::ast::ExprStarred;
|
||||||
|
|
||||||
|
use ruff_formatter::write;
|
||||||
|
|
||||||
use crate::comments::Comments;
|
use crate::comments::Comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
default_expression_needs_parentheses, NeedsParentheses, Parentheses, Parenthesize,
|
||||||
};
|
};
|
||||||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter};
|
use crate::prelude::*;
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use crate::FormatNodeRule;
|
||||||
use rustpython_parser::ast::ExprStarred;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatExprStarred;
|
pub struct FormatExprStarred;
|
||||||
|
|
||||||
impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
||||||
fn fmt_fields(&self, _item: &ExprStarred, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &ExprStarred, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(
|
let ExprStarred {
|
||||||
f,
|
range: _,
|
||||||
[not_yet_implemented_custom_text(
|
value,
|
||||||
"*NOT_YET_IMPLEMENTED_ExprStarred"
|
ctx: _,
|
||||||
)]
|
} = item;
|
||||||
)
|
|
||||||
|
write!(f, [text("*"), value.format()])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fmt_dangling_comments(&self, node: &ExprStarred, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
|
debug_assert_eq!(f.context().comments().dangling_comments(node), []);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,7 @@ def f():
|
||||||
+
|
+
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
+@decorator(*args)
|
||||||
+def f():
|
+def f():
|
||||||
+ ...
|
+ ...
|
||||||
+
|
+
|
||||||
|
@ -216,7 +216,7 @@ def f():
|
||||||
##
|
##
|
||||||
|
|
||||||
-@(decorator)
|
-@(decorator)
|
||||||
+@decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
+@decorator(*args, **kwargs)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ def f():
|
||||||
|
|
||||||
-@sequence["decorator"]
|
-@sequence["decorator"]
|
||||||
+@decorator(
|
+@decorator(
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
+ *args,
|
||||||
+ **kwargs,
|
+ **kwargs,
|
||||||
+)
|
+)
|
||||||
def f():
|
def f():
|
||||||
|
@ -257,7 +257,7 @@ def f():
|
||||||
+
|
+
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
+@dotted.decorator(*args)
|
||||||
+def f():
|
+def f():
|
||||||
+ ...
|
+ ...
|
||||||
+
|
+
|
||||||
|
@ -271,7 +271,7 @@ def f():
|
||||||
+
|
+
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
+@dotted.decorator(*args, **kwargs)
|
||||||
+def f():
|
+def f():
|
||||||
+ ...
|
+ ...
|
||||||
+
|
+
|
||||||
|
@ -279,7 +279,7 @@ def f():
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@dotted.decorator(
|
+@dotted.decorator(
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
+ *args,
|
||||||
+ **kwargs,
|
+ **kwargs,
|
||||||
+)
|
+)
|
||||||
+def f():
|
+def f():
|
||||||
|
@ -309,7 +309,7 @@ def f():
|
||||||
+
|
+
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@double.dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
+@double.dotted.decorator(*args)
|
||||||
+def f():
|
+def f():
|
||||||
+ ...
|
+ ...
|
||||||
+
|
+
|
||||||
|
@ -323,7 +323,7 @@ def f():
|
||||||
+
|
+
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@double.dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
+@double.dotted.decorator(*args, **kwargs)
|
||||||
+def f():
|
+def f():
|
||||||
+ ...
|
+ ...
|
||||||
+
|
+
|
||||||
|
@ -331,7 +331,7 @@ def f():
|
||||||
+##
|
+##
|
||||||
+
|
+
|
||||||
+@double.dotted.decorator(
|
+@double.dotted.decorator(
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
+ *args,
|
||||||
+ **kwargs,
|
+ **kwargs,
|
||||||
+)
|
+)
|
||||||
+def f():
|
+def f():
|
||||||
|
@ -392,7 +392,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
@decorator(*args)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
@decorator(*args, **kwargs)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ def f():
|
||||||
##
|
##
|
||||||
|
|
||||||
@decorator(
|
@decorator(
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
def f():
|
def f():
|
||||||
|
@ -444,7 +444,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
@dotted.decorator(*args)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
@dotted.decorator(*args, **kwargs)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ def f():
|
||||||
##
|
##
|
||||||
|
|
||||||
@dotted.decorator(
|
@dotted.decorator(
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
def f():
|
def f():
|
||||||
|
@ -496,7 +496,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@double.dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred)
|
@double.dotted.decorator(*args)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -510,7 +510,7 @@ def f():
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
@double.dotted.decorator(*NOT_YET_IMPLEMENTED_ExprStarred, **kwargs)
|
@double.dotted.decorator(*args, **kwargs)
|
||||||
def f():
|
def f():
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -518,7 +518,7 @@ def f():
|
||||||
##
|
##
|
||||||
|
|
||||||
@double.dotted.decorator(
|
@double.dotted.decorator(
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
def f():
|
def f():
|
||||||
|
|
|
@ -39,21 +39,8 @@ async for x in (
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -1,27 +1,19 @@
|
@@ -10,18 +10,10 @@
|
||||||
-for x in *a, *b:
|
for x in *a, b, *c:
|
||||||
+for x in *NOT_YET_IMPLEMENTED_ExprStarred, *NOT_YET_IMPLEMENTED_ExprStarred:
|
|
||||||
print(x)
|
|
||||||
|
|
||||||
-for x in a, b, *c:
|
|
||||||
+for x in a, b, *NOT_YET_IMPLEMENTED_ExprStarred:
|
|
||||||
print(x)
|
|
||||||
|
|
||||||
-for x in *a, b, c:
|
|
||||||
+for x in *NOT_YET_IMPLEMENTED_ExprStarred, b, c:
|
|
||||||
print(x)
|
|
||||||
|
|
||||||
-for x in *a, b, *c:
|
|
||||||
+for x in *NOT_YET_IMPLEMENTED_ExprStarred, b, *NOT_YET_IMPLEMENTED_ExprStarred:
|
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
-async for x in *a, *b:
|
-async for x in *a, *b:
|
||||||
|
@ -80,16 +67,16 @@ async for x in (
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
|
||||||
```py
|
```py
|
||||||
for x in *NOT_YET_IMPLEMENTED_ExprStarred, *NOT_YET_IMPLEMENTED_ExprStarred:
|
for x in *a, *b:
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
for x in a, b, *NOT_YET_IMPLEMENTED_ExprStarred:
|
for x in a, b, *c:
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
for x in *NOT_YET_IMPLEMENTED_ExprStarred, b, c:
|
for x in *a, b, c:
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
for x in *NOT_YET_IMPLEMENTED_ExprStarred, b, *NOT_YET_IMPLEMENTED_ExprStarred:
|
for x in *a, b, *c:
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
NOT_YET_IMPLEMENTED_StmtAsyncFor
|
NOT_YET_IMPLEMENTED_StmtAsyncFor
|
||||||
|
|
|
@ -1,240 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
|
||||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_311/pep_654.py
|
|
||||||
---
|
|
||||||
## Input
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
raise OSError("blah")
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except* ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise ValueError(42)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
raise TypeError(int)
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
raise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* (TypeError, ValueError) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* OSError as e:
|
|
||||||
raise TypeError(3) from e
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Black Differences
|
|
||||||
|
|
||||||
```diff
|
|
||||||
--- Black
|
|
||||||
+++ Ruff
|
|
||||||
@@ -1,5 +1,5 @@
|
|
||||||
try:
|
|
||||||
- raise OSError("blah")
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@@ -14,10 +14,10 @@
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
- raise ValueError(42)
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
- raise TypeError(int)
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
@@ -26,10 +26,10 @@
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
- raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
- raise
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
@@ -38,16 +38,16 @@
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
- raise orig
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* (TypeError, ValueError) as e:
|
|
||||||
- raise SyntaxError(3) from e
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
- raise orig
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* OSError as e:
|
|
||||||
- raise TypeError(3) from e
|
|
||||||
+ NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Ruff Output
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except* ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* (TypeError, ValueError) as e:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except* OSError as e:
|
|
||||||
NOT_YET_IMPLEMENTED_StmtRaise
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Black Output
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
raise OSError("blah")
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except* ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise ValueError(42)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
raise TypeError(int)
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
raise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* (TypeError, ValueError) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* OSError as e:
|
|
||||||
raise TypeError(3) from e
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
|
@ -1,197 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
|
||||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_311/pep_654_style.py
|
|
||||||
---
|
|
||||||
## Input
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
raise OSError("blah")
|
|
||||||
except * ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except *ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise ValueError(42)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
raise TypeError(int)
|
|
||||||
except *(Exception):
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
except \
|
|
||||||
*TypeError as e:
|
|
||||||
tes = e
|
|
||||||
raise
|
|
||||||
except * ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except *(TypeError, ValueError, *OTHER_EXCEPTIONS) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except\
|
|
||||||
* OSError as e:
|
|
||||||
raise TypeError(3) from e
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Black Differences
|
|
||||||
|
|
||||||
```diff
|
|
||||||
--- Black
|
|
||||||
+++ Ruff
|
|
||||||
@@ -39,7 +39,7 @@
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
- except* (TypeError, ValueError, *OTHER_EXCEPTIONS) as e:
|
|
||||||
+ except* (TypeError, ValueError, *NOT_YET_IMPLEMENTED_ExprStarred) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Ruff Output
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
raise OSError("blah")
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except* ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise ValueError(42)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
raise TypeError(int)
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
raise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* (TypeError, ValueError, *NOT_YET_IMPLEMENTED_ExprStarred) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* OSError as e:
|
|
||||||
raise TypeError(3) from e
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
## Black Output
|
|
||||||
|
|
||||||
```py
|
|
||||||
try:
|
|
||||||
raise OSError("blah")
|
|
||||||
except* ExceptionGroup as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with trio.open_nursery() as nursery:
|
|
||||||
# Make two concurrent calls to child()
|
|
||||||
nursery.start_soon(child)
|
|
||||||
nursery.start_soon(child)
|
|
||||||
except* ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise ValueError(42)
|
|
||||||
except:
|
|
||||||
try:
|
|
||||||
raise TypeError(int)
|
|
||||||
except* Exception:
|
|
||||||
pass
|
|
||||||
1 / 0
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise FalsyEG("eg", [TypeError(1), ValueError(2)])
|
|
||||||
except* TypeError as e:
|
|
||||||
tes = e
|
|
||||||
raise
|
|
||||||
except* ValueError as e:
|
|
||||||
ves = e
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* (TypeError, ValueError, *OTHER_EXCEPTIONS) as e:
|
|
||||||
raise SyntaxError(3) from e
|
|
||||||
except BaseException as e:
|
|
||||||
exc = e
|
|
||||||
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
raise orig
|
|
||||||
except* OSError as e:
|
|
||||||
raise TypeError(3) from e
|
|
||||||
except ExceptionGroup as e:
|
|
||||||
exc = e
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ while x := f(x):
|
||||||
(y := f(x))
|
(y := f(x))
|
||||||
y0 = (y1 := f(x))
|
y0 = (y1 := f(x))
|
||||||
foo(x=(y := f(x)))
|
foo(x=(y := f(x)))
|
||||||
@@ -19,29 +19,29 @@
|
@@ -19,10 +19,10 @@
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,10 +86,8 @@ while x := f(x):
|
||||||
+lambda x: True
|
+lambda x: True
|
||||||
x = (y := 0)
|
x = (y := 0)
|
||||||
(z := (y := (x := 0)))
|
(z := (y := (x := 0)))
|
||||||
-(info := (name, phone, *rest))
|
(info := (name, phone, *rest))
|
||||||
+(info := (name, phone, *NOT_YET_IMPLEMENTED_ExprStarred))
|
@@ -31,17 +31,17 @@
|
||||||
(x := 1, 2)
|
|
||||||
(total := total + tax)
|
|
||||||
len(lines := f.readlines())
|
len(lines := f.readlines())
|
||||||
foo(x := 3, cat="vector")
|
foo(x := 3, cat="vector")
|
||||||
foo(cat=(category := "vector"))
|
foo(cat=(category := "vector"))
|
||||||
|
@ -144,7 +142,7 @@ lambda x: True
|
||||||
lambda x: True
|
lambda x: True
|
||||||
x = (y := 0)
|
x = (y := 0)
|
||||||
(z := (y := (x := 0)))
|
(z := (y := (x := 0)))
|
||||||
(info := (name, phone, *NOT_YET_IMPLEMENTED_ExprStarred))
|
(info := (name, phone, *rest))
|
||||||
(x := 1, 2)
|
(x := 1, 2)
|
||||||
(total := total + tax)
|
(total := total + tax)
|
||||||
len(lines := f.readlines())
|
len(lines := f.readlines())
|
||||||
|
|
|
@ -31,13 +31,7 @@ def t():
|
||||||
```diff
|
```diff
|
||||||
--- Black
|
--- Black
|
||||||
+++ Ruff
|
+++ Ruff
|
||||||
@@ -3,19 +3,19 @@
|
@@ -8,14 +8,14 @@
|
||||||
|
|
||||||
def starred_return():
|
|
||||||
my_list = ["value2", "value3"]
|
|
||||||
- return "value1", *my_list
|
|
||||||
+ return "value1", *NOT_YET_IMPLEMENTED_ExprStarred
|
|
||||||
|
|
||||||
|
|
||||||
def starred_yield():
|
def starred_yield():
|
||||||
my_list = ["value2", "value3"]
|
my_list = ["value2", "value3"]
|
||||||
|
@ -66,7 +60,7 @@ def t():
|
||||||
|
|
||||||
def starred_return():
|
def starred_return():
|
||||||
my_list = ["value2", "value3"]
|
my_list = ["value2", "value3"]
|
||||||
return "value1", *NOT_YET_IMPLEMENTED_ExprStarred
|
return "value1", *my_list
|
||||||
|
|
||||||
|
|
||||||
def starred_yield():
|
def starred_yield():
|
||||||
|
|
|
@ -141,7 +141,7 @@ 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 = (
|
||||||
@@ -100,19 +98,32 @@
|
@@ -100,19 +98,30 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
c = call(
|
c = call(
|
||||||
|
@ -177,10 +177,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
|
||||||
+ ], # type: ignore
|
+ ], # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
-aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||||
+aaaaaaaaaaaaa, bbbbbbbbb = map(
|
|
||||||
+ list, map(itertools.chain.from_iterable, zip(*NOT_YET_IMPLEMENTED_ExprStarred))
|
|
||||||
+) # type: ignore[arg-type]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Ruff Output
|
## Ruff Output
|
||||||
|
@ -312,9 +309,7 @@ call_to_some_function_asdf(
|
||||||
], # type: ignore
|
], # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
aaaaaaaaaaaaa, bbbbbbbbb = map(
|
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
|
||||||
list, map(itertools.chain.from_iterable, zip(*NOT_YET_IMPLEMENTED_ExprStarred))
|
|
||||||
) # type: ignore[arg-type]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Black Output
|
## Black Output
|
||||||
|
|
|
@ -316,32 +316,9 @@ last_call()
|
||||||
()
|
()
|
||||||
(1,)
|
(1,)
|
||||||
(1, 2)
|
(1, 2)
|
||||||
@@ -69,40 +72,37 @@
|
@@ -87,22 +90,19 @@
|
||||||
2,
|
|
||||||
3,
|
|
||||||
]
|
|
||||||
-[*a]
|
|
||||||
-[*range(10)]
|
|
||||||
+[*NOT_YET_IMPLEMENTED_ExprStarred]
|
|
||||||
+[*NOT_YET_IMPLEMENTED_ExprStarred]
|
|
||||||
[
|
|
||||||
- *a,
|
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
]
|
|
||||||
[
|
|
||||||
4,
|
|
||||||
- *a,
|
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
|
||||||
5,
|
|
||||||
]
|
|
||||||
[
|
|
||||||
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
|
||||||
element,
|
|
||||||
another,
|
another,
|
||||||
- *more,
|
*more,
|
||||||
+ *NOT_YET_IMPLEMENTED_ExprStarred,
|
|
||||||
]
|
]
|
||||||
-{i for i in (1, 2, 3)}
|
-{i for i in (1, 2, 3)}
|
||||||
-{(i**2) for i in (1, 2, 3)}
|
-{(i**2) for i in (1, 2, 3)}
|
||||||
|
@ -375,20 +352,15 @@ last_call()
|
||||||
Python3 > Python2 > COBOL
|
Python3 > Python2 > COBOL
|
||||||
Life is Life
|
Life is Life
|
||||||
call()
|
call()
|
||||||
@@ -115,10 +115,10 @@
|
@@ -115,7 +115,7 @@
|
||||||
arg,
|
arg,
|
||||||
another,
|
another,
|
||||||
kwarg="hey",
|
kwarg="hey",
|
||||||
- **kwargs
|
- **kwargs
|
||||||
+ **kwargs,
|
+ **kwargs,
|
||||||
) # 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])
|
||||||
+call(*NOT_YET_IMPLEMENTED_ExprStarred)
|
|
||||||
+call(a, *NOT_YET_IMPLEMENTED_ExprStarred)
|
|
||||||
call(**self.screen_kwargs)
|
|
||||||
call(b, **self.screen_kwargs)
|
|
||||||
lukasz.langa.pl
|
|
||||||
@@ -131,34 +131,28 @@
|
@@ -131,34 +131,28 @@
|
||||||
tuple[str, ...]
|
tuple[str, ...]
|
||||||
tuple[str, int, float, dict[str, int]]
|
tuple[str, int, float, dict[str, int]]
|
||||||
|
@ -397,6 +369,9 @@ last_call()
|
||||||
- int,
|
- int,
|
||||||
- float,
|
- float,
|
||||||
- dict[str, int],
|
- dict[str, int],
|
||||||
|
-]
|
||||||
|
-very_long_variable_name_filters: t.List[
|
||||||
|
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
+ (
|
+ (
|
||||||
+ str,
|
+ str,
|
||||||
+ int,
|
+ int,
|
||||||
|
@ -404,9 +379,6 @@ last_call()
|
||||||
+ dict[str, int],
|
+ dict[str, int],
|
||||||
+ )
|
+ )
|
||||||
]
|
]
|
||||||
-very_long_variable_name_filters: t.List[
|
|
||||||
- t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
|
||||||
-]
|
|
||||||
-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
-)
|
-)
|
||||||
|
@ -446,7 +418,7 @@ last_call()
|
||||||
numpy[np.newaxis, :]
|
numpy[np.newaxis, :]
|
||||||
(str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
|
(str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
|
||||||
{"2.7": dead, "3.7": long_live or die_hard}
|
{"2.7": dead, "3.7": long_live or die_hard}
|
||||||
@@ -181,11 +175,11 @@
|
@@ -181,10 +175,10 @@
|
||||||
(SomeName)
|
(SomeName)
|
||||||
SomeName
|
SomeName
|
||||||
(Good, Bad, Ugly)
|
(Good, Bad, Ugly)
|
||||||
|
@ -454,26 +426,14 @@ last_call()
|
||||||
-((i**2) for i in (1, 2, 3))
|
-((i**2) for i in (1, 2, 3))
|
||||||
-((i**2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
|
-((i**2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
|
||||||
-(((i**2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
|
-(((i**2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
|
||||||
-(*starred,)
|
|
||||||
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
+(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
+(*NOT_YET_IMPLEMENTED_ExprStarred,)
|
(*starred,)
|
||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"type": "type",
|
@@ -208,24 +202,14 @@
|
||||||
@@ -200,32 +194,22 @@
|
|
||||||
c = 1
|
|
||||||
d = (1,) + a + (2,)
|
|
||||||
e = (1,).count(1)
|
|
||||||
-f = 1, *range(10)
|
|
||||||
-g = 1, *"ten"
|
|
||||||
+f = 1, *NOT_YET_IMPLEMENTED_ExprStarred
|
|
||||||
+g = 1, *NOT_YET_IMPLEMENTED_ExprStarred
|
|
||||||
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
|
|
||||||
vars_to_remove
|
|
||||||
)
|
|
||||||
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
|
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
|
||||||
vars_to_remove
|
vars_to_remove
|
||||||
)
|
)
|
||||||
|
@ -506,7 +466,7 @@ last_call()
|
||||||
Ø = set()
|
Ø = set()
|
||||||
authors.łukasz.say_thanks()
|
authors.łukasz.say_thanks()
|
||||||
mapping = {
|
mapping = {
|
||||||
@@ -237,29 +221,33 @@
|
@@ -237,10 +221,10 @@
|
||||||
|
|
||||||
|
|
||||||
def gen():
|
def gen():
|
||||||
|
@ -521,10 +481,10 @@ last_call()
|
||||||
|
|
||||||
|
|
||||||
async def f():
|
async def f():
|
||||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
@@ -248,18 +232,22 @@
|
||||||
|
|
||||||
|
|
||||||
-print(*[] or [1])
|
print(*[] or [1])
|
||||||
-print(**{1: 3} if False else {x: x for x in range(3)})
|
-print(**{1: 3} if False else {x: x for x in range(3)})
|
||||||
-print(*lambda x: x)
|
-print(*lambda x: x)
|
||||||
-assert not Test, "Short message"
|
-assert not Test, "Short message"
|
||||||
|
@ -532,13 +492,12 @@ last_call()
|
||||||
- force=False
|
- force=False
|
||||||
-), "Short message"
|
-), "Short message"
|
||||||
-assert parens is TooMany
|
-assert parens is TooMany
|
||||||
+print(*NOT_YET_IMPLEMENTED_ExprStarred)
|
|
||||||
+print(
|
+print(
|
||||||
+ **{1: 3}
|
+ **{1: 3}
|
||||||
+ if False
|
+ if False
|
||||||
+ else {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
+ else {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
+)
|
+)
|
||||||
+print(*NOT_YET_IMPLEMENTED_ExprStarred)
|
+print(*lambda x: True)
|
||||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
+NOT_YET_IMPLEMENTED_StmtAssert
|
+NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
@ -664,23 +623,23 @@ str or None if (1 if True else 2) else str or bytes or None
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
]
|
]
|
||||||
[*NOT_YET_IMPLEMENTED_ExprStarred]
|
[*a]
|
||||||
[*NOT_YET_IMPLEMENTED_ExprStarred]
|
[*range(10)]
|
||||||
[
|
[
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*a,
|
||||||
4,
|
4,
|
||||||
5,
|
5,
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
4,
|
4,
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*a,
|
||||||
5,
|
5,
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
||||||
element,
|
element,
|
||||||
another,
|
another,
|
||||||
*NOT_YET_IMPLEMENTED_ExprStarred,
|
*more,
|
||||||
]
|
]
|
||||||
{NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
|
{NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
|
||||||
{NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
|
{NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
|
||||||
|
@ -709,8 +668,8 @@ call(
|
||||||
kwarg="hey",
|
kwarg="hey",
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) # note: no trailing comma pre-3.6
|
) # note: no trailing comma pre-3.6
|
||||||
call(*NOT_YET_IMPLEMENTED_ExprStarred)
|
call(*gidgets[:2])
|
||||||
call(a, *NOT_YET_IMPLEMENTED_ExprStarred)
|
call(a, *gidgets[:2])
|
||||||
call(**self.screen_kwargs)
|
call(**self.screen_kwargs)
|
||||||
call(b, **self.screen_kwargs)
|
call(b, **self.screen_kwargs)
|
||||||
lukasz.langa.pl
|
lukasz.langa.pl
|
||||||
|
@ -771,7 +730,7 @@ SomeName
|
||||||
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
(NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in [])
|
||||||
(*NOT_YET_IMPLEMENTED_ExprStarred,)
|
(*starred,)
|
||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"type": "type",
|
"type": "type",
|
||||||
|
@ -786,8 +745,8 @@ b = (1,)
|
||||||
c = 1
|
c = 1
|
||||||
d = (1,) + a + (2,)
|
d = (1,) + a + (2,)
|
||||||
e = (1,).count(1)
|
e = (1,).count(1)
|
||||||
f = 1, *NOT_YET_IMPLEMENTED_ExprStarred
|
f = 1, *range(10)
|
||||||
g = 1, *NOT_YET_IMPLEMENTED_ExprStarred
|
g = 1, *"ten"
|
||||||
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
|
what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
|
||||||
vars_to_remove
|
vars_to_remove
|
||||||
)
|
)
|
||||||
|
@ -823,13 +782,13 @@ async def f():
|
||||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||||
|
|
||||||
|
|
||||||
print(*NOT_YET_IMPLEMENTED_ExprStarred)
|
print(*[] or [1])
|
||||||
print(
|
print(
|
||||||
**{1: 3}
|
**{1: 3}
|
||||||
if False
|
if False
|
||||||
else {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
else {NOT_IMPLEMENTED_dict_key: NOT_IMPLEMENTED_dict_value for key, value in NOT_IMPLEMENTED_dict}
|
||||||
)
|
)
|
||||||
print(*NOT_YET_IMPLEMENTED_ExprStarred)
|
print(*lambda x: True)
|
||||||
NOT_YET_IMPLEMENTED_StmtAssert
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
NOT_YET_IMPLEMENTED_StmtAssert
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
NOT_YET_IMPLEMENTED_StmtAssert
|
NOT_YET_IMPLEMENTED_StmtAssert
|
||||||
|
|
|
@ -316,7 +316,7 @@ d={'a':1,
|
||||||
# fmt: off
|
# fmt: off
|
||||||
- a , b = *hello
|
- a , b = *hello
|
||||||
- 'unformatted'
|
- 'unformatted'
|
||||||
+ a, b = *NOT_YET_IMPLEMENTED_ExprStarred
|
+ a, b = *hello
|
||||||
+ "unformatted"
|
+ "unformatted"
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
@ -507,7 +507,7 @@ def import_as_names():
|
||||||
|
|
||||||
def testlist_star_expr():
|
def testlist_star_expr():
|
||||||
# fmt: off
|
# fmt: off
|
||||||
a, b = *NOT_YET_IMPLEMENTED_ExprStarred
|
a, b = *hello
|
||||||
"unformatted"
|
"unformatted"
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||||
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/starred.py
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
```py
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
* # Trailing star comment
|
||||||
|
[
|
||||||
|
# Leading value commnt
|
||||||
|
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||||
|
] # trailing value comment
|
||||||
|
)
|
||||||
|
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
* ( # Leading value commnt
|
||||||
|
[What, i, this, s, very, long, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]
|
||||||
|
) # trailing value comment
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output
|
||||||
|
```py
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
# Trailing star comment
|
||||||
|
*[
|
||||||
|
# Leading value commnt
|
||||||
|
[
|
||||||
|
What,
|
||||||
|
i,
|
||||||
|
this,
|
||||||
|
s,
|
||||||
|
very,
|
||||||
|
long,
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
||||||
|
]
|
||||||
|
] # trailing value comment
|
||||||
|
)
|
||||||
|
|
||||||
|
call(
|
||||||
|
# Leading starred comment
|
||||||
|
# Leading value commnt
|
||||||
|
*(
|
||||||
|
[
|
||||||
|
What,
|
||||||
|
i,
|
||||||
|
this,
|
||||||
|
s,
|
||||||
|
very,
|
||||||
|
long,
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
||||||
|
]
|
||||||
|
) # trailing value comment
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ with (
|
||||||
# currently unparsable by black: https://github.com/psf/black/issues/3678
|
# currently unparsable by black: https://github.com/psf/black/issues/3678
|
||||||
with (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
|
with (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
|
||||||
pass
|
pass
|
||||||
with (a, *NOT_YET_IMPLEMENTED_ExprStarred):
|
with (a, *b):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue