Skip to content

Commit

Permalink
Leave non breaking space in comment with 'type: ignore' inside
Browse files Browse the repository at this point in the history
The switch to unvalid 'type: ignore' to valid 'type: ignore' is a
lot more complicated to do.

See:psf#2092
  • Loading branch information
Pierre-Sassoulas committed Apr 11, 2021
1 parent 145d46e commit f66a033
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/black/__init__.py
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/data/comments7.py
Expand Up @@ -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(
Expand All @@ -199,7 +199,7 @@ def func():
a[-1], # type: ignore
)

# The type: ignore exception only applies to line length, not
#  The type: ignore exception only applies to line length, not
# other types of formatting.
c = call(
"aaaaaaaa",
Expand Down

0 comments on commit f66a033

Please sign in to comment.