From 6fe800933d8919436cabf40466ee462f49463814 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Thu, 10 Oct 2019 11:50:51 -0700 Subject: [PATCH] Fix issue with type comments on lines with trailing commas (#1058) 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 f283ffc..d8aa356 100644 --- a/black.py +++ b/black.py @@ -1321,7 +1321,7 @@ class Line: 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 54b7b00..248552c 100644 --- a/tests/data/comments2.py +++ b/tests/data/comments2.py @@ -146,6 +146,7 @@ short ], ) +CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final ####################### ### SECTION COMMENT ### @@ -313,6 +314,8 @@ short ) +CONFIG_FILES = [CONFIG_FILE] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final + ####################### ### SECTION COMMENT ### ####################### -- 2.39.5