diff --git a/src/black/__init__.py b/src/black/__init__.py index 40148ae428d..21a71e61faa 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -2709,8 +2709,9 @@ def make_comment(content: str) -> str: if content[0] == "#": content = content[1:] - if content and content[0] == " ": # This is a non-breaking space - content = " " + content[1:] # And this is a simple space + NON_BREAKING_SPACE = " " + if content and content[0] == NON_BREAKING_SPACE and "type: ignore" not in content: + content[0] = " " # Replace NBSP by a simple space if content and content[0] not in " !:#'%": content = " " + content return "#" + content diff --git a/tests/data/comments7.py b/tests/data/comments7.py index bd81e700765..e123b4d8df8 100644 --- a/tests/data/comments7.py +++ b/tests/data/comments7.py @@ -183,7 +183,7 @@ def func(): 0.0789, 0.0123, 0.0789, - a[-1], # type: ignore + a[-1], # type: ignore ) c = call(0.0123, 0.0456, 0.0789, 0.0123, 0.0789, a[-1]) # type: ignore c = call(