and self.leaves[3].value == ")"
)
+ @property
+ def is_triple_quoted_string(self) -> bool:
+ """Is the line a triple quoted docstring?"""
+ return (
+ bool(self)
+ and self.leaves[0].type == token.STRING
+ and (
+ self.leaves[0].value.startswith('"""')
+ or self.leaves[0].value.startswith("'''")
+ )
+ )
+
def contains_standalone_comments(self, depth_limit: int = sys.maxsize) -> bool:
"""If so, needs to be split before emitting."""
for leaf in self.leaves:
the prefix of the first leaf consists of optional newlines. Those newlines
are consumed by `maybe_empty_lines()` and included in the computation.
"""
+
is_pyi: bool = False
previous_line: Optional[Line] = None
previous_after: int = 0
if self.previous_line.is_decorator:
return 0, 0
+ if (
+ self.previous_line.is_class
+ and self.previous_line.depth != current_line.depth
+ ):
+ return 0, 0
+
if (
self.previous_line.is_comment
and self.previous_line.depth == current_line.depth
):
return (before or 1), 0
+ if (
+ self.previous_line
+ and self.previous_line.is_class
+ and current_line.is_triple_quoted_string
+ ):
+ return before, 1
+
return before, 0
Note: destroys the tree it's visiting by mutating prefixes of its leaves
in ways that will no longer stringify to valid Python code on the tree.
"""
+
is_pyi: bool = False
current_line: Line = Factory(Line)
remove_u_prefix: bool = False
@dataclass
class Report:
"""Provides a reformatting counter. Can be rendered with `str(report)`."""
+
check: bool = False
quiet: bool = False
change_count: int = 0
--- /dev/null
+class ClassSimplest:
+ pass
+class ClassWithInit:
+ def __init__(self):
+ pass
+class ClassWithInitAndVars:
+ cls_var = 100
+ def __init__(self):
+ pass
+class ClassWithInitAndVarsAndDocstring:
+ """Test class"""
+ cls_var = 100
+ def __init__(self):
+ pass
+
+
+# output
+
+
+class ClassSimplest:
+ pass
+
+
+class ClassWithInit:
+ def __init__(self):
+ pass
+
+
+class ClassWithInitAndVars:
+ cls_var = 100
+
+ def __init__(self):
+ pass
+
+
+class ClassWithInitAndVarsAndDocstring:
+ """Test class"""
+
+ cls_var = 100
+
+ def __init__(self):
+ pass
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, line_length=ll)
+ @patch("black.dump_to_file", dump_to_stderr)
+ def test_new_line_between_class_and_code(self) -> None:
+ source, expected = read_data("class_methods_new_line")
+ actual = fs(source)
+ self.assertFormatEqual(expected, actual)
+ black.assert_equivalent(source, actual)
+ black.assert_stable(source, actual, line_length=ll)
+
def test_report(self) -> None:
report = black.Report()
out_lines = []