MCPcopy Index your code
hub / github.com/python/cpython / reformat_comment

Function reformat_comment

Lib/idlelib/format.py:156–176  ·  view source on GitHub ↗

Return data reformatted to specified width with comment header.

(data, limit, comment_header)

Source from the content-addressed store, hash-verified

154 return "\n".join(new)
155
156def reformat_comment(data, limit, comment_header):
157 """Return data reformatted to specified width with comment header."""
158
159 # Remove header from the comment lines
160 lc = len(comment_header)
161 data = "\n".join(line[lc:] for line in data.split("\n"))
162 # Reformat to maxformatwidth chars or a 20 char width,
163 # whichever is greater.
164 format_width = max(limit - len(comment_header), 20)
165 newdata = reformat_paragraph(data, format_width)
166 # re-split and re-insert the comment header.
167 newdata = newdata.split("\n")
168 # If the block ends in a \n, we don't want the comment prefix
169 # inserted after it. (Im not sure it makes sense to reformat a
170 # comment block that is not made of complete lines, but whatever!)
171 # Can't think of a clean solution, so we hack away
172 block_suffix = ""
173 if not newdata[-1]:
174 block_suffix = "\n"
175 newdata = newdata[:-1]
176 return '\n'.join(comment_header+line for line in newdata) + block_suffix
177
178def is_all_white(line):
179 """Return True if line is empty or all whitespace."""

Callers 1

Calls 3

reformat_paragraphFunction · 0.85
joinMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…