This is documented but not actually implemented yet.
@ambv what do you think about doing this the way prettier does instead (or as well), where you only need a single comment to disable formatting on an entire block/node: https://prettier.io/docs/en/ignore.html
# fmt: ignore
hey = {
"don't": 'touch', 'my': 'ugly', 'formatting',
'because': ['I', "don't", 'know', 'any', 'better']}
I think fmt off/fmt: on would still be useful, but I think ignoring by AST node would be the most common use case.
@joslarson tl;dr - Explicit is better than implicit.
What you're suggesting sounds intriguing but I would need to implement # yapf: disable and # yapf: enable anyway. So # fmt: off and # fmt: on it is for the time being. That makes it obvious where you want the auto-formatting to resume. If people put those in strange places, that won't be fun to debug but I'm prepared to deal with this.
We might switch to a single # fmt: ignore if the current approach proves to be too flaky.
Most helpful comment
@joslarson tl;dr - Explicit is better than implicit.
What you're suggesting sounds intriguing but I would need to implement
# yapf: disableand# yapf: enableanyway. So# fmt: offand# fmt: onit is for the time being. That makes it obvious where you want the auto-formatting to resume. If people put those in strange places, that won't be fun to debug but I'm prepared to deal with this.We might switch to a single
# fmt: ignoreif the current approach proves to be too flaky.