]> 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:

Don't allow type comments to be merged behind regular comments (#1027)
authorMichael J. Sullivan <sully@msully.net>
Tue, 17 Sep 2019 20:40:03 +0000 (13:40 -0700)
committerJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 17 Sep 2019 20:40:03 +0000 (13:40 -0700)
Type comments only apply if they are the first comment on the line,
which means that allowing them to be pushed behind a regular comment
when joining lines is a semantic change (and, indeed, one that black
catches and fails on).

black.py
tests/data/comments6.py

index 71f42ef307194f3febbd336c2c70597b25eafe5c..a4f36887aecc3630136cb4ed040b3768b814564a 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1296,7 +1296,7 @@ class Line:
                     return True
         return False
 
                     return True
         return False
 
-    def contains_inner_type_comments(self) -> bool:
+    def contains_uncollapsable_type_comments(self) -> bool:
         ignored_ids = set()
         try:
             last_leaf = self.leaves[-1]
         ignored_ids = set()
         try:
             last_leaf = self.leaves[-1]
@@ -1313,13 +1313,19 @@ class Line:
         except IndexError:
             return False
 
         except IndexError:
             return False
 
+        # A type comment is uncollapsable if it is attached to a leaf
+        # that isn't at the end of the line (since that could cause it
+        # to get associated to a different argument) or if there are
+        # comments before it (since that could cause it to get hidden
+        # behind a comment.
+        comment_seen = False
         for leaf_id, comments in self.comments.items():
         for leaf_id, comments in self.comments.items():
-            if leaf_id in ignored_ids:
-                continue
-
             for comment in comments:
                 if is_type_comment(comment):
             for comment in comments:
                 if is_type_comment(comment):
-                    return True
+                    if leaf_id not in ignored_ids or comment_seen:
+                        return True
+
+            comment_seen = True
 
         return False
 
 
         return False
 
@@ -2328,7 +2334,7 @@ def split_line(
     line_str = str(line).strip("\n")
 
     if (
     line_str = str(line).strip("\n")
 
     if (
-        not line.contains_inner_type_comments()
+        not line.contains_uncollapsable_type_comments()
         and not line.should_explode
         and is_line_short_enough(line, line_length=line_length, line_str=line_str)
     ):
         and not line.should_explode
         and is_line_short_enough(line, line_length=line_length, line_str=line_str)
     ):
index a2cd018adcb77cea5859184cfc3220a0abb45c3f..6e34b74f9e75c42360374aacef593158b11cbe49 100644 (file)
@@ -69,6 +69,20 @@ def f(
     )  # type: int
 
 
     )  # type: int
 
 
+def f(
+    x,  # not a type comment
+    y,  # type: int
+):
+    # type: (...) -> None
+    pass
+
+
+def f(
+    x,  # not a type comment
+):  # type: (int) -> None
+    pass
+
+
 def func(
     a=some_list[0],  # type: int
 ):  # type: () -> int
 def func(
     a=some_list[0],  # type: int
 ):  # type: () -> int