Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable formatting with some # type: ignores #1113

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion black.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,10 @@ def contains_uncollapsable_type_comments(self) -> bool:
for leaf_id, comments in self.comments.items():
for comment in comments:
if is_type_comment(comment):
if leaf_id not in ignored_ids or comment_seen:
if comment_seen or (
not is_type_comment(comment, " ignore")
and leaf_id not in ignored_ids
):
return True

comment_seen = True
Expand Down
13 changes: 13 additions & 0 deletions tests/data/comments2.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def inline_comments_in_brackets_ruin_everything():

CONFIG_FILES = [CONFIG_FILE, ] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final

class Test:
def _init_host(self, parsed) -> None:
if (parsed.hostname is None or # type: ignore
not parsed.hostname.strip()):
pass

#######################
### SECTION COMMENT ###
#######################
Expand Down Expand Up @@ -312,6 +318,13 @@ def inline_comments_in_brackets_ruin_everything():

CONFIG_FILES = [CONFIG_FILE,] + SHARED_CONFIG_FILES + USER_CONFIG_FILES # type: Final


class Test:
def _init_host(self, parsed) -> None:
if parsed.hostname is None or not parsed.hostname.strip(): # type: ignore
pass


#######################
### SECTION COMMENT ###
#######################
Expand Down
4 changes: 1 addition & 3 deletions tests/data/comments7.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def func():


def func():
c = call(
0.0123, 0.0456, 0.0789, 0.0123, 0.0789, a[-1], # type: ignore
)
c = call(0.0123, 0.0456, 0.0789, 0.0123, 0.0789, a[-1],) # type: ignore
msullivan marked this conversation as resolved.
Show resolved Hide resolved

# The type: ignore exception only applies to line length, not
# other types of formatting.
Expand Down