Skip to content

Commit

Permalink
Handle the case with type hint in the pre-3.6 style
Browse files Browse the repository at this point in the history
Also handle notmal comment not starting with 'type:' better.
  • Loading branch information
Pierre-Sassoulas committed Apr 11, 2021
1 parent cbe8654 commit 41d50de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/black/__init__.py
Expand Up @@ -2710,7 +2710,11 @@ def make_comment(content: str) -> str:
if content[0] == "#":
content = content[1:]
NON_BREAKING_SPACE = " "
if content and content[0] == NON_BREAKING_SPACE and "type: ignore" not in content:
if (
content
and content[0] == NON_BREAKING_SPACE
and not content.lstrip().startswith("type:")
):
content = " " + content[1:] # Replace NBSP by a simple space
if content and content[0] not in " !:#'%":
content = " " + content
Expand Down
7 changes: 6 additions & 1 deletion tests/data/comments7.py
Expand Up @@ -129,6 +129,8 @@ def test_fails_invalid_post_data(
):
...

square = Square(4) # type: Optional[Square]

# output

from .config import (
Expand Down Expand Up @@ -263,4 +265,7 @@ class C:
def test_fails_invalid_post_data(
self, pyramid_config, db_request, post_data, message
):
...
...


square = Square(4) # type: Optional[Square]

0 comments on commit 41d50de

Please sign in to comment.