Skip to content

Commit

Permalink
Fix AssertionError on "..." outside of a continuation prompt
Browse files Browse the repository at this point in the history
Thanks @Zac-HD for the report and fix!

Fixes #69
  • Loading branch information
jdufresne committed Jan 5, 2021
1 parent 0cc1c71 commit 4d8d7fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions blacken_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def finish_fragment() -> None:
for line in match['code'].splitlines():
orig_line, line = line, line.lstrip()
continuation_match = PYCON_CONTINUATION_RE.match(line)
if continuation_match:
assert fragment is not None
if continuation_match and fragment is not None:
fragment += line[continuation_match.end():] + '\n'
else:
finish_fragment()
Expand Down
13 changes: 13 additions & 0 deletions tests/blacken_docs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,16 @@ def test_format_src_rst_pycon_preserves_output_indentation():
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == before


def test_format_src_rst_pycon_elided_traceback():
before = (
'.. code-block:: pycon\n'
'\n'
' >>> 1 / 0\n'
' Traceback (most recent call last):\n'
' ...\n'
' ZeroDivisionError: division by zero\n'
)
after, _ = blacken_docs.format_str(before, BLACK_MODE)
assert after == before

0 comments on commit 4d8d7fe

Please sign in to comment.