Fix the worst issues
This commit is contained in:
parent
3fd83e08e7
commit
6e8871b0ce
@ -280,7 +280,7 @@ def visit_match_case(self, node: Node) -> Iterator[Line]:
|
|||||||
|
|
||||||
def visit_suite(self, node: Node) -> Iterator[Line]:
|
def visit_suite(self, node: Node) -> Iterator[Line]:
|
||||||
"""Visit a suite."""
|
"""Visit a suite."""
|
||||||
if is_stub_suite(node, self.mode):
|
if is_stub_suite(node):
|
||||||
yield from self.visit(node.children[2])
|
yield from self.visit(node.children[2])
|
||||||
else:
|
else:
|
||||||
yield from self.visit_default(node)
|
yield from self.visit_default(node)
|
||||||
@ -303,7 +303,7 @@ def visit_simple_stmt(self, node: Node) -> Iterator[Line]:
|
|||||||
yield from self.line(-1)
|
yield from self.line(-1)
|
||||||
|
|
||||||
else:
|
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.line()
|
||||||
yield from self.visit_default(node)
|
yield from self.visit_default(node)
|
||||||
|
|
||||||
|
@ -828,16 +828,14 @@ def is_line_short_enough( # noqa: C901
|
|||||||
if not line_str:
|
if not line_str:
|
||||||
line_str = line_to_string(line)
|
line_str = line_to_string(line)
|
||||||
|
|
||||||
width = str_width if Preview.respect_east_asian_width in mode else len
|
|
||||||
|
|
||||||
if line.contains_standalone_comments():
|
if line.contains_standalone_comments():
|
||||||
return False
|
return False
|
||||||
if "\n" not in line_str:
|
if "\n" not in line_str:
|
||||||
# No multiline strings (MLS) present
|
# 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")
|
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
|
return False
|
||||||
|
|
||||||
# Traverse the AST to examine the context of the multiline string (MLS),
|
# Traverse the AST to examine the context of the multiline string (MLS),
|
||||||
|
@ -735,10 +735,10 @@ def is_funcdef(node: Node) -> bool:
|
|||||||
return node.type == syms.funcdef
|
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."""
|
"""Return True if `node` is a suite with a stub body."""
|
||||||
if node.parent is not None:
|
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.funcdef,
|
||||||
syms.async_funcdef,
|
syms.async_funcdef,
|
||||||
syms.classdef,
|
syms.classdef,
|
||||||
|
Loading…
Reference in New Issue
Block a user