diff --git a/patches/pyink.patch b/patches/pyink.patch index 20fd5fb7bfe..4f8f27aa676 100644 --- a/patches/pyink.patch +++ b/patches/pyink.patch @@ -794,7 +794,15 @@ leaves = iter(self.leaves) first = next(leaves) res = f"{first.prefix}{indent}{first.value}" -@@ -591,7 +625,7 @@ class EmptyLineTracker: +@@ -561,6 +595,7 @@ class EmptyLineTracker: + and self.previous_block.previous_block is None + and len(self.previous_block.original_line.leaves) == 1 + and self.previous_block.original_line.is_triple_quoted_string ++ and not (current_line.is_class or current_line.is_def) + ): + before = 1 + +@@ -591,7 +626,7 @@ class EmptyLineTracker: def _maybe_empty_lines(self, current_line: Line) -> Tuple[int, int]: max_allowed = 1 @@ -803,7 +811,7 @@ max_allowed = 1 if self.mode.is_pyi else 2 if current_line.leaves: # Consume the first leaf's extra newlines. -@@ -606,7 +640,7 @@ class EmptyLineTracker: +@@ -606,7 +641,7 @@ class EmptyLineTracker: depth = current_line.depth previous_def = None @@ -812,7 +820,7 @@ previous_def = self.previous_defs.pop() if previous_def is not None: -@@ -655,10 +689,25 @@ class EmptyLineTracker: +@@ -655,10 +690,25 @@ class EmptyLineTracker: if ( self.previous_line @@ -840,7 +848,7 @@ ): return (before or 1), 0 -@@ -671,6 +720,14 @@ class EmptyLineTracker: +@@ -671,6 +721,14 @@ class EmptyLineTracker: return 0, 1 return before, 1 @@ -855,7 +863,7 @@ if self.previous_line and self.previous_line.opens_block: return 0, 0 return before, 0 -@@ -691,15 +748,16 @@ class EmptyLineTracker: +@@ -691,15 +749,16 @@ class EmptyLineTracker: return 0, 0 @@ -875,7 +883,7 @@ and before == 0 ): slc = self.semantic_leading_comment -@@ -716,9 +774,9 @@ class EmptyLineTracker: +@@ -716,9 +775,9 @@ class EmptyLineTracker: if self.mode.is_pyi: if current_line.is_class or self.previous_line.is_class: @@ -887,7 +895,7 @@ newlines = 1 elif current_line.is_stub_class and self.previous_line.is_stub_class: # No blank line between classes with an empty body -@@ -747,7 +805,7 @@ class EmptyLineTracker: +@@ -747,7 +806,7 @@ class EmptyLineTracker: # Blank line between a block of functions (maybe with preceding # decorators) and a block of non-functions newlines = 1 @@ -896,7 +904,7 @@ newlines = 1 else: newlines = 0 -@@ -815,10 +873,14 @@ def is_line_short_enough( # noqa: C901 +@@ -815,10 +874,14 @@ def is_line_short_enough( # noqa: C901 line_str = line_to_string(line) width = str_width if mode.preview else len @@ -912,7 +920,7 @@ and "\n" not in line_str # multiline strings and not line.contains_standalone_comments() ) -@@ -827,7 +889,7 @@ def is_line_short_enough( # noqa: C901 +@@ -827,7 +890,7 @@ def is_line_short_enough( # noqa: C901 return False if "\n" not in line_str: # No multiline strings (MLS) present @@ -921,7 +929,7 @@ first, *_, last = line_str.split("\n") if width(first) > mode.line_length or width(last) > mode.line_length: -@@ -1017,7 +1079,7 @@ def can_omit_invisible_parens( +@@ -1017,7 +1080,7 @@ def can_omit_invisible_parens( def _can_omit_opening_paren(line: Line, *, first: Leaf, line_length: int) -> bool: """See `can_omit_invisible_parens`.""" remainder = False @@ -930,7 +938,7 @@ _index = -1 for _index, leaf, leaf_length in line.enumerate_with_length(): if leaf.type in CLOSING_BRACKETS and leaf.opening_bracket is first: -@@ -1041,7 +1103,7 @@ def _can_omit_opening_paren(line: Line, +@@ -1041,7 +1104,7 @@ def _can_omit_opening_paren(line: Line, def _can_omit_closing_paren(line: Line, *, last: Leaf, line_length: int) -> bool: """See `can_omit_invisible_parens`.""" @@ -1435,6 +1443,26 @@ class TestDeFactoAPI: """Test that certain symbols that are commonly used externally keep working. +--- a/tests/util.py ++++ b/tests/util.py +@@ -246,6 +246,8 @@ def get_flags_parser() -> argparse.Argum + " version works correctly." + ), + ) ++ parser.add_argument("--pyink", default=False, action="store_true") ++ parser.add_argument("--pyink-indentation", default=4, type=int, choices=[2, 4]) + return parser + + +@@ -260,6 +262,8 @@ def parse_mode(flags_line: str) -> TestC + is_ipynb=args.ipynb, + magic_trailing_comma=not args.skip_magic_trailing_comma, + preview=args.preview, ++ is_pyink=args.pyink, ++ pyink_indentation=args.pyink_indentation, + ) + return TestCaseArgs(mode=mode, fast=args.fast, minimum_version=args.minimum_version) + --- a/tox.ini +++ b/tox.ini @@ -95,4 +95,4 @@ setenv = PYTHONPATH = {toxinidir}/src diff --git a/src/pyink/lines.py b/src/pyink/lines.py index 1e2d6457539..99948615e3c 100644 --- a/src/pyink/lines.py +++ b/src/pyink/lines.py @@ -595,6 +595,7 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock: and self.previous_block.previous_block is None and len(self.previous_block.original_line.leaves) == 1 and self.previous_block.original_line.is_triple_quoted_string + and not (current_line.is_class or current_line.is_def) ): before = 1