mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Regenerate expected Black snapshots (#2968)
This commit is contained in:
parent
879512742f
commit
1c01ec21cb
45 changed files with 2336 additions and 194 deletions
|
@ -1,4 +1,4 @@
|
||||||
ax = 123456789 .bit_count()
|
x = 123456789 .bit_count()
|
||||||
x = (123456).__abs__()
|
x = (123456).__abs__()
|
||||||
x = .1.is_integer()
|
x = .1.is_integer()
|
||||||
x = 1. .imag
|
x = 1. .imag
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# The percent-percent comments are Spyder IDE cells.
|
# The percent-percent comments are Spyder IDE cells.
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
def func():
|
def func():
|
||||||
x = """
|
x = """
|
||||||
|
|
|
@ -62,6 +62,8 @@ def decorated1():
|
||||||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||||
# In the current style, the user will have to split those lines by hand.
|
# In the current style, the user will have to split those lines by hand.
|
||||||
some_instruction
|
some_instruction
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||||
def g():
|
def g():
|
||||||
...
|
...
|
||||||
|
|
6
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py
vendored
Normal file
6
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# The percent-percent comments are Spyder IDE cells.
|
||||||
|
# Both `#%%`` and `# %%` are accepted, so `black` standardises
|
||||||
|
# to the latter.
|
||||||
|
|
||||||
|
#%%
|
||||||
|
# %%
|
139
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py
vendored
Normal file
139
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py
vendored
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
# Test for https://github.com/psf/black/issues/246.
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This multiline comments section
|
||||||
|
# should be split from the statement
|
||||||
|
# above by two lines.
|
||||||
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
async def async_function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
class MyClass:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This should be stick to the statement above
|
||||||
|
|
||||||
|
# This should be split from the above by two lines
|
||||||
|
class MyClassWithComplexLeadingComments:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClassWithDocstring:
|
||||||
|
"""A docstring."""
|
||||||
|
# Leading comment after a class with just a docstring
|
||||||
|
class MyClassAfterAnotherClassWithDocstring:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
# leading 2 extra
|
||||||
|
@deco2(with_args=True)
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@deco2(with_args=True)
|
||||||
|
|
||||||
|
# leading 3 that already has an empty line
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@deco2(with_args=True)
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
|
||||||
|
# leading 4 that already has an empty line
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if a:
|
||||||
|
# Leading comment before inline function
|
||||||
|
def inline():
|
||||||
|
pass
|
||||||
|
# Another leading comment
|
||||||
|
def another_inline():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# More leading comments
|
||||||
|
def inline_after_else():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if a:
|
||||||
|
# Leading comment before "top-level inline" function
|
||||||
|
def top_level_quote_inline():
|
||||||
|
pass
|
||||||
|
# Another leading comment
|
||||||
|
def another_top_level_quote_inline_inline():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# More leading comments
|
||||||
|
def top_level_quote_inline_after_else():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MyClass:
|
||||||
|
# First method has no empty lines between bare class def.
|
||||||
|
# More comments.
|
||||||
|
def first_method(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
@decorator2 # fmt: skip
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function.
|
||||||
|
# NOTE this comment only has one empty line below, and the formatter
|
||||||
|
# should enforce two blank lines.
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
# A standalone comment
|
||||||
|
def bar():
|
||||||
|
pass
|
50
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py
vendored
Normal file
50
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py
vendored
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
def docstring_almost_at_line_limit():
|
||||||
|
"""long docstring.................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def mulitline_docstring_almost_at_line_limit():
|
||||||
|
"""long docstring.................................................................
|
||||||
|
|
||||||
|
..................................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring................................................................
|
||||||
|
|
||||||
|
..................................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_at_line_limit():
|
||||||
|
"""long docstring................................................................"""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring..............................................................."""
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_docstring_at_line_limit():
|
||||||
|
"""first line-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
second line----------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_docstring_at_line_limit_with_prefix():
|
||||||
|
f"""first line----------------------------------------------------------------------
|
||||||
|
|
||||||
|
second line----------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
|
||||||
|
def single_quote_docstring_over_line_limit():
|
||||||
|
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||||
|
|
||||||
|
|
||||||
|
def single_quote_docstring_over_line_limit2():
|
||||||
|
'We do not want to put the closing quote on a new line as that is invalid (see GH-3141).'
|
466
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.diff
vendored
Normal file
466
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.diff
vendored
Normal file
|
@ -0,0 +1,466 @@
|
||||||
|
--- [Deterministic header]
|
||||||
|
+++ [Deterministic header]
|
||||||
|
@@ -1,8 +1,8 @@
|
||||||
|
...
|
||||||
|
-'some_string'
|
||||||
|
-b'\\xa3'
|
||||||
|
+"some_string"
|
||||||
|
+b"\\xa3"
|
||||||
|
Name
|
||||||
|
None
|
||||||
|
True
|
||||||
|
False
|
||||||
|
1
|
||||||
|
@@ -21,99 +21,135 @@
|
||||||
|
Name1 or (Name2 and Name3) or Name4
|
||||||
|
Name1 or Name2 and Name3 or Name4
|
||||||
|
v1 << 2
|
||||||
|
1 >> v2
|
||||||
|
1 % finished
|
||||||
|
-1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
|
||||||
|
-((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
|
||||||
|
+1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8
|
||||||
|
+((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8)
|
||||||
|
not great
|
||||||
|
~great
|
||||||
|
+value
|
||||||
|
-1
|
||||||
|
~int and not v1 ^ 123 + v2 | True
|
||||||
|
(~int) and (not ((v1 ^ (123 + v2)) | True))
|
||||||
|
-+really ** -confusing ** ~operator ** -precedence
|
||||||
|
-flags & ~ select.EPOLLIN and waiters.write_task is not None
|
||||||
|
++(really ** -(confusing ** ~(operator**-precedence)))
|
||||||
|
+flags & ~select.EPOLLIN and waiters.write_task is not None
|
||||||
|
lambda arg: None
|
||||||
|
lambda a=True: a
|
||||||
|
lambda a, b, c=True: a
|
||||||
|
-lambda a, b, c=True, *, d=(1 << v2), e='str': a
|
||||||
|
-lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
|
||||||
|
+lambda a, b, c=True, *, d=(1 << v2), e="str": a
|
||||||
|
+lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
|
||||||
|
manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
|
||||||
|
-foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
|
||||||
|
+foo = lambda port_id, ignore_missing: {
|
||||||
|
+ "port1": port1_resource,
|
||||||
|
+ "port2": port2_resource,
|
||||||
|
+}[port_id]
|
||||||
|
1 if True else 2
|
||||||
|
str or None if True else str or bytes or None
|
||||||
|
(str or None) if True else (str or bytes or None)
|
||||||
|
str or None if (1 if True else 2) else str or bytes or None
|
||||||
|
(str or None) if (1 if True else 2) else (str or bytes or None)
|
||||||
|
-((super_long_variable_name or None) if (1 if super_long_test_name else 2) 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), **{'3.6': verygood}}
|
||||||
|
+(
|
||||||
|
+ (super_long_variable_name or None)
|
||||||
|
+ if (1 if super_long_test_name else 2)
|
||||||
|
+ 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), **{"3.6": verygood}}
|
||||||
|
{**a, **b, **c}
|
||||||
|
-{'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')}
|
||||||
|
-({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None
|
||||||
|
+{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
|
||||||
|
+({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
|
||||||
|
()
|
||||||
|
(1,)
|
||||||
|
(1, 2)
|
||||||
|
(1, 2, 3)
|
||||||
|
[]
|
||||||
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
|
||||||
|
-[1, 2, 3,]
|
||||||
|
+[
|
||||||
|
+ 1,
|
||||||
|
+ 2,
|
||||||
|
+ 3,
|
||||||
|
+]
|
||||||
|
[*a]
|
||||||
|
[*range(10)]
|
||||||
|
-[*a, 4, 5,]
|
||||||
|
-[4, *a, 5,]
|
||||||
|
-[this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, another, *more]
|
||||||
|
+[
|
||||||
|
+ *a,
|
||||||
|
+ 4,
|
||||||
|
+ 5,
|
||||||
|
+]
|
||||||
|
+[
|
||||||
|
+ 4,
|
||||||
|
+ *a,
|
||||||
|
+ 5,
|
||||||
|
+]
|
||||||
|
+[
|
||||||
|
+ this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
||||||
|
+ element,
|
||||||
|
+ another,
|
||||||
|
+ *more,
|
||||||
|
+]
|
||||||
|
{i 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) + j) for i in (1, 2, 3) for j 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) + j) for i in (1, 2, 3) for j 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, 'a'), (2, 'b'), (3, 'c'))]
|
||||||
|
-[((i ** 2) + j) for i in (1, 2, 3) for j 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) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
|
||||||
|
{i: 0 for i in (1, 2, 3)}
|
||||||
|
-{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
|
||||||
|
+{i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
|
||||||
|
{a: b * 2 for a, b in dictionary.items()}
|
||||||
|
{a: b * -2 for a, b in dictionary.items()}
|
||||||
|
-{k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension}
|
||||||
|
+{
|
||||||
|
+ k: v
|
||||||
|
+ for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
|
||||||
|
+}
|
||||||
|
Python3 > Python2 > COBOL
|
||||||
|
Life is Life
|
||||||
|
call()
|
||||||
|
call(arg)
|
||||||
|
-call(kwarg='hey')
|
||||||
|
-call(arg, kwarg='hey')
|
||||||
|
-call(arg, another, kwarg='hey', **kwargs)
|
||||||
|
-call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs) # note: no trailing comma pre-3.6
|
||||||
|
+call(kwarg="hey")
|
||||||
|
+call(arg, kwarg="hey")
|
||||||
|
+call(arg, another, kwarg="hey", **kwargs)
|
||||||
|
+call(
|
||||||
|
+ this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
||||||
|
+ arg,
|
||||||
|
+ another,
|
||||||
|
+ kwarg="hey",
|
||||||
|
+ **kwargs
|
||||||
|
+) # note: no trailing comma pre-3.6
|
||||||
|
call(*gidgets[:2])
|
||||||
|
call(a, *gidgets[:2])
|
||||||
|
call(**self.screen_kwargs)
|
||||||
|
call(b, **self.screen_kwargs)
|
||||||
|
lukasz.langa.pl
|
||||||
|
call.me(maybe)
|
||||||
|
-1 .real
|
||||||
|
-1.0 .real
|
||||||
|
+(1).real
|
||||||
|
+(1.0).real
|
||||||
|
....__class__
|
||||||
|
list[str]
|
||||||
|
dict[str, int]
|
||||||
|
tuple[str, ...]
|
||||||
|
+tuple[str, int, float, dict[str, int]]
|
||||||
|
tuple[
|
||||||
|
- str, int, float, dict[str, int]
|
||||||
|
-]
|
||||||
|
-tuple[str, int, float, dict[str, int],]
|
||||||
|
+ str,
|
||||||
|
+ int,
|
||||||
|
+ float,
|
||||||
|
+ dict[str, int],
|
||||||
|
+]
|
||||||
|
very_long_variable_name_filters: t.List[
|
||||||
|
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
|
]
|
||||||
|
xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
||||||
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
)
|
||||||
|
-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[
|
||||||
|
- ..., List[SomeClass]
|
||||||
|
-] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
|
||||||
|
+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
|
||||||
|
+ sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
|
+) # type: ignore
|
||||||
|
slice[0]
|
||||||
|
slice[0:1]
|
||||||
|
slice[0:1:2]
|
||||||
|
slice[:]
|
||||||
|
slice[:-1]
|
||||||
|
@@ -137,118 +173,199 @@
|
||||||
|
numpy[-(c + 1) :, d]
|
||||||
|
numpy[:, l[-2]]
|
||||||
|
numpy[:, ::-1]
|
||||||
|
numpy[np.newaxis, :]
|
||||||
|
(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', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}
|
||||||
|
+{"2.7": dead, "3.7": long_live or die_hard}
|
||||||
|
+{"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
|
||||||
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
|
||||||
|
(SomeName)
|
||||||
|
SomeName
|
||||||
|
(Good, Bad, Ugly)
|
||||||
|
(i 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) + j) for i in (1, 2, 3) for j 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) + j) for i in (1, 2, 3) for j in (1, 2, 3))
|
||||||
|
(*starred,)
|
||||||
|
-{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs}
|
||||||
|
+{
|
||||||
|
+ "id": "1",
|
||||||
|
+ "type": "type",
|
||||||
|
+ "started_at": now(),
|
||||||
|
+ "ended_at": now() + timedelta(days=10),
|
||||||
|
+ "priority": 1,
|
||||||
|
+ "import_session_id": 1,
|
||||||
|
+ **kwargs,
|
||||||
|
+}
|
||||||
|
a = (1,)
|
||||||
|
-b = 1,
|
||||||
|
+b = (1,)
|
||||||
|
c = 1
|
||||||
|
d = (1,) + a + (2,)
|
||||||
|
e = (1,).count(1)
|
||||||
|
f = 1, *range(10)
|
||||||
|
g = 1, *"ten"
|
||||||
|
-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(vars_to_remove)
|
||||||
|
-result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc()).all()
|
||||||
|
-result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all()
|
||||||
|
+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(
|
||||||
|
+ vars_to_remove
|
||||||
|
+)
|
||||||
|
+result = (
|
||||||
|
+ session.query(models.Customer.id)
|
||||||
|
+ .filter(
|
||||||
|
+ models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
|
+ )
|
||||||
|
+ .order_by(models.Customer.id.asc())
|
||||||
|
+ .all()
|
||||||
|
+)
|
||||||
|
+result = (
|
||||||
|
+ session.query(models.Customer.id)
|
||||||
|
+ .filter(
|
||||||
|
+ models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
|
+ )
|
||||||
|
+ .order_by(
|
||||||
|
+ models.Customer.id.asc(),
|
||||||
|
+ )
|
||||||
|
+ .all()
|
||||||
|
+)
|
||||||
|
Ø = set()
|
||||||
|
authors.łukasz.say_thanks()
|
||||||
|
mapping = {
|
||||||
|
A: 0.25 * (10.0 / 12),
|
||||||
|
B: 0.1 * (10.0 / 12),
|
||||||
|
C: 0.1 * (10.0 / 12),
|
||||||
|
D: 0.1 * (10.0 / 12),
|
||||||
|
}
|
||||||
|
|
||||||
|
+
|
||||||
|
def gen():
|
||||||
|
yield from outside_of_generator
|
||||||
|
- a = (yield)
|
||||||
|
- b = ((yield))
|
||||||
|
- c = (((yield)))
|
||||||
|
+ a = yield
|
||||||
|
+ b = yield
|
||||||
|
+ c = yield
|
||||||
|
+
|
||||||
|
|
||||||
|
async def f():
|
||||||
|
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||||
|
-print(* [] or [1])
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+print(*[] or [1])
|
||||||
|
print(**{1: 3} if False else {x: x for x in range(3)})
|
||||||
|
-print(* lambda x: x)
|
||||||
|
-assert(not Test),("Short message")
|
||||||
|
-assert this is ComplexTest and not requirements.fit_in_a_single_line(force=False), "Short message"
|
||||||
|
-assert(((parens is TooMany)))
|
||||||
|
-for x, in (1,), (2,), (3,): ...
|
||||||
|
-for y in (): ...
|
||||||
|
-for z in (i for i in (1, 2, 3)): ...
|
||||||
|
-for i in (call()): ...
|
||||||
|
-for j in (1 + (2 + 3)): ...
|
||||||
|
-while(this and that): ...
|
||||||
|
-for addr_family, addr_type, addr_proto, addr_canonname, addr_sockaddr in socket.getaddrinfo('google.com', 'http'):
|
||||||
|
+print(*lambda x: x)
|
||||||
|
+assert not Test, "Short message"
|
||||||
|
+assert this is ComplexTest and not requirements.fit_in_a_single_line(
|
||||||
|
+ force=False
|
||||||
|
+), "Short message"
|
||||||
|
+assert parens is TooMany
|
||||||
|
+for (x,) in (1,), (2,), (3,):
|
||||||
|
+ ...
|
||||||
|
+for y in ():
|
||||||
|
+ ...
|
||||||
|
+for z in (i for i in (1, 2, 3)):
|
||||||
|
+ ...
|
||||||
|
+for i in call():
|
||||||
|
+ ...
|
||||||
|
+for j in 1 + (2 + 3):
|
||||||
|
+ ...
|
||||||
|
+while this and that:
|
||||||
|
+ ...
|
||||||
|
+for (
|
||||||
|
+ addr_family,
|
||||||
|
+ addr_type,
|
||||||
|
+ addr_proto,
|
||||||
|
+ addr_canonname,
|
||||||
|
+ addr_sockaddr,
|
||||||
|
+) in socket.getaddrinfo("google.com", "http"):
|
||||||
|
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
|
||||||
|
-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
|
||||||
|
-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
|
||||||
|
-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
|
||||||
|
-if (
|
||||||
|
- threading.current_thread() != threading.main_thread() and
|
||||||
|
- threading.current_thread() != threading.main_thread() or
|
||||||
|
- signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
|
||||||
|
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-if (
|
||||||
|
- 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
|
||||||
|
-):
|
||||||
|
- 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
|
||||||
|
-):
|
||||||
|
- 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
|
||||||
|
-):
|
||||||
|
- return True
|
||||||
|
-aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaa * (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa) / (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
+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
|
||||||
|
+)
|
||||||
|
+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
|
||||||
|
+)
|
||||||
|
+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
|
||||||
|
+)
|
||||||
|
+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
|
||||||
|
+)
|
||||||
|
+if (
|
||||||
|
+ threading.current_thread() != threading.main_thread()
|
||||||
|
+ and threading.current_thread() != threading.main_thread()
|
||||||
|
+ or signal.getsignal(signal.SIGINT) != signal.default_int_handler
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+if (
|
||||||
|
+ 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
|
||||||
|
+):
|
||||||
|
+ 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
|
||||||
|
+):
|
||||||
|
+ 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
|
||||||
|
+):
|
||||||
|
+ return True
|
||||||
|
+(
|
||||||
|
+ aaaaaaaaaaaaaaaa
|
||||||
|
+ + aaaaaaaaaaaaaaaa
|
||||||
|
+ - aaaaaaaaaaaaaaaa
|
||||||
|
+ * (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
+ / (aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa)
|
||||||
|
+)
|
||||||
|
aaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaa
|
||||||
|
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+(
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ >> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+)
|
||||||
|
bbbb >> bbbb * bbbb
|
||||||
|
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+(
|
||||||
|
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+ ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
+)
|
||||||
|
last_call()
|
||||||
|
# standalone comment at ENDMARKER
|
12
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py
vendored
Normal file
12
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# We should not treat the trailing comma
|
||||||
|
# in a single-element subscript.
|
||||||
|
a: tuple[int,]
|
||||||
|
b = tuple[int,]
|
||||||
|
|
||||||
|
# The magic comma still applies to multi-element subscripts.
|
||||||
|
c: tuple[int, int,]
|
||||||
|
d = tuple[int, int,]
|
||||||
|
|
||||||
|
# Magic commas still work as expected for non-subscripts.
|
||||||
|
small_list = [1,]
|
||||||
|
list_of_types = [tuple[int,],]
|
|
@ -0,0 +1,12 @@
|
||||||
|
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source.
|
||||||
|
|
||||||
|
# Left hand side fits in a single line but will still be exploded by the
|
||||||
|
# magic trailing comma.
|
||||||
|
first_value, (m1, m2,), third_value = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
|
||||||
|
arg1,
|
||||||
|
arg2,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make when when the left side of assignment plus the opening paren "... = (" is
|
||||||
|
# exactly line length limit + 1, it won't be split like that.
|
||||||
|
xxxxxxxxx_yyy_zzzzzzzz[xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)] = 1
|
81
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py
vendored
Normal file
81
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py
vendored
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
# Control example
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
# Remove brackets for short coroutine/task
|
||||||
|
async def main():
|
||||||
|
await (asyncio.sleep(1))
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (
|
||||||
|
asyncio.sleep(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (asyncio.sleep(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check comments
|
||||||
|
async def main():
|
||||||
|
await ( # Hello
|
||||||
|
asyncio.sleep(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (
|
||||||
|
asyncio.sleep(1) # Hello
|
||||||
|
)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (
|
||||||
|
asyncio.sleep(1)
|
||||||
|
) # Hello
|
||||||
|
|
||||||
|
# Long lines
|
||||||
|
async def main():
|
||||||
|
await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1))
|
||||||
|
|
||||||
|
# Same as above but with magic trailing comma in function
|
||||||
|
async def main():
|
||||||
|
await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1), asyncio.sleep(1),)
|
||||||
|
|
||||||
|
# Cr@zY Br@ck3Tz
|
||||||
|
async def main():
|
||||||
|
await (
|
||||||
|
(((((((((((((
|
||||||
|
((( (((
|
||||||
|
((( (((
|
||||||
|
((( (((
|
||||||
|
((( (((
|
||||||
|
((black(1)))
|
||||||
|
))) )))
|
||||||
|
))) )))
|
||||||
|
))) )))
|
||||||
|
))) )))
|
||||||
|
)))))))))))))
|
||||||
|
)
|
||||||
|
|
||||||
|
# Keep brackets around non power operations and nested awaits
|
||||||
|
async def main():
|
||||||
|
await (set_of_tasks | other_set)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await asyncio.sleep(1))
|
||||||
|
|
||||||
|
# It's awaits all the way down...
|
||||||
|
async def main():
|
||||||
|
await (await x)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (yield x)
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await (asyncio.sleep(1)))
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await (await (await (await (asyncio.sleep(1))))))
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (yield)
|
35
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py
vendored
Normal file
35
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# These brackets are redundant, therefore remove.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (AttributeError) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# This is tuple of exceptions.
|
||||||
|
# Although this could be replaced with just the exception,
|
||||||
|
# we do not remove brackets to preserve AST.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (AttributeError,) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# This is a tuple of exceptions. Do not remove brackets.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (AttributeError, ValueError) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# Test long variants.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
|
||||||
|
raise err
|
19
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py
vendored
Normal file
19
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Only remove tuple brackets after `for`
|
||||||
|
for (k, v) in d.items():
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
# Don't touch tuple brackets after `in`
|
||||||
|
for module in (core, _unicodefun):
|
||||||
|
if hasattr(module, "_verify_python3_env"):
|
||||||
|
module._verify_python3_env = lambda: None
|
||||||
|
|
||||||
|
# Brackets remain for long for loop lines
|
||||||
|
for (why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long, i_dont_know_but_we_should_still_check_the_behaviour_if_they_do) in d.items():
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items():
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
# Test deeply nested brackets
|
||||||
|
for (((((k, v))))) in d.items():
|
||||||
|
print(k, v)
|
|
@ -0,0 +1,108 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
def foo1():
|
||||||
|
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo2():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("All the newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo3():
|
||||||
|
|
||||||
|
print("No newline above me!")
|
||||||
|
|
||||||
|
print("There is a newline above me, and that's OK!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo4():
|
||||||
|
|
||||||
|
# There is a comment here
|
||||||
|
|
||||||
|
print("The newline above me should not be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
def bar(self):
|
||||||
|
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
|
||||||
|
print(f"{i}) The line above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print(f"{i}) The lines above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
|
||||||
|
for j in range(7):
|
||||||
|
|
||||||
|
print(f"{i}) The lines above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
|
||||||
|
print("The new line above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("The new lines above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
if random.uniform(0, 1) > 0.5:
|
||||||
|
print("Two lines above me are about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print("The newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
while False:
|
||||||
|
|
||||||
|
print("The newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="w") as file:
|
||||||
|
|
||||||
|
file.write("The new line above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="w") as file:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
file.write("The new lines above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="r") as read_file:
|
||||||
|
|
||||||
|
with open("/path/to/output_file.txt", mode="w") as write_file:
|
||||||
|
|
||||||
|
write_file.writelines(read_file.readlines())
|
|
@ -0,0 +1,88 @@
|
||||||
|
# Control
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
# Remove the brackets
|
||||||
|
def double(a: int) -> (int):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
# Some newline variations
|
||||||
|
def double(a: int) -> (
|
||||||
|
int):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
def double(a: int) -> (int
|
||||||
|
):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
def double(a: int) -> (
|
||||||
|
int
|
||||||
|
):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
# Don't lose the comments
|
||||||
|
def double(a: int) -> ( # Hello
|
||||||
|
int
|
||||||
|
):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
def double(a: int) -> (
|
||||||
|
int # Hello
|
||||||
|
):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
# Really long annotations
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def foo() -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def foo(a: int, b: int, c: int,) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds | intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# Split args but no need to split return
|
||||||
|
def foo(a: int, b: int, c: int,) -> int:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# Deeply nested brackets
|
||||||
|
# with *interesting* spacing
|
||||||
|
def double(a: int) -> (((((int))))):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
def double(a: int) -> (
|
||||||
|
( (
|
||||||
|
((int)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
):
|
||||||
|
return 2*a
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
( (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
)
|
||||||
|
)):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# Return type with commas
|
||||||
|
def foo() -> (
|
||||||
|
tuple[int, int, int]
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong]:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
# Magic trailing comma example
|
||||||
|
def foo() -> tuple[int, int, int,]:
|
||||||
|
return 2
|
|
@ -0,0 +1,47 @@
|
||||||
|
# We should not remove the trailing comma in a single-element subscript.
|
||||||
|
a: tuple[int,]
|
||||||
|
b = tuple[int,]
|
||||||
|
|
||||||
|
# But commas in multiple element subscripts should be removed.
|
||||||
|
c: tuple[int, int,]
|
||||||
|
d = tuple[int, int,]
|
||||||
|
|
||||||
|
# Remove commas for non-subscripts.
|
||||||
|
small_list = [1,]
|
||||||
|
list_of_types = [tuple[int,],]
|
||||||
|
small_set = {1,}
|
||||||
|
set_of_types = {tuple[int,],}
|
||||||
|
|
||||||
|
# Except single element tuples
|
||||||
|
small_tuple = (1,)
|
||||||
|
|
||||||
|
# Trailing commas in multiple chained non-nested parens.
|
||||||
|
zero(
|
||||||
|
one,
|
||||||
|
).two(
|
||||||
|
three,
|
||||||
|
).four(
|
||||||
|
five,
|
||||||
|
)
|
||||||
|
|
||||||
|
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||||
|
|
||||||
|
(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
) = func1(
|
||||||
|
arg1
|
||||||
|
) and func2(arg2)
|
||||||
|
|
||||||
|
func(
|
||||||
|
argument1,
|
||||||
|
(
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
),
|
||||||
|
argument4,
|
||||||
|
argument5,
|
||||||
|
argument6,
|
||||||
|
)
|
|
@ -0,0 +1,33 @@
|
||||||
|
zero(one,).two(three,).four(five,)
|
||||||
|
|
||||||
|
func1(arg1).func2(arg2,).func3(arg3).func4(arg4,).func5(arg5)
|
||||||
|
|
||||||
|
# Inner one-element tuple shouldn't explode
|
||||||
|
func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
|
||||||
|
|
||||||
|
(a, b, c, d,) = func1(arg1) and func2(arg2)
|
||||||
|
|
||||||
|
|
||||||
|
# Example from https://github.com/psf/black/issues/3229
|
||||||
|
def refresh_token(self, device_family, refresh_token, api_key):
|
||||||
|
return self.orchestration.refresh_token(
|
||||||
|
data={
|
||||||
|
"refreshToken": refresh_token,
|
||||||
|
},
|
||||||
|
api_key=api_key,
|
||||||
|
)["extensions"]["sdk"]["token"]
|
||||||
|
|
||||||
|
|
||||||
|
# Edge case where a bug in a working-in-progress version of
|
||||||
|
# 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)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3414.
|
||||||
|
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||||
|
xxxxxxxxx
|
||||||
|
).xxxxxxxxxxxxxxxxxx(), (
|
||||||
|
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
)
|
1
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/whitespace.py
vendored
Normal file
1
crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/whitespace.py
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -3,13 +3,10 @@ source: src/source_code/mod.rs
|
||||||
assertion_line: 0
|
assertion_line: 0
|
||||||
expression: formatted
|
expression: formatted
|
||||||
---
|
---
|
||||||
def bob(): \
|
def bob(): # pylint: disable=W9016
|
||||||
# pylint: disable=W9016
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def bobtwo(): \
|
def bobtwo(): # some comment here
|
||||||
\
|
|
||||||
# some comment here
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ else:
|
||||||
add_compiler(compilers[(7.0, 32)])
|
add_compiler(compilers[(7.0, 32)])
|
||||||
# add_compiler(compilers[(7.1, 64)])
|
# add_compiler(compilers[(7.1, 64)])
|
||||||
|
|
||||||
|
|
||||||
# Comment before function.
|
# Comment before function.
|
||||||
def inline_comments_in_brackets_ruin_everything():
|
def inline_comments_in_brackets_ruin_everything():
|
||||||
if typedargslist:
|
if typedargslist:
|
||||||
|
|
|
@ -5,6 +5,7 @@ expression: formatted
|
||||||
---
|
---
|
||||||
# The percent-percent comments are Spyder IDE cells.
|
# The percent-percent comments are Spyder IDE cells.
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
def func():
|
def func():
|
||||||
x = """
|
x = """
|
||||||
|
|
|
@ -67,6 +67,8 @@ def decorated1():
|
||||||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||||
# In the current style, the user will have to split those lines by hand.
|
# In the current style, the user will have to split those lines by hand.
|
||||||
some_instruction
|
some_instruction
|
||||||
|
|
||||||
|
|
||||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||||
def g():
|
def g():
|
||||||
...
|
...
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# The percent-percent comments are Spyder IDE cells.
|
||||||
|
# Both `#%%`` and `# %%` are accepted, so `black` standardises
|
||||||
|
# to the latter.
|
||||||
|
|
||||||
|
# %%
|
||||||
|
# %%
|
||||||
|
|
|
@ -0,0 +1,167 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# Test for https://github.com/psf/black/issues/246.
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# This multiline comments section
|
||||||
|
# should be split from the statement
|
||||||
|
# above by two lines.
|
||||||
|
def function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
async def async_function():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# This comment should be split from the statement above by two lines.
|
||||||
|
class MyClass:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
# This should be stick to the statement above
|
||||||
|
|
||||||
|
|
||||||
|
# This should be split from the above by two lines
|
||||||
|
class MyClassWithComplexLeadingComments:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ClassWithDocstring:
|
||||||
|
"""A docstring."""
|
||||||
|
|
||||||
|
|
||||||
|
# Leading comment after a class with just a docstring
|
||||||
|
class MyClassAfterAnotherClassWithDocstring:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
# leading 2 extra
|
||||||
|
@deco2(with_args=True)
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@deco2(with_args=True)
|
||||||
|
|
||||||
|
# leading 3 that already has an empty line
|
||||||
|
@deco3
|
||||||
|
# leading 4
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
some = statement
|
||||||
|
|
||||||
|
|
||||||
|
# leading 1
|
||||||
|
@deco1
|
||||||
|
# leading 2
|
||||||
|
@deco2(with_args=True)
|
||||||
|
# leading 3
|
||||||
|
@deco3
|
||||||
|
|
||||||
|
# leading 4 that already has an empty line
|
||||||
|
def decorated_with_split_leading_comments():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if a:
|
||||||
|
# Leading comment before inline function
|
||||||
|
def inline():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Another leading comment
|
||||||
|
def another_inline():
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
# More leading comments
|
||||||
|
def inline_after_else():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if a:
|
||||||
|
# Leading comment before "top-level inline" function
|
||||||
|
def top_level_quote_inline():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Another leading comment
|
||||||
|
def another_top_level_quote_inline_inline():
|
||||||
|
pass
|
||||||
|
|
||||||
|
else:
|
||||||
|
# More leading comments
|
||||||
|
def top_level_quote_inline_after_else():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MyClass:
|
||||||
|
# First method has no empty lines between bare class def.
|
||||||
|
# More comments.
|
||||||
|
def first_method(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
@decorator2 # fmt: skip
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function.
|
||||||
|
# NOTE this comment only has one empty line below, and the formatter
|
||||||
|
# should enforce two blank lines.
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
# A standalone comment
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
def docstring_almost_at_line_limit():
|
||||||
|
"""long docstring................................................................."""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_almost_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring................................................................"""
|
||||||
|
|
||||||
|
|
||||||
|
def mulitline_docstring_almost_at_line_limit():
|
||||||
|
"""long docstring.................................................................
|
||||||
|
|
||||||
|
..................................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def mulitline_docstring_almost_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring................................................................
|
||||||
|
|
||||||
|
..................................................................................
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_at_line_limit():
|
||||||
|
"""long docstring................................................................"""
|
||||||
|
|
||||||
|
|
||||||
|
def docstring_at_line_limit_with_prefix():
|
||||||
|
f"""long docstring..............................................................."""
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_docstring_at_line_limit():
|
||||||
|
"""first line-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
second line----------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
|
||||||
|
def multiline_docstring_at_line_limit_with_prefix():
|
||||||
|
f"""first line----------------------------------------------------------------------
|
||||||
|
|
||||||
|
second line----------------------------------------------------------------------"""
|
||||||
|
|
||||||
|
|
||||||
|
def single_quote_docstring_over_line_limit():
|
||||||
|
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||||
|
|
||||||
|
|
||||||
|
def single_quote_docstring_over_line_limit2():
|
||||||
|
"We do not want to put the closing quote on a new line as that is invalid (see GH-3141)."
|
||||||
|
|
|
@ -8,9 +8,9 @@ expression: formatted
|
||||||
|
|
||||||
# leading comment
|
# leading comment
|
||||||
def f():
|
def f():
|
||||||
NO = ''
|
NO = ""
|
||||||
SPACE = ' '
|
SPACE = " "
|
||||||
DOUBLESPACE = ' '
|
DOUBLESPACE = " "
|
||||||
|
|
||||||
t = leaf.type
|
t = leaf.type
|
||||||
p = leaf.parent # trailing comment
|
p = leaf.parent # trailing comment
|
||||||
|
@ -21,19 +21,14 @@ def f():
|
||||||
if t == token.COMMENT: # another trailing comment
|
if t == token.COMMENT: # another trailing comment
|
||||||
return DOUBLESPACE
|
return DOUBLESPACE
|
||||||
|
|
||||||
|
|
||||||
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||||
|
|
||||||
|
|
||||||
prev = leaf.prev_sibling
|
prev = leaf.prev_sibling
|
||||||
if not prev:
|
if not prev:
|
||||||
prevp = preceding_leaf(p)
|
prevp = preceding_leaf(p)
|
||||||
if not prevp or prevp.type in OPENING_BRACKETS:
|
if not prevp or prevp.type in OPENING_BRACKETS:
|
||||||
|
|
||||||
|
|
||||||
return NO
|
return NO
|
||||||
|
|
||||||
|
|
||||||
if prevp.type == token.EQUAL:
|
if prevp.type == token.EQUAL:
|
||||||
if prevp.parent and prevp.parent.type in {
|
if prevp.parent and prevp.parent.type in {
|
||||||
syms.typedargslist,
|
syms.typedargslist,
|
||||||
|
@ -54,14 +49,16 @@ def f():
|
||||||
}:
|
}:
|
||||||
return NO
|
return NO
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# SECTION BECAUSE SECTIONS
|
# SECTION BECAUSE SECTIONS
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
def g():
|
def g():
|
||||||
NO = ''
|
NO = ""
|
||||||
SPACE = ' '
|
SPACE = " "
|
||||||
DOUBLESPACE = ' '
|
DOUBLESPACE = " "
|
||||||
|
|
||||||
t = leaf.type
|
t = leaf.type
|
||||||
p = leaf.parent
|
p = leaf.parent
|
||||||
|
@ -75,7 +72,7 @@ def g():
|
||||||
return DOUBLESPACE
|
return DOUBLESPACE
|
||||||
|
|
||||||
# Another comment because more comments
|
# Another comment because more comments
|
||||||
assert p is not None, f'INTERNAL ERROR: hand-made leaf without parent: {leaf!r}'
|
assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
|
||||||
|
|
||||||
prev = leaf.prev_sibling
|
prev = leaf.prev_sibling
|
||||||
if not prev:
|
if not prev:
|
||||||
|
|
|
@ -4,8 +4,8 @@ assertion_line: 0
|
||||||
expression: formatted
|
expression: formatted
|
||||||
---
|
---
|
||||||
...
|
...
|
||||||
'some_string'
|
"some_string"
|
||||||
b'\\xa3'
|
b"\\xa3"
|
||||||
Name
|
Name
|
||||||
None
|
None
|
||||||
True
|
True
|
||||||
|
@ -36,75 +36,111 @@ not great
|
||||||
-1
|
-1
|
||||||
~int and not v1 ^ 123 + v2 | True
|
~int and not v1 ^ 123 + v2 | True
|
||||||
(~int) and (not ((v1 ^ (123 + v2)) | True))
|
(~int) and (not ((v1 ^ (123 + v2)) | True))
|
||||||
+really ** -confusing ** ~operator ** -precedence
|
+(really ** -(confusing ** ~(operator**-precedence)))
|
||||||
flags & ~select.EPOLLIN and waiters.write_task is not None
|
flags & ~select.EPOLLIN and waiters.write_task is not None
|
||||||
lambda arg: None
|
lambda arg: None
|
||||||
lambda a=True: a
|
lambda a=True: a
|
||||||
lambda a, b, c=True: a
|
lambda a, b, c=True: a
|
||||||
lambda a, b, c=True, *, d=(1 << v2), e='str': a
|
lambda a, b, c=True, *, d=(1 << v2), e="str": a
|
||||||
lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
|
lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
|
||||||
manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
|
manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
|
||||||
foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
|
foo = lambda port_id, ignore_missing: {
|
||||||
|
"port1": port1_resource,
|
||||||
|
"port2": port2_resource,
|
||||||
|
}[port_id]
|
||||||
1 if True else 2
|
1 if True else 2
|
||||||
str or None if True else str or bytes or None
|
str or None if True else str or bytes or None
|
||||||
(str or None) if True else (str or bytes or None)
|
(str or None) if True else (str or bytes or None)
|
||||||
str or None if (1 if True else 2) else str or bytes or None
|
str or None if (1 if True else 2) else str or bytes or None
|
||||||
(str or None) if (1 if True else 2) else (str or bytes or None)
|
(str or None) if (1 if True else 2) else (str or bytes or None)
|
||||||
((super_long_variable_name or None) if (1 if super_long_test_name else 2) else (str or bytes or None))
|
(
|
||||||
{'2.7': dead, '3.7': (long_live or die_hard)}
|
(super_long_variable_name or None)
|
||||||
{'2.7': dead, '3.7': (long_live or die_hard), **{'3.6': verygood}}
|
if (1 if super_long_test_name else 2)
|
||||||
|
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), **{"3.6": verygood}}
|
||||||
{**a, **b, **c}
|
{**a, **b, **c}
|
||||||
{'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')}
|
{"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
|
||||||
({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None
|
({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
|
||||||
()
|
()
|
||||||
(1,)
|
(1,)
|
||||||
(1, 2)
|
(1, 2)
|
||||||
(1, 2, 3)
|
(1, 2, 3)
|
||||||
[]
|
[]
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
|
||||||
[1, 2, 3,]
|
[
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
]
|
||||||
[*a]
|
[*a]
|
||||||
[*range(10)]
|
[*range(10)]
|
||||||
[*a, 4, 5,]
|
[
|
||||||
[4, *a, 5,]
|
*a,
|
||||||
[this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, another, *more]
|
4,
|
||||||
|
5,
|
||||||
|
]
|
||||||
|
[
|
||||||
|
4,
|
||||||
|
*a,
|
||||||
|
5,
|
||||||
|
]
|
||||||
|
[
|
||||||
|
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
||||||
|
element,
|
||||||
|
another,
|
||||||
|
*more,
|
||||||
|
]
|
||||||
{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)}
|
||||||
{(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)}
|
||||||
[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)]
|
||||||
[(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)]
|
||||||
{i: 0 for i in (1, 2, 3)}
|
{i: 0 for i in (1, 2, 3)}
|
||||||
{i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
|
{i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
|
||||||
{a: b * 2 for a, b in dictionary.items()}
|
{a: b * 2 for a, b in dictionary.items()}
|
||||||
{a: b * -2 for a, b in dictionary.items()}
|
{a: b * -2 for a, b in dictionary.items()}
|
||||||
{k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension}
|
{
|
||||||
|
k: v
|
||||||
|
for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
|
||||||
|
}
|
||||||
Python3 > Python2 > COBOL
|
Python3 > Python2 > COBOL
|
||||||
Life is Life
|
Life is Life
|
||||||
call()
|
call()
|
||||||
call(arg)
|
call(arg)
|
||||||
call(kwarg='hey')
|
call(kwarg="hey")
|
||||||
call(arg, kwarg='hey')
|
call(arg, kwarg="hey")
|
||||||
call(arg, another, kwarg='hey', **kwargs)
|
call(arg, another, kwarg="hey", **kwargs)
|
||||||
call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs) # note: no trailing comma pre-3.6
|
call(
|
||||||
|
this_is_a_very_long_variable_which_will_force_a_delimiter_split,
|
||||||
|
arg,
|
||||||
|
another,
|
||||||
|
kwarg="hey",
|
||||||
|
**kwargs
|
||||||
|
) # note: no trailing comma pre-3.6
|
||||||
call(*gidgets[:2])
|
call(*gidgets[:2])
|
||||||
call(a, *gidgets[:2])
|
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
|
||||||
call.me(maybe)
|
call.me(maybe)
|
||||||
1 .real
|
(1).real
|
||||||
1.0 .real
|
(1.0).real
|
||||||
....__class__
|
....__class__
|
||||||
list[str]
|
list[str]
|
||||||
dict[str, int]
|
dict[str, int]
|
||||||
tuple[str, ...]
|
tuple[str, ...]
|
||||||
|
tuple[str, int, float, dict[str, int]]
|
||||||
tuple[
|
tuple[
|
||||||
str, int, float, dict[str, int]
|
str,
|
||||||
|
int,
|
||||||
|
float,
|
||||||
|
dict[str, int],
|
||||||
]
|
]
|
||||||
tuple[str, int, float, dict[str, int],]
|
|
||||||
very_long_variable_name_filters: t.List[
|
very_long_variable_name_filters: t.List[
|
||||||
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
|
||||||
]
|
]
|
||||||
|
@ -114,9 +150,9 @@ xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: igno
|
||||||
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
|
xxxx_xxx_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__)
|
||||||
)
|
)
|
||||||
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[
|
xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
|
||||||
..., List[SomeClass]
|
sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
|
||||||
] = classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
|
) # type: ignore
|
||||||
slice[0]
|
slice[0]
|
||||||
slice[0:1]
|
slice[0:1]
|
||||||
slice[0:1:2]
|
slice[0:1:2]
|
||||||
|
@ -144,29 +180,57 @@ numpy[:, l[-2]]
|
||||||
numpy[:, ::-1]
|
numpy[:, ::-1]
|
||||||
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}
|
||||||
{'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}
|
{"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
|
||||||
(SomeName)
|
(SomeName)
|
||||||
SomeName
|
SomeName
|
||||||
(Good, Bad, Ugly)
|
(Good, Bad, Ugly)
|
||||||
(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))
|
||||||
((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,)
|
(*starred,)
|
||||||
{"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs}
|
{
|
||||||
|
"id": "1",
|
||||||
|
"type": "type",
|
||||||
|
"started_at": now(),
|
||||||
|
"ended_at": now() + timedelta(days=10),
|
||||||
|
"priority": 1,
|
||||||
|
"import_session_id": 1,
|
||||||
|
**kwargs,
|
||||||
|
}
|
||||||
a = (1,)
|
a = (1,)
|
||||||
b = 1,
|
b = (1,)
|
||||||
c = 1
|
c = 1
|
||||||
d = (1,) + a + (2,)
|
d = (1,) + a + (2,)
|
||||||
e = (1,).count(1)
|
e = (1,).count(1)
|
||||||
f = 1, *range(10)
|
f = 1, *range(10)
|
||||||
g = 1, *"ten"
|
g = 1, *"ten"
|
||||||
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
|
||||||
result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc()).all()
|
)
|
||||||
result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all()
|
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
|
||||||
|
vars_to_remove
|
||||||
|
)
|
||||||
|
result = (
|
||||||
|
session.query(models.Customer.id)
|
||||||
|
.filter(
|
||||||
|
models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
|
)
|
||||||
|
.order_by(models.Customer.id.asc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
result = (
|
||||||
|
session.query(models.Customer.id)
|
||||||
|
.filter(
|
||||||
|
models.Customer.account_id == account_id, models.Customer.email == email_address
|
||||||
|
)
|
||||||
|
.order_by(
|
||||||
|
models.Customer.id.asc(),
|
||||||
|
)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
Ø = set()
|
Ø = set()
|
||||||
authors.łukasz.say_thanks()
|
authors.łukasz.say_thanks()
|
||||||
mapping = {
|
mapping = {
|
||||||
|
@ -176,85 +240,138 @@ mapping = {
|
||||||
D: 0.1 * (10.0 / 12),
|
D: 0.1 * (10.0 / 12),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def gen():
|
def gen():
|
||||||
yield from outside_of_generator
|
yield from outside_of_generator
|
||||||
a = (yield)
|
a = yield
|
||||||
b = ((yield))
|
b = yield
|
||||||
c = (((yield)))
|
c = yield
|
||||||
|
|
||||||
|
|
||||||
async def f():
|
async def f():
|
||||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||||
|
|
||||||
|
|
||||||
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"
|
||||||
assert this is ComplexTest and not requirements.fit_in_a_single_line(force=False), "Short message"
|
assert this is ComplexTest and not requirements.fit_in_a_single_line(
|
||||||
assert(((parens is TooMany)))
|
force=False
|
||||||
for x, in (1,), (2,), (3,): ...
|
), "Short message"
|
||||||
for y in (): ...
|
assert parens is TooMany
|
||||||
for z in (i for i in (1, 2, 3)): ...
|
for (x,) in (1,), (2,), (3,):
|
||||||
for i in (call()): ...
|
...
|
||||||
for j in (1 + (2 + 3)): ...
|
for y in ():
|
||||||
while(this and that): ...
|
...
|
||||||
for addr_family, addr_type, addr_proto, addr_canonname, addr_sockaddr in socket.getaddrinfo('google.com', 'http'):
|
for z in (i for i in (1, 2, 3)):
|
||||||
|
...
|
||||||
|
for i in call():
|
||||||
|
...
|
||||||
|
for j in 1 + (2 + 3):
|
||||||
|
...
|
||||||
|
while this and that:
|
||||||
|
...
|
||||||
|
for (
|
||||||
|
addr_family,
|
||||||
|
addr_type,
|
||||||
|
addr_proto,
|
||||||
|
addr_canonname,
|
||||||
|
addr_sockaddr,
|
||||||
|
) in socket.getaddrinfo("google.com", "http"):
|
||||||
pass
|
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
|
a = (
|
||||||
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
|
aaaa.bbbb.cccc.dddd.eeee.ffff.gggg.hhhh.iiii.jjjj.kkkk.llll.mmmm.nnnn.oooo.pppp
|
||||||
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
|
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 not 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
|
||||||
|
)
|
||||||
|
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
|
||||||
|
)
|
||||||
|
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
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
threading.current_thread() != threading.main_thread() and
|
threading.current_thread() != threading.main_thread()
|
||||||
threading.current_thread() != threading.main_thread() or
|
and threading.current_thread() != threading.main_thread()
|
||||||
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.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l ** aaaa.m // aaaa.n
|
~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
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
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.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
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
if (
|
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.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
|
||||||
):
|
):
|
||||||
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 ^bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
(
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
)
|
||||||
last_call()
|
last_call()
|
||||||
# standalone comment at ENDMARKER
|
# standalone comment at ENDMARKER
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ f"trigger 3.6 mode"
|
||||||
|
|
||||||
# Comment 2
|
# Comment 2
|
||||||
|
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
def func_no_args():
|
def func_no_args():
|
||||||
a; b; c
|
a; b; c
|
||||||
|
|
|
@ -9,52 +9,97 @@ import sys
|
||||||
|
|
||||||
from third_party import X, Y, Z
|
from third_party import X, Y, Z
|
||||||
|
|
||||||
from library import some_connection, \
|
from library import some_connection, some_decorator
|
||||||
some_decorator
|
|
||||||
f'trigger 3.6 mode'
|
f"trigger 3.6 mode"
|
||||||
|
|
||||||
|
|
||||||
def func_no_args():
|
def func_no_args():
|
||||||
a; b; c
|
a
|
||||||
if True: raise RuntimeError
|
b
|
||||||
if False: ...
|
c
|
||||||
|
if True:
|
||||||
|
raise RuntimeError
|
||||||
|
if False:
|
||||||
|
...
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
print(i)
|
print(i)
|
||||||
continue
|
continue
|
||||||
exec("new-style exec", {}, {})
|
exec("new-style exec", {}, {})
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def coroutine(arg, exec=False):
|
async def coroutine(arg, exec=False):
|
||||||
"Single-line docstring. Multiline is harder to reformat."
|
"Single-line docstring. Multiline is harder to reformat."
|
||||||
async with some_connection() as conn:
|
async with some_connection() as conn:
|
||||||
await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@some_decorator(
|
@some_decorator(with_args=True, many_args=[1, 2, 3])
|
||||||
with_args=True,
|
def function_signature_stress_test(
|
||||||
many_args=[1,2,3]
|
number: int,
|
||||||
)
|
no_annotation=None,
|
||||||
def function_signature_stress_test(number:int,no_annotation=None,text:str="default",* ,debug:bool=False,**kwargs) -> str:
|
text: str = "default",
|
||||||
|
*,
|
||||||
|
debug: bool = False,
|
||||||
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
return text[number:-1]
|
return text[number:-1]
|
||||||
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
|
|
||||||
|
|
||||||
|
def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
|
||||||
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
|
||||||
assert task._cancel_stack[: len(old_stack)] == old_stack
|
assert task._cancel_stack[: len(old_stack)] == old_stack
|
||||||
def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
|
|
||||||
|
|
||||||
|
def spaces_types(
|
||||||
|
a: int = 1,
|
||||||
|
b: tuple = (),
|
||||||
|
c: list = [],
|
||||||
|
d: dict = {},
|
||||||
|
e: bool = True,
|
||||||
|
f: int = -1,
|
||||||
|
g: int = 1 if False else 2,
|
||||||
|
h: str = "",
|
||||||
|
i: str = r"",
|
||||||
|
):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
def spaces2(result=_core.Value(None)):
|
def spaces2(result=_core.Value(None)):
|
||||||
assert fut is self._read_fut, (fut, self._read_fut)
|
assert fut is self._read_fut, (fut, self._read_fut)
|
||||||
|
|
||||||
|
|
||||||
def example(session):
|
def example(session):
|
||||||
result = session.query(models.Customer.id).filter(
|
result = (
|
||||||
|
session.query(models.Customer.id)
|
||||||
|
.filter(
|
||||||
models.Customer.account_id == account_id,
|
models.Customer.account_id == account_id,
|
||||||
models.Customer.email == email_address,
|
models.Customer.email == email_address,
|
||||||
).order_by(
|
)
|
||||||
models.Customer.id.asc()
|
.order_by(models.Customer.id.asc())
|
||||||
).all()
|
.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def long_lines():
|
def long_lines():
|
||||||
if True:
|
if True:
|
||||||
typedargslist.extend(
|
typedargslist.extend(
|
||||||
gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
|
gen_annotated_params(
|
||||||
|
ast_args.kwonlyargs,
|
||||||
|
ast_args.kw_defaults,
|
||||||
|
parameters,
|
||||||
|
implicit_default=True,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
typedargslist.extend(
|
typedargslist.extend(
|
||||||
gen_annotated_params(
|
gen_annotated_params(
|
||||||
ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True,
|
ast_args.kwonlyargs,
|
||||||
|
ast_args.kw_defaults,
|
||||||
|
parameters,
|
||||||
|
implicit_default=True,
|
||||||
# trailing standalone comment
|
# trailing standalone comment
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -77,8 +122,11 @@ def long_lines():
|
||||||
\n?
|
\n?
|
||||||
)
|
)
|
||||||
$
|
$
|
||||||
""", re.MULTILINE | re.VERBOSE
|
""",
|
||||||
|
re.MULTILINE | re.VERBOSE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def trailing_comma():
|
def trailing_comma():
|
||||||
mapping = {
|
mapping = {
|
||||||
A: 0.25 * (10.0 / 12),
|
A: 0.25 * (10.0 / 12),
|
||||||
|
@ -86,6 +134,8 @@ def trailing_comma():
|
||||||
C: 0.1 * (10.0 / 12),
|
C: 0.1 * (10.0 / 12),
|
||||||
D: 0.1 * (10.0 / 12),
|
D: 0.1 * (10.0 / 12),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def f(
|
def f(
|
||||||
a,
|
a,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
@ -97,5 +147,8 @@ def f(
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
def __await__(): return (yield)
|
|
||||||
|
|
||||||
|
def __await__():
|
||||||
|
return (yield)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ def f(
|
||||||
) -> A:
|
) -> A:
|
||||||
with cache_dir():
|
with cache_dir():
|
||||||
if something:
|
if something:
|
||||||
result = (
|
result = CliRunner().invoke(
|
||||||
CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"])
|
black.main, [str(src1), str(src2), "--diff", "--check"]
|
||||||
)
|
)
|
||||||
limited.append(-limited.pop()) # negate top
|
limited.append(-limited.pop()) # negate top
|
||||||
return A(
|
return A(
|
||||||
|
@ -18,24 +18,34 @@ def f(
|
||||||
very_long_argument_name2=-very.long.value.for_the_argument,
|
very_long_argument_name2=-very.long.value.for_the_argument,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def g():
|
def g():
|
||||||
"Docstring."
|
"Docstring."
|
||||||
|
|
||||||
def inner():
|
def inner():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("Inner defs should breathe a little.")
|
print("Inner defs should breathe a little.")
|
||||||
|
|
||||||
|
|
||||||
def h():
|
def h():
|
||||||
def inner():
|
def inner():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("Inner defs should breathe a little.")
|
print("Inner defs should breathe a little.")
|
||||||
|
|
||||||
|
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
def i_should_be_followed_by_only_one_newline():
|
def i_should_be_followed_by_only_one_newline():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
try:
|
try:
|
||||||
import msvcrt
|
import msvcrt
|
||||||
|
|
||||||
def i_should_be_followed_by_only_one_newline():
|
def i_should_be_followed_by_only_one_newline():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -49,11 +59,13 @@ elif False:
|
||||||
class IHopeYouAreHavingALovelyDay:
|
class IHopeYouAreHavingALovelyDay:
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
print("i_should_be_followed_by_only_one_newline")
|
print("i_should_be_followed_by_only_one_newline")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
with hmm_but_this_should_get_two_preceding_newlines():
|
with hmm_but_this_should_get_two_preceding_newlines():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -3,29 +3,72 @@ source: src/source_code/mod.rs
|
||||||
assertion_line: 0
|
assertion_line: 0
|
||||||
expression: formatted
|
expression: formatted
|
||||||
---
|
---
|
||||||
def f(a,):
|
def f(
|
||||||
d = {'key': 'value',}
|
a,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
}
|
||||||
tup = (1,)
|
tup = (1,)
|
||||||
|
|
||||||
def f2(a,b,):
|
|
||||||
d = {'key': 'value', 'key2': 'value2',}
|
|
||||||
tup = (1,2,)
|
|
||||||
|
|
||||||
def f(a:int=1,):
|
def f2(
|
||||||
call(arg={'explode': 'this',})
|
a,
|
||||||
call2(arg=[1,2,3],)
|
b,
|
||||||
|
):
|
||||||
|
d = {
|
||||||
|
"key": "value",
|
||||||
|
"key2": "value2",
|
||||||
|
}
|
||||||
|
tup = (
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def f(
|
||||||
|
a: int = 1,
|
||||||
|
):
|
||||||
|
call(
|
||||||
|
arg={
|
||||||
|
"explode": "this",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
call2(
|
||||||
|
arg=[1, 2, 3],
|
||||||
|
)
|
||||||
x = {
|
x = {
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"b": 2,
|
"b": 2,
|
||||||
}["a"]
|
}["a"]
|
||||||
if a == {"a": 1,"b": 2,"c": 3,"d": 4,"e": 5,"f": 6,"g": 7,"h": 8,}["a"]:
|
if (
|
||||||
|
a
|
||||||
|
== {
|
||||||
|
"a": 1,
|
||||||
|
"b": 2,
|
||||||
|
"c": 3,
|
||||||
|
"d": 4,
|
||||||
|
"e": 5,
|
||||||
|
"f": 6,
|
||||||
|
"g": 7,
|
||||||
|
"h": 8,
|
||||||
|
}["a"]
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> Set[
|
|
||||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
||||||
]:
|
|
||||||
json = {"k": {"k2": {"k3": [1,]}}}
|
|
||||||
|
|
||||||
|
def xxxxxxxxxxxxxxxxxxxxxxxxxxxx() -> (
|
||||||
|
Set["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
|
||||||
|
):
|
||||||
|
json = {
|
||||||
|
"k": {
|
||||||
|
"k2": {
|
||||||
|
"k3": [
|
||||||
|
1,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# The type annotation shouldn't get a trailing comma since that would change its type.
|
# The type annotation shouldn't get a trailing comma since that would change its type.
|
||||||
|
@ -36,21 +79,24 @@ def some_function_with_a_really_long_name() -> (
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def some_method_with_a_really_long_name(very_long_parameter_so_yeah: str, another_long_parameter: int) -> (
|
def some_method_with_a_really_long_name(
|
||||||
another_case_of_returning_a_deeply_nested_import_of_a_type_i_suppose_cause_why_not
|
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
|
pass
|
||||||
|
|
||||||
|
|
||||||
def func() -> (
|
def func() -> (
|
||||||
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(this_shouldn_t_get_a_trailing_comma_too)
|
also_super_long_type_annotation_that_may_cause_an_AST_related_crash_in_black(
|
||||||
):
|
|
||||||
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
|
this_shouldn_t_get_a_trailing_comma_too
|
||||||
))
|
)
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -62,6 +108,13 @@ some_module.some_function(
|
||||||
|
|
||||||
# Inner trailing comma causes outer to explode
|
# Inner trailing comma causes outer to explode
|
||||||
some_module.some_function(
|
some_module.some_function(
|
||||||
argument1, (one, two,), argument4, argument5, argument6
|
argument1,
|
||||||
|
(
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
),
|
||||||
|
argument4,
|
||||||
|
argument5,
|
||||||
|
argument6,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# We should not treat the trailing comma
|
||||||
|
# in a single-element subscript.
|
||||||
|
a: tuple[int,]
|
||||||
|
b = tuple[int,]
|
||||||
|
|
||||||
|
# The magic comma still applies to multi-element subscripts.
|
||||||
|
c: tuple[
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
]
|
||||||
|
d = tuple[
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Magic commas still work as expected for non-subscripts.
|
||||||
|
small_list = [
|
||||||
|
1,
|
||||||
|
]
|
||||||
|
list_of_types = [
|
||||||
|
tuple[int,],
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# Test cases separate from `prefer_rhs_split.py` that contains unformatted source.
|
||||||
|
|
||||||
|
# Left hand side fits in a single line but will still be exploded by the
|
||||||
|
# magic trailing comma.
|
||||||
|
(
|
||||||
|
first_value,
|
||||||
|
(
|
||||||
|
m1,
|
||||||
|
m2,
|
||||||
|
),
|
||||||
|
third_value,
|
||||||
|
) = xxxxxx_yyyyyy_zzzzzz_wwwwww_uuuuuuu_vvvvvvvvvvv(
|
||||||
|
arg1,
|
||||||
|
arg2,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make when when the left side of assignment plus the opening paren "... = (" is
|
||||||
|
# exactly line length limit + 1, it won't be split like that.
|
||||||
|
xxxxxxxxx_yyy_zzzzzzzz[
|
||||||
|
xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1)
|
||||||
|
] = 1
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
# Control example
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Remove brackets for short coroutine/task
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Check comments
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1) # Hello
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1) # Hello
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await asyncio.sleep(1) # Hello
|
||||||
|
|
||||||
|
|
||||||
|
# Long lines
|
||||||
|
async def main():
|
||||||
|
await asyncio.gather(
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Same as above but with magic trailing comma in function
|
||||||
|
async def main():
|
||||||
|
await asyncio.gather(
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
asyncio.sleep(1),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Cr@zY Br@ck3Tz
|
||||||
|
async def main():
|
||||||
|
await black(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Keep brackets around non power operations and nested awaits
|
||||||
|
async def main():
|
||||||
|
await (set_of_tasks | other_set)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await asyncio.sleep(1))
|
||||||
|
|
||||||
|
|
||||||
|
# It's awaits all the way down...
|
||||||
|
async def main():
|
||||||
|
await (await x)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (yield x)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await asyncio.sleep(1))
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (await (await (await (await asyncio.sleep(1)))))
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
await (yield)
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# These brackets are redundant, therefore remove.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except AttributeError as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# This is tuple of exceptions.
|
||||||
|
# Although this could be replaced with just the exception,
|
||||||
|
# we do not remove brackets to preserve AST.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (AttributeError,) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# This is a tuple of exceptions. Do not remove brackets.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (AttributeError, ValueError) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
# Test long variants.
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (
|
||||||
|
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error
|
||||||
|
) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (
|
||||||
|
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||||
|
) as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
try:
|
||||||
|
a.something
|
||||||
|
except (
|
||||||
|
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||||
|
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
|
||||||
|
) as err:
|
||||||
|
raise err
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# Only remove tuple brackets after `for`
|
||||||
|
for k, v in d.items():
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
# Don't touch tuple brackets after `in`
|
||||||
|
for module in (core, _unicodefun):
|
||||||
|
if hasattr(module, "_verify_python3_env"):
|
||||||
|
module._verify_python3_env = lambda: None
|
||||||
|
|
||||||
|
# Brackets remain for long for loop lines
|
||||||
|
for (
|
||||||
|
why_would_anyone_choose_to_name_a_loop_variable_with_a_name_this_long,
|
||||||
|
i_dont_know_but_we_should_still_check_the_behaviour_if_they_do,
|
||||||
|
) in d.items():
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
for (
|
||||||
|
k,
|
||||||
|
v,
|
||||||
|
) in (
|
||||||
|
dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfudsofajdslkfjdslkfjldisfjdffjsdlkfjdlkjjkdflskadjldkfjsalkfjdasj.items()
|
||||||
|
):
|
||||||
|
print(k, v)
|
||||||
|
|
||||||
|
# Test deeply nested brackets
|
||||||
|
for k, v in d.items():
|
||||||
|
print(k, v)
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
def foo1():
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo2():
|
||||||
|
print("All the newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo3():
|
||||||
|
print("No newline above me!")
|
||||||
|
|
||||||
|
print("There is a newline above me, and that's OK!")
|
||||||
|
|
||||||
|
|
||||||
|
def foo4():
|
||||||
|
# There is a comment here
|
||||||
|
|
||||||
|
print("The newline above me should not be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
def bar(self):
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
print(f"{i}) The line above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
print(f"{i}) The lines above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
for j in range(7):
|
||||||
|
print(f"{i}) The lines above me should be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
print("The new line above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
print("The new lines above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
if random.randint(0, 3) == 0:
|
||||||
|
if random.uniform(0, 1) > 0.5:
|
||||||
|
print("Two lines above me are about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("The newline above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("The newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
while False:
|
||||||
|
print("The newlines above me should be deleted!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="w") as file:
|
||||||
|
file.write("The new line above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="w") as file:
|
||||||
|
file.write("The new lines above me is about to be removed!")
|
||||||
|
|
||||||
|
|
||||||
|
with open("/path/to/file.txt", mode="r") as read_file:
|
||||||
|
with open("/path/to/output_file.txt", mode="w") as write_file:
|
||||||
|
write_file.writelines(read_file.readlines())
|
||||||
|
|
|
@ -3,13 +3,14 @@ source: src/source_code/mod.rs
|
||||||
assertion_line: 0
|
assertion_line: 0
|
||||||
expression: formatted
|
expression: formatted
|
||||||
---
|
---
|
||||||
x = (1)
|
x = 1
|
||||||
x = (1.2)
|
x = 1.2
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
).encode()
|
).encode()
|
||||||
|
|
||||||
|
|
||||||
async def show_status():
|
async def show_status():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -20,42 +21,71 @@ async def show_status():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def example():
|
def example():
|
||||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
|
||||||
|
|
||||||
def example1():
|
def example1():
|
||||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
def example1point5():
|
def example1point5():
|
||||||
return ((((((1111111111111111111111111111111111111111111111111111111111111111111111111111111111111))))))
|
return 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
def example2():
|
def example2():
|
||||||
return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"))
|
return (
|
||||||
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def example3():
|
def example3():
|
||||||
return ((1111111111111111111111111111111111111111111111111111111111111111111111111111111))
|
return (
|
||||||
|
1111111111111111111111111111111111111111111111111111111111111111111111111111111
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def example4():
|
def example4():
|
||||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((True))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
return True
|
||||||
|
|
||||||
|
|
||||||
def example5():
|
def example5():
|
||||||
return ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
return ()
|
||||||
|
|
||||||
|
|
||||||
def example6():
|
def example6():
|
||||||
return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]})))))))))
|
return {a: a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]}
|
||||||
|
|
||||||
|
|
||||||
def example7():
|
def example7():
|
||||||
return ((((((((({a:a for a in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20000000000000000000]})))))))))
|
return {
|
||||||
|
a: a
|
||||||
|
for a in [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
13,
|
||||||
|
14,
|
||||||
|
15,
|
||||||
|
16,
|
||||||
|
17,
|
||||||
|
18,
|
||||||
|
19,
|
||||||
|
20000000000000000000,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def example8():
|
def example8():
|
||||||
return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
|
return None
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# Control
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
# Remove the brackets
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
# Some newline variations
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
# Don't lose the comments
|
||||||
|
def double(a: int) -> int: # Hello
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
def double(a: int) -> int: # Hello
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
# Really long annotations
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
| intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
# Split args but no need to split return
|
||||||
|
def foo(
|
||||||
|
a: int,
|
||||||
|
b: int,
|
||||||
|
c: int,
|
||||||
|
) -> int:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
# Deeply nested brackets
|
||||||
|
# with *interesting* spacing
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
def double(a: int) -> int:
|
||||||
|
return 2 * a
|
||||||
|
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
intsdfsafafafdfdsasdfsfsdfasdfafdsafdfdsfasdskdsdsfdsafdsafsdfdasfffsfdsfdsafafhdskfhdsfjdslkfdlfsdkjhsdfjkdshfkljds
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
# Return type with commas
|
||||||
|
def foo() -> tuple[int, int, int]:
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
def foo() -> (
|
||||||
|
tuple[
|
||||||
|
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||||
|
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||||
|
loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,
|
||||||
|
]
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
||||||
|
|
||||||
|
# Magic trailing comma example
|
||||||
|
def foo() -> (
|
||||||
|
tuple[
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
int,
|
||||||
|
]
|
||||||
|
):
|
||||||
|
return 2
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
# We should not remove the trailing comma in a single-element subscript.
|
||||||
|
a: tuple[int,]
|
||||||
|
b = tuple[int,]
|
||||||
|
|
||||||
|
# But commas in multiple element subscripts should be removed.
|
||||||
|
c: tuple[int, int]
|
||||||
|
d = tuple[int, int]
|
||||||
|
|
||||||
|
# Remove commas for non-subscripts.
|
||||||
|
small_list = [1]
|
||||||
|
list_of_types = [tuple[int,]]
|
||||||
|
small_set = {1}
|
||||||
|
set_of_types = {tuple[int,]}
|
||||||
|
|
||||||
|
# Except single element tuples
|
||||||
|
small_tuple = (1,)
|
||||||
|
|
||||||
|
# Trailing commas in multiple chained non-nested parens.
|
||||||
|
zero(one).two(three).four(five)
|
||||||
|
|
||||||
|
func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5)
|
||||||
|
|
||||||
|
(a, b, c, d) = func1(arg1) and func2(arg2)
|
||||||
|
|
||||||
|
func(argument1, (one, two), argument4, argument5, argument6)
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
zero(
|
||||||
|
one,
|
||||||
|
).two(
|
||||||
|
three,
|
||||||
|
).four(
|
||||||
|
five,
|
||||||
|
)
|
||||||
|
|
||||||
|
func1(arg1).func2(
|
||||||
|
arg2,
|
||||||
|
).func3(arg3).func4(
|
||||||
|
arg4,
|
||||||
|
).func5(arg5)
|
||||||
|
|
||||||
|
# Inner one-element tuple shouldn't explode
|
||||||
|
func1(arg1).func2(arg1, (one_tuple,)).func3(arg3)
|
||||||
|
|
||||||
|
(
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
c,
|
||||||
|
d,
|
||||||
|
) = func1(
|
||||||
|
arg1
|
||||||
|
) and func2(arg2)
|
||||||
|
|
||||||
|
|
||||||
|
# Example from https://github.com/psf/black/issues/3229
|
||||||
|
def refresh_token(self, device_family, refresh_token, api_key):
|
||||||
|
return self.orchestration.refresh_token(
|
||||||
|
data={
|
||||||
|
"refreshToken": refresh_token,
|
||||||
|
},
|
||||||
|
api_key=api_key,
|
||||||
|
)["extensions"]["sdk"]["token"]
|
||||||
|
|
||||||
|
|
||||||
|
# Edge case where a bug in a working-in-progress version of
|
||||||
|
# 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)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3414.
|
||||||
|
assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
|
||||||
|
xxxxxxxxx
|
||||||
|
).xxxxxxxxxxxxxxxxxx(), (
|
||||||
|
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||||
|
)
|
||||||
|
|
|
@ -4,10 +4,15 @@ assertion_line: 0
|
||||||
expression: formatted
|
expression: formatted
|
||||||
---
|
---
|
||||||
# This is a standalone comment.
|
# This is a standalone comment.
|
||||||
sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3
|
(
|
||||||
|
sdfjklsdfsjldkflkjsf,
|
||||||
|
sdfjsdfjlksdljkfsdlkf,
|
||||||
|
sdfsdjfklsdfjlksdljkf,
|
||||||
|
sdsfsdfjskdflsfsdf,
|
||||||
|
) = (1, 2, 3)
|
||||||
|
|
||||||
# This is as well.
|
# This is as well.
|
||||||
this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
|
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
|
||||||
|
|
||||||
(a,) = call()
|
(a,) = call()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
source: src/source_code/mod.rs
|
||||||
|
assertion_line: 0
|
||||||
|
expression: formatted
|
||||||
|
---
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,4 @@ for ((x in {}) or {})["a"] in x:
|
||||||
pass
|
pass
|
||||||
pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
|
pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
|
||||||
lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
|
lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue