Stability fixup: interaction between newlines and comments (#1975)
* Add test case to illustrate the issue * Accept carriage returns as valid separators while enumerating comments Without this acceptance, escaped multi-line statments that use carriage returns will not be counted into the 'ignored_lines' variable since the emitted line values will end with a CR and not an escape character. That leads to comments associated with the line being incorrectly labeled with the STANDALONE_COMMENT type, affecting comment placement and line space management. * Remove comment linking to ephemeral build log
This commit is contained in:
parent
2d0c14989d
commit
b8c1020b52
@ -2635,7 +2635,7 @@ def list_comments(prefix: str, *, is_endmarker: bool) -> List[ProtoComment]:
|
||||
consumed = 0
|
||||
nlines = 0
|
||||
ignored_lines = 0
|
||||
for index, line in enumerate(prefix.split("\n")):
|
||||
for index, line in enumerate(re.split("\r?\n", prefix)):
|
||||
consumed += len(line) + 1 # adding the length of the split '\n'
|
||||
line = line.lstrip()
|
||||
if not line:
|
||||
|
@ -1793,6 +1793,11 @@ def test_bpo_33660_workaround(self) -> None:
|
||||
finally:
|
||||
os.chdir(str(old_cwd))
|
||||
|
||||
def test_newline_comment_interaction(self) -> None:
|
||||
source = "class A:\\\r\n# type: ignore\n pass\n"
|
||||
output = black.format_str(source, mode=DEFAULT_MODE)
|
||||
black.assert_stable(source, output, mode=DEFAULT_MODE)
|
||||
|
||||
|
||||
with open(black.__file__, "r", encoding="utf-8") as _bf:
|
||||
black_source_lines = _bf.readlines()
|
||||
|
Loading…
Reference in New Issue
Block a user