From 265d9466ed32733878ea357058366cd78440e410 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Thu, 10 Oct 2019 11:24:09 -0700 Subject: [PATCH] Fix issue with type comments on lines with trailing commas The code introduced in #1027 to detect whether a type comment appeared after a regular comment in a Line would spuriously misfire when a leaf was in the comments dict but had an empty list of comments. This can occur as an artifact of how comments on trailing commas are handled, it seems. (This was discovered trying to test black out on mypy.) --- black.py | 2 +- tests/data/comments2.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/black.py b/black.py index f283ffc99b3..d8aa3562d8f 100644 --- a/black.py +++ b/black.py @@ -1321,7 +1321,7 @@ def contains_uncollapsable_type_comments(self) -> bool: if leaf_id not in ignored_ids or comment_seen: return True - comment_seen = True + comment_seen = True return False diff --git a/tests/data/comments2.py b/tests/data/comments2.py index 54b7b0018c9..248552c12aa 100644 --- a/tests/data/comments2.py +++ b/tests/data/comments2.py @@ -146,6 +146,7 @@ def inline_comments_in_brackets_ruin_everything(): ], ) +CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final ####################### ### SECTION COMMENT ### @@ -313,6 +314,8 @@ def inline_comments_in_brackets_ruin_everything(): ) +CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final + ####################### ### SECTION COMMENT ### #######################