Fix another dummy impl case

This commit is contained in:
Jelle Zijlstra 2023-12-11 13:39:36 -08:00
parent c27daf6a8f
commit dc2d1046ee
6 changed files with 46 additions and 30 deletions

View File

@ -42,6 +42,7 @@
is_atom_with_invisible_parens, is_atom_with_invisible_parens,
is_docstring, is_docstring,
is_empty_tuple, is_empty_tuple,
is_function_or_class,
is_lpar_token, is_lpar_token,
is_multiline_string, is_multiline_string,
is_name_token, is_name_token,
@ -293,9 +294,8 @@ def visit_simple_stmt(self, node: Node) -> Iterator[Line]:
wrap_in_parentheses(node, child, visible=False) wrap_in_parentheses(node, child, visible=False)
prev_type = child.type prev_type = child.type
is_suite_like = node.parent and node.parent.type in STATEMENT if node.parent and node.parent.type in STATEMENT:
if is_suite_like: if is_stub_body(node) and is_function_or_class(node.parent):
if is_stub_body(node):
yield from self.visit_default(node) yield from self.visit_default(node)
else: else:
yield from self.line(+1) yield from self.line(+1)

View File

@ -735,14 +735,13 @@ def is_funcdef(node: Node) -> bool:
return node.type == syms.funcdef return node.type == syms.funcdef
def is_function_or_class(node: Node) -> bool:
return node.type in {syms.funcdef, syms.classdef, syms.async_funcdef}
def is_stub_suite(node: Node) -> bool: def is_stub_suite(node: Node) -> bool:
"""Return True if `node` is a suite with a stub body.""" """Return True if `node` is a suite with a stub body."""
if node.parent is not None: if node.parent is not None and not is_function_or_class(node.parent):
if node.parent.type not in (
syms.funcdef,
syms.async_funcdef,
syms.classdef,
):
return False return False
# If there is a comment, we want to keep it. # If there is a comment, we want to keep it.

View File

@ -514,12 +514,18 @@ async def f():
force=False force=False
), "Short message" ), "Short message"
assert parens is TooMany assert parens is TooMany
for (x,) in (1,), (2,), (3,): ... for (x,) in (1,), (2,), (3,):
for y in (): ... ...
for z in (i for i in (1, 2, 3)): ... for y in ():
for i in call(): ... ...
for j in 1 + (2 + 3): ... for z in (i for i in (1, 2, 3)):
while this and that: ... ...
for i in call():
...
for j in 1 + (2 + 3):
...
while this and that:
...
for ( for (
addr_family, addr_family,
addr_type, addr_type,

View File

@ -114,7 +114,8 @@ def func_no_args():
c c
if True: if True:
raise RuntimeError raise RuntimeError
if False: ... if False:
...
for i in range(10): for i in range(10):
print(i) print(i)
continue continue

View File

@ -24,8 +24,10 @@
def func(match: case, case: match) -> case: def func(match: case, case: match) -> case:
match Something(): match Something():
case func(match, case): ... case func(match, case):
case another: ... ...
case another:
...
match a, *b, c: match a, *b, c:

View File

@ -167,7 +167,7 @@
slice[0:1:2] slice[0:1:2]
slice[:] slice[:]
slice[:-1] slice[:-1]
@@ -137,118 +156,191 @@ @@ -137,118 +156,197 @@
numpy[-(c + 1) :, d] numpy[-(c + 1) :, d]
numpy[:, l[-2]] numpy[:, l[-2]]
numpy[:, ::-1] numpy[:, ::-1]
@ -265,22 +265,30 @@
-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(force=False), "Short message"
-assert(((parens is TooMany))) -assert(((parens is TooMany)))
-for x, in (1,), (2,), (3,): ... -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) +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( +assert this is ComplexTest and not requirements.fit_in_a_single_line(
+ force=False + force=False
+), "Short message" +), "Short message"
+assert parens is TooMany +assert parens is TooMany
+for (x,) in (1,), (2,), (3,): ... +for (x,) in (1,), (2,), (3,):
for y in (): ... + ...
for z in (i for i in (1, 2, 3)): ... +for y in ():
-for i in (call()): ... + ...
-for j in (1 + (2 + 3)): ... +for z in (i for i 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'): +for i in call():
+for i in call(): ... + ...
+for j in 1 + (2 + 3): ... +for j in 1 + (2 + 3):
+while this and that: ... + ...
+while this and that:
+ ...
+for ( +for (
+ addr_family, + addr_family,
+ addr_type, + addr_type,