]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix optional parentheses being removed within `# fmt: off` sections
authorŁukasz Langa <lukasz@langa.pl>
Mon, 21 May 2018 22:20:19 +0000 (15:20 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Mon, 21 May 2018 22:21:14 +0000 (15:21 -0700)
Fixes #224

README.md
black.py
tests/fmtonoff.py

index b11f7e01eee5ff5acedba7f6a244a90bb9651004..9b42f20a10f7fe9b27348cd19afb44dd484a15f5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -659,6 +659,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 * fixed invalid code produced when standalone comments were present in a trailer
   that was omitted from line splitting on a large expression (#237)
 
+* fixed optional parentheses being removed within `# fmt: off` sections (#224)
+
 
 ### 18.5b0
 
index 8d551640f365e8dd0072adc08cbb0452cad1c715..9fbacc1048cd15fd7816ccdfb8dd3f6dd7252b9c 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1820,7 +1820,7 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
     return 0
 
 
-def generate_comments(leaf: Leaf) -> Iterator[Leaf]:
+def generate_comments(leaf: LN) -> Iterator[Leaf]:
     """Clean the prefix of the `leaf` and generate comments from it, if any.
 
     Comments in lib2to3 are shoved into the whitespace prefix.  This happens
@@ -2337,6 +2337,11 @@ def normalize_invisible_parens(node: Node, parens_after: Set[str]) -> None:
     Standardizes on visible parentheses for single-element tuples, and keeps
     existing visible parentheses for other tuples and generator expressions.
     """
+    try:
+        list(generate_comments(node))
+    except FormatOff:
+        return  # This `node` has a prefix with `# fmt: off`, don't mess with parens.
+
     check_lpar = False
     for child in list(node.children):
         if check_lpar:
index 0ff6672c86bb6aacf1b591fb607b81a9f664b8a1..e76e6a7fcd671cbaf81682bc2c7d0f02e28e9b49 100644 (file)
@@ -50,6 +50,11 @@ def long_lines():
         typedargslist.extend(
             gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
         )
+        # fmt: off
+        a = (
+            unnecessary_bracket()
+        )
+        # fmt: on
     _type_comment_re = re.compile(
         r"""
         ^
@@ -69,8 +74,10 @@ def long_lines():
             \n?
         )
         $
-        """, re.MULTILINE | re.VERBOSE
+        """, # fmt: off
+        re.MULTILINE | re.VERBOSE
     )
+    # fmt: on
 def single_literal_yapf_disable():
     """Black does not support this."""
     BAZ = {
@@ -163,6 +170,11 @@ def long_lines():
                 implicit_default=True,
             )
         )
+        # fmt: off
+        a = (
+            unnecessary_bracket()
+        )
+        # fmt: on
     _type_comment_re = re.compile(
         r"""
         ^
@@ -182,9 +194,10 @@ def long_lines():
             \n?
         )
         $
-        """,
+        """,  # fmt: off
         re.MULTILINE | re.VERBOSE,
     )
+    # fmt: on
 
 
 def single_literal_yapf_disable():