diff --git a/black.py b/black.py index a48f64765d9..20554658b95 100644 --- a/black.py +++ b/black.py @@ -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 diff --git a/tests/data/comments2.py b/tests/data/comments2.py index f4a30b8afac..89c29104bd8 100644 --- a/tests/data/comments2.py +++ b/tests/data/comments2.py @@ -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 ### ####################### @@ -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 ### ####################### diff --git a/tests/data/comments7.py b/tests/data/comments7.py index 948b3b03a2b..40951253f2e 100644 --- a/tests/data/comments7.py +++ b/tests/data/comments7.py @@ -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 # The type: ignore exception only applies to line length, not # other types of formatting.