Skip to content

Commit

Permalink
Fix mangling pweave and Spyder IDE special comments
Browse files Browse the repository at this point in the history
Fixes psf#532.

(cherry picked from commit c6c8ef7)
  • Loading branch information
ambv authored and jleclanche committed Nov 14, 2018
1 parent 8124134 commit 484a84c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
* cache is now populated when `--check` is successful for a file which speeds up
consecutive checks of properly formatted unmodified files (#448)

* fixed mangling [pweave](http://mpastell.com/pweave/) and
[Spyder IDE](https://pythonhosted.org/spyder/) special comments (#532)

* fixed unstable formatting when unpacking big tuples (#267)

* fixed parsing of `__future__` imports with renames (#389)
Expand Down
6 changes: 3 additions & 3 deletions black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2102,8 +2102,8 @@ def list_comments(prefix: str, *, is_endmarker: bool) -> List[ProtoComment]:
def make_comment(content: str) -> str:
"""Return a consistently formatted comment from the given `content` string.
All comments (except for "##", "#!", "#:") should have a single space between
the hash sign and the content.
All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
space between the hash sign and the content.
If `content` didn't start with a hash sign, one is provided.
"""
Expand All @@ -2113,7 +2113,7 @@ def make_comment(content: str) -> str:

if content[0] == "#":
content = content[1:]
if content and content[0] not in " !:#":
if content and content[0] not in " !:#'%":
content = " " + content
return "#" + content

Expand Down
3 changes: 3 additions & 0 deletions tests/data/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self):
"""Docstring for instance attribute spam."""


#' <h1>This is pweave!</h1>


@fast(really=True)
async def wat():
async with X.open_async() as x: # Some more comments
Expand Down
6 changes: 6 additions & 0 deletions tests/data/comments3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# The percent-percent comments are Spyder IDE cells.

#%%
def func():
x = """
a really long string
Expand Down Expand Up @@ -39,3 +42,6 @@ def func():
# shared between sub-exceptions are not omitted
_seen=set(_seen),
)


#%%

0 comments on commit 484a84c

Please sign in to comment.