Fix the worst issues

This commit is contained in:
Jelle Zijlstra 2023-12-11 13:23:26 -08:00
parent 3fd83e08e7
commit 6e8871b0ce
3 changed files with 6 additions and 8 deletions

View File

@ -280,7 +280,7 @@ def visit_match_case(self, node: Node) -> Iterator[Line]:
def visit_suite(self, node: Node) -> Iterator[Line]:
"""Visit a suite."""
if is_stub_suite(node, self.mode):
if is_stub_suite(node):
yield from self.visit(node.children[2])
else:
yield from self.visit_default(node)
@ -303,7 +303,7 @@ def visit_simple_stmt(self, node: Node) -> Iterator[Line]:
yield from self.line(-1)
else:
if not node.parent or not is_stub_suite(node.parent, self.mode):
if not node.parent or not is_stub_suite(node.parent):
yield from self.line()
yield from self.visit_default(node)

View File

@ -828,16 +828,14 @@ def is_line_short_enough( # noqa: C901
if not line_str:
line_str = line_to_string(line)
width = str_width if Preview.respect_east_asian_width in mode else len
if line.contains_standalone_comments():
return False
if "\n" not in line_str:
# No multiline strings (MLS) present
return width(line_str) <= mode.line_length
return str_width(line_str) <= mode.line_length
first, *_, last = line_str.split("\n")
if width(first) > mode.line_length or width(last) > mode.line_length:
if str_width(first) > mode.line_length or str_width(last) > mode.line_length:
return False
# Traverse the AST to examine the context of the multiline string (MLS),

View File

@ -735,10 +735,10 @@ def is_funcdef(node: Node) -> bool:
return node.type == syms.funcdef
def is_stub_suite(node: Node, mode: Mode) -> bool:
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 Preview.dummy_implementations in mode and node.parent.type not in (
if node.parent.type not in (
syms.funcdef,
syms.async_funcdef,
syms.classdef,