Fix mangling pweave and Spyder IDE special comments

Fixes #532.
This commit is contained in:
Łukasz Langa 2018-09-26 09:42:42 -07:00
parent 9372dc8510
commit c6c8ef76a4
No known key found for this signature in database
GPG Key ID: B26995E310250568
4 changed files with 15 additions and 3 deletions

View File

@ -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 * cache is now populated when `--check` is successful for a file which speeds up
consecutive checks of properly formatted unmodified files (#448) 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 unstable formatting when unpacking big tuples (#267)
* fixed parsing of `__future__` imports with renames (#389) * fixed parsing of `__future__` imports with renames (#389)

View File

@ -2082,8 +2082,8 @@ def list_comments(prefix: str, *, is_endmarker: bool) -> List[ProtoComment]:
def make_comment(content: str) -> str: def make_comment(content: str) -> str:
"""Return a consistently formatted comment from the given `content` string. """Return a consistently formatted comment from the given `content` string.
All comments (except for "##", "#!", "#:") should have a single space between All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
the hash sign and the content. space between the hash sign and the content.
If `content` didn't start with a hash sign, one is provided. 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] == "#": if content[0] == "#":
content = content[1:] content = content[1:]
if content and content[0] not in " !:#": if content and content[0] not in " !:#'%":
content = " " + content content = " " + content
return "#" + content return "#" + content

View File

@ -70,6 +70,9 @@ def __init__(self):
"""Docstring for instance attribute spam.""" """Docstring for instance attribute spam."""
#' <h1>This is pweave!</h1>
@fast(really=True) @fast(really=True)
async def wat(): async def wat():
async with X.open_async() as x: # Some more comments async with X.open_async() as x: # Some more comments

View File

@ -1,3 +1,6 @@
# The percent-percent comments are Spyder IDE cells.
#%%
def func(): def func():
x = """ x = """
a really long string a really long string
@ -39,3 +42,6 @@ def func():
# shared between sub-exceptions are not omitted # shared between sub-exceptions are not omitted
_seen=set(_seen), _seen=set(_seen),
) )
#%%