From 6e8871b0ce271cabb7de717926973c14ac541eaf Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 11 Dec 2023 13:23:26 -0800 Subject: [PATCH] Fix the worst issues --- src/black/linegen.py | 4 ++-- src/black/lines.py | 6 ++---- src/black/nodes.py | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/black/linegen.py b/src/black/linegen.py index c2be304..1745b95 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -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) diff --git a/src/black/lines.py b/src/black/lines.py index 1046ff1..4bed73c 100644 --- a/src/black/lines.py +++ b/src/black/lines.py @@ -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), diff --git a/src/black/nodes.py b/src/black/nodes.py index 388d1ee..da53fa2 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -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,