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

View File

@ -735,15 +735,14 @@ def is_funcdef(node: Node) -> bool:
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:
"""Return True if `node` is a suite with a stub body."""
if node.parent is not None:
if node.parent.type not in (
syms.funcdef,
syms.async_funcdef,
syms.classdef,
):
return False
if node.parent is not None and not is_function_or_class(node.parent):
return False
# If there is a comment, we want to keep it.
if node.prefix.strip():

View File

@ -514,12 +514,18 @@ async def f():
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 (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,

View File

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

View File

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

View File

@ -167,7 +167,7 @@
slice[0:1:2]
slice[:]
slice[:-1]
@@ -137,118 +156,191 @@
@@ -137,118 +156,197 @@
numpy[-(c + 1) :, d]
numpy[:, l[-2]]
numpy[:, ::-1]
@ -265,22 +265,30 @@
-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'):
+for i in call(): ...
+for j in 1 + (2 + 3): ...
+while this and that: ...
+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,