From c2327c83b28aa9ae6e7ea7078f17033c23e34d9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Tue, 19 Jun 2018 23:46:58 -0700 Subject: [PATCH] More tests for `# fmt: off` Two more known limitations that I don't feel like solving now. Probably very low priority. --- black.py | 3 +++ tests/data/fmtonoff.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/black.py b/black.py index 0f966ae..f1b1c30 100644 --- a/black.py +++ b/black.py @@ -2577,6 +2577,9 @@ def convert_one_fmt_off_pair(node: Node) -> bool: continue ignored_nodes = list(generate_ignored_nodes(leaf)) + if not ignored_nodes: + continue + first = ignored_nodes[0] # Can be a container node with the `leaf`. parent = first.parent prefix = first.prefix diff --git a/tests/data/fmtonoff.py b/tests/data/fmtonoff.py index 373e5c7..74b52ec 100644 --- a/tests/data/fmtonoff.py +++ b/tests/data/fmtonoff.py @@ -53,6 +53,27 @@ def example(session): .order_by(models.Customer.id.asc())\ .all() # fmt: on +def off_and_on_without_data(): + """All comments here are technically on the same prefix. + + The comments between will be formatted. This is a known limitation. + """ + # fmt: off + + + #hey, that won't work + + + # fmt: on + pass +def on_and_off_broken(): + """Another known limitation.""" + # fmt: on + # fmt: off + this=should.not_be.formatted() + but=it is formatted + because . the . handling . inside . generate_ignored_nodes() + doesnt . consider . ordering . within . one . prefix def long_lines(): if True: typedargslist.extend( @@ -201,6 +222,29 @@ def example(session): # fmt: on +def off_and_on_without_data(): + """All comments here are technically on the same prefix. + + The comments between will be formatted. This is a known limitation. + """ + # fmt: off + + # hey, that won't work + + # fmt: on + pass + + +def on_and_off_broken(): + """Another known limitation.""" + # fmt: on + # fmt: off + this = should.not_be.formatted() + but = it is formatted + because.the.handling.inside.generate_ignored_nodes() + doesnt.consider.ordering.within.one.prefix + + def long_lines(): if True: typedargslist.extend( -- 2.39.5