mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +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 = .1.is_integer()
|
||||
x = 1. .imag
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# The percent-percent comments are Spyder IDE cells.
|
||||
|
||||
#%%
|
||||
|
||||
# %%
|
||||
def func():
|
||||
x = """
|
||||
a really long string
|
||||
|
@ -44,4 +45,4 @@ def func():
|
|||
)
|
||||
|
||||
|
||||
#%%
|
||||
# %%
|
||||
|
|
|
@ -62,6 +62,8 @@ def decorated1():
|
|||
# Preview.empty_lines_before_class_or_def_with_leading_comments.
|
||||
# In the current style, the user will have to split those lines by hand.
|
||||
some_instruction
|
||||
|
||||
|
||||
# This comment should be split from `some_instruction` by two lines but isn't.
|
||||
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
|
|
@ -34,7 +34,7 @@ def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=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)):
|
||||
assert fut is self._read_fut, (fut, self._read_fut)
|
||||
|
||||
|
||||
def example(session):
|
||||
result = session.query(models.Customer.id).filter(
|
||||
models.Customer.account_id == account_id,
|
||||
|
|
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 @@
|
|||
|
Loading…
Add table
Add a link
Reference in a new issue