From 6714ec12f64e2300deb0068950df61c398e8e101 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 11 Apr 2021 11:13:07 +0200 Subject: [PATCH] Leave non breaking space in comment with 'type: ignore' inside The switch to unvalid 'type: ignore' to valid 'type: ignore' is a lot more complicated to do. See:https://github.com/psf/black/pull/2092\#issuecomment-817178166 --- src/black/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 40148ae428d..40e82cc0c07 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 = " " + content[1:] # Replace NBSP by a simple space if content and content[0] not in " !:#'%": content = " " + content return "#" + content