From d93e72680625a100c7c5701280f1bcf83124ae40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Thu, 21 Jun 2018 13:29:34 -0700 Subject: [PATCH 1/1] Don't freeze when multiple comments directly precede # fmt: off Fixes #371 --- README.md | 5 +++++ black.py | 2 +- tests/data/fmtonoff.py | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c93c300..96d169a 100644 --- a/README.md +++ b/README.md @@ -820,6 +820,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). ## Change Log +### 18.6b4 + +* hotfix: don't freeze when multiple comments directly precede `# fmt: off` (#371) + + ### 18.6b3 * typing stub files (`.pyi`) now have blank lines added after constants (#340) diff --git a/black.py b/black.py index 0da2fad..2d23298 100644 --- a/black.py +++ b/black.py @@ -2608,7 +2608,7 @@ def convert_one_fmt_off_pair(node: Node) -> bool: ) return True - previous_consumed += comment.consumed + previous_consumed = comment.consumed return False diff --git a/tests/data/fmtonoff.py b/tests/data/fmtonoff.py index 74b52ec..b2e9fc0 100644 --- a/tests/data/fmtonoff.py +++ b/tests/data/fmtonoff.py @@ -11,6 +11,10 @@ from third_party import (X, Y, Z) # fmt: on f'trigger 3.6 mode' +# Comment 1 + +# Comment 2 + # fmt: off def func_no_args(): a; b; c @@ -159,6 +163,10 @@ from third_party import (X, Y, Z) # fmt: on f"trigger 3.6 mode" +# Comment 1 + +# Comment 2 + # fmt: off def func_no_args(): a; b; c -- 2.39.5