Skip to content

Commit e89af29

Browse files
committed
dont skip formatting #%%
1 parent 71e71e5 commit e89af29

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

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

13+
- Code cell separators `#%%` are now standardised to `# %%` (#2919)
14+
1315
### Preview style
1416

1517
<!-- Changes that affect Black's preview style -->

src/black/comments.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ def list_comments(prefix: str, *, is_endmarker: bool) -> List[ProtoComment]:
105105
def make_comment(content: str) -> str:
106106
"""Return a consistently formatted comment from the given `content` string.
107107
108-
All comments (except for "##", "#!", "#:", '#'", "#%%") should have a single
108+
All comments (except for "##", "#!", "#:", '#'") should have a single
109109
space between the hash sign and the content.
110110
111111
If `content` didn't start with a hash sign, one is provided.
112112
"""
113113
content = content.rstrip()
114114
if not content:
115115
return "#"
116-
117116
if content[0] == "#":
118117
content = content[1:]
119118
NON_BREAKING_SPACE = " "
@@ -123,7 +122,7 @@ def make_comment(content: str) -> str:
123122
and not content.lstrip().startswith("type:")
124123
):
125124
content = " " + content[1:] # Replace NBSP by a simple space
126-
if content and content[0] not in " !:#'%":
125+
if content and content[0] not in " !:#'":
127126
content = " " + content
128127
return "#" + content
129128

tests/data/comments3.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# The percent-percent comments are Spyder IDE cells.
2+
# Both `#%%`` and `# %%` are accepted, so `black` standardises
3+
# to the latter.
24

35
#%%
46
def func():
@@ -44,4 +46,56 @@ def func():
4446
)
4547

4648

47-
#%%
49+
#%%
50+
51+
# output
52+
53+
# The percent-percent comments are Spyder IDE cells.
54+
# Both `#%%`` and `# %%` are accepted, so `black` standardises
55+
# to the latter.
56+
57+
# %%
58+
def func():
59+
x = """
60+
a really long string
61+
"""
62+
lcomp3 = [
63+
# This one is actually too long to fit in a single line.
64+
element.split("\n", 1)[0]
65+
# yup
66+
for element in collection.select_elements()
67+
# right
68+
if element is not None
69+
]
70+
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
71+
if isinstance(exc_value, MultiError):
72+
embedded = []
73+
for exc in exc_value.exceptions:
74+
if exc not in _seen:
75+
embedded.append(
76+
# This should be left alone (before)
77+
traceback.TracebackException.from_exception(
78+
exc,
79+
limit=limit,
80+
lookup_lines=lookup_lines,
81+
capture_locals=capture_locals,
82+
# copy the set of _seen exceptions so that duplicates
83+
# shared between sub-exceptions are not omitted
84+
_seen=set(_seen),
85+
)
86+
# This should be left alone (after)
87+
)
88+
89+
# everything is fine if the expression isn't nested
90+
traceback.TracebackException.from_exception(
91+
exc,
92+
limit=limit,
93+
lookup_lines=lookup_lines,
94+
capture_locals=capture_locals,
95+
# copy the set of _seen exceptions so that duplicates
96+
# shared between sub-exceptions are not omitted
97+
_seen=set(_seen),
98+
)
99+
100+
101+
# %%

0 commit comments

Comments
 (0)