Skip to content

Commit

Permalink
dont skip formatting #%%
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 14, 2022
1 parent 71e71e5 commit 1059de1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -10,6 +10,8 @@

<!-- Changes that affect Black's stable style -->

- Code cell separators `#%%` are now standardised to `# %%` (#2919)

### Preview style

<!-- Changes that affect Black's preview style -->
Expand Down
4 changes: 2 additions & 2 deletions src/black/comments.py
Expand Up @@ -105,7 +105,7 @@ 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
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 @@ -123,7 +123,7 @@ def make_comment(content: str) -> str:
and not content.lstrip().startswith("type:")
):
content = " " + content[1:] # Replace NBSP by a simple space
if content and content[0] not in " !:#'%":
if content and content[0] not in " !:#'":
content = " " + content
return "#" + content

Expand Down
56 changes: 55 additions & 1 deletion tests/data/comments3.py
@@ -1,4 +1,6 @@
# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.

#%%
def func():
Expand Down Expand Up @@ -44,4 +46,56 @@ def func():
)


#%%
#%%

# output

# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.

# %%
def func():
x = """
a really long string
"""
lcomp3 = [
# This one is actually too long to fit in a single line.
element.split("\n", 1)[0]
# yup
for element in collection.select_elements()
# right
if element is not None
]
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
if isinstance(exc_value, MultiError):
embedded = []
for exc in exc_value.exceptions:
if exc not in _seen:
embedded.append(
# This should be left alone (before)
traceback.TracebackException.from_exception(
exc,
limit=limit,
lookup_lines=lookup_lines,
capture_locals=capture_locals,
# copy the set of _seen exceptions so that duplicates
# shared between sub-exceptions are not omitted
_seen=set(_seen),
)
# This should be left alone (after)
)

# everything is fine if the expression isn't nested
traceback.TracebackException.from_exception(
exc,
limit=limit,
lookup_lines=lookup_lines,
capture_locals=capture_locals,
# copy the set of _seen exceptions so that duplicates
# shared between sub-exceptions are not omitted
_seen=set(_seen),
)


# %%

0 comments on commit 1059de1

Please sign in to comment.