Skip to content

Commit

Permalink
Fix issue with type comments on lines with trailing commas (#1058)
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
msullivan authored and JelleZijlstra committed Oct 10, 2019
1 parent d9e71a7 commit 6fe8009
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion black.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/data/comments2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down Expand Up @@ -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 ###
#######################
Expand Down

0 comments on commit 6fe8009

Please sign in to comment.