Loading black.py +35 −4 Changes for black.py: 35 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -3116,18 +3116,49 @@ def generate_ignored_nodes(leaf: Leaf) -> Iterator[LN]: """ container: Optional[LN] = container_of(leaf) while container is not None and container.type != token.ENDMARKER: if fmt_on(container): return # fix for fmt: on in children if contains_fmt_on_at_column(container, leaf.column): for child in container.children: if contains_fmt_on_at_column(child, leaf.column): return yield child else: yield container container = container.next_sibling def fmt_on(container: LN) -> bool: is_fmt_on = False for comment in list_comments(container.prefix, is_endmarker=False): if comment.value in FMT_ON: is_fmt_on = True elif comment.value in FMT_OFF: is_fmt_on = False if is_fmt_on: return return is_fmt_on yield container container = container.next_sibling def contains_fmt_on_at_column(container: LN, column: int) -> bool: for child in container.children: if ( isinstance(child, Node) and first_leaf_column(child) == column or isinstance(child, Leaf) and child.column == column ): if fmt_on(child): return True return False def first_leaf_column(node: Node) -> Optional[int]: for child in node.children: if isinstance(child, Leaf): return child.column return None def maybe_make_parens_invisible_in_atom(node: LN, parent: LN) -> bool: Loading tests/data/fmtonoff4.py 0 → 100644 +31 −0 Changes for tests/data/fmtonoff4.py: 31 added lines, 0 removed lines. Original line number Diff line number Diff line # fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test([ 1, 2, 3, 4, ]) def f(): pass # output # fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test( [1, 2, 3, 4,] ) def f(): pass tests/test_black.py +8 −0 Changes for tests/test_black.py: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -632,6 +632,14 @@ def test_fmtonoff3(self) -> None: black.assert_equivalent(source, actual) black.assert_stable(source, actual, black.FileMode()) @patch("black.dump_to_file", dump_to_stderr) def test_fmtonoff4(self) -> None: source, expected = read_data("fmtonoff4") actual = fs(source) self.assertFormatEqual(expected, actual) black.assert_equivalent(source, actual) black.assert_stable(source, actual, black.FileMode()) @patch("black.dump_to_file", dump_to_stderr) def test_remove_empty_parentheses_after_class(self) -> None: source, expected = read_data("class_blank_parentheses") Loading Loading
black.py +35 −4 Changes for black.py: 35 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -3116,18 +3116,49 @@ def generate_ignored_nodes(leaf: Leaf) -> Iterator[LN]: """ container: Optional[LN] = container_of(leaf) while container is not None and container.type != token.ENDMARKER: if fmt_on(container): return # fix for fmt: on in children if contains_fmt_on_at_column(container, leaf.column): for child in container.children: if contains_fmt_on_at_column(child, leaf.column): return yield child else: yield container container = container.next_sibling def fmt_on(container: LN) -> bool: is_fmt_on = False for comment in list_comments(container.prefix, is_endmarker=False): if comment.value in FMT_ON: is_fmt_on = True elif comment.value in FMT_OFF: is_fmt_on = False if is_fmt_on: return return is_fmt_on yield container container = container.next_sibling def contains_fmt_on_at_column(container: LN, column: int) -> bool: for child in container.children: if ( isinstance(child, Node) and first_leaf_column(child) == column or isinstance(child, Leaf) and child.column == column ): if fmt_on(child): return True return False def first_leaf_column(node: Node) -> Optional[int]: for child in node.children: if isinstance(child, Leaf): return child.column return None def maybe_make_parens_invisible_in_atom(node: LN, parent: LN) -> bool: Loading
tests/data/fmtonoff4.py 0 → 100644 +31 −0 Changes for tests/data/fmtonoff4.py: 31 added lines, 0 removed lines. Original line number Diff line number Diff line # fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test([ 1, 2, 3, 4, ]) def f(): pass # output # fmt: off @test([ 1, 2, 3, 4, ]) # fmt: on def f(): pass @test( [1, 2, 3, 4,] ) def f(): pass
tests/test_black.py +8 −0 Changes for tests/test_black.py: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -632,6 +632,14 @@ def test_fmtonoff3(self) -> None: black.assert_equivalent(source, actual) black.assert_stable(source, actual, black.FileMode()) @patch("black.dump_to_file", dump_to_stderr) def test_fmtonoff4(self) -> None: source, expected = read_data("fmtonoff4") actual = fs(source) self.assertFormatEqual(expected, actual) black.assert_equivalent(source, actual) black.assert_stable(source, actual, black.FileMode()) @patch("black.dump_to_file", dump_to_stderr) def test_remove_empty_parentheses_after_class(self) -> None: source, expected = read_data("class_blank_parentheses") Loading