From: Ɓukasz Langa Date: Wed, 26 Sep 2018 16:42:42 +0000 (-0700) Subject: Fix mangling pweave and Spyder IDE special comments X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/c6c8ef76a4d991cd8a7a3b00a816b6db72ecdf04?ds=sidebyside Fix mangling pweave and Spyder IDE special comments Fixes #532. --- diff --git a/README.md b/README.md index 75cc1a5..bc684ec 100644 --- a/README.md +++ b/README.md @@ -953,6 +953,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) diff --git a/black.py b/black.py index 692f6d5..d4b3985 100644 --- a/black.py +++ b/black.py @@ -2082,8 +2082,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. """ @@ -2093,7 +2093,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 diff --git a/tests/data/comments.py b/tests/data/comments.py index 8ce9ffe..4ae3d2c 100644 --- a/tests/data/comments.py +++ b/tests/data/comments.py @@ -70,6 +70,9 @@ class Foo: """Docstring for instance attribute spam.""" +#'

This is pweave!

+ + @fast(really=True) async def wat(): async with X.open_async() as x: # Some more comments diff --git a/tests/data/comments3.py b/tests/data/comments3.py index e95bd21..fbbef6d 100644 --- a/tests/data/comments3.py +++ b/tests/data/comments3.py @@ -1,3 +1,6 @@ +# The percent-percent comments are Spyder IDE cells. + +#%% def func(): x = """ a really long string @@ -39,3 +42,6 @@ def func(): # shared between sub-exceptions are not omitted _seen=set(_seen), ) + + +#%% \ No newline at end of file