MCPcopy
hub / github.com/openai/openai-python / finish_fragment

Function finish_fragment

scripts/utils/ruffen-docs.py:56–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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():

Callers 1

_pycon_matchFunction · 0.85

Calls 2

_collect_errorFunction · 0.85
format_code_blockFunction · 0.85

Tested by

no test coverage detected