()
| 54 | fragment = cast(Optional[str], None) |
| 55 | |
| 56 | def finish_fragment() -> None: |
| 57 | nonlocal code |
| 58 | nonlocal fragment |
| 59 | |
| 60 | if fragment is not None: |
| 61 | with _collect_error(match): |
| 62 | fragment = format_code_block(fragment) |
| 63 | fragment_lines = fragment.splitlines() |
| 64 | code += f"{PYCON_PREFIX}{fragment_lines[0]}\n" |
| 65 | for line in fragment_lines[1:]: |
| 66 | # Skip blank lines to handle Black adding a blank above |
| 67 | # functions within blocks. A blank line would end the REPL |
| 68 | # continuation prompt. |
| 69 | # |
| 70 | # >>> if True: |
| 71 | # ... def f(): |
| 72 | # ... pass |
| 73 | # ... |
| 74 | if line: |
| 75 | code += f"{PYCON_CONTINUATION_PREFIX} {line}\n" |
| 76 | if fragment_lines[-1].startswith(" "): |
| 77 | code += f"{PYCON_CONTINUATION_PREFIX}\n" |
| 78 | fragment = None |
| 79 | |
| 80 | indentation = None |
| 81 | for line in match["code"].splitlines(): |
no test coverage detected