MCPcopy
hub / github.com/prompt-toolkit/ptpython / run_and_show_expression

Method run_and_show_expression

src/ptpython/repl.py:102–139  ·  view source on GitHub ↗
(self, expression: str)

Source from the content-addressed store, hash-verified

100 output.write(f"WARNING | File not found: {path}\n\n")
101
102 def run_and_show_expression(self, expression: str) -> None:
103 try:
104 # Eval.
105 try:
106 result = self.eval(expression)
107 except KeyboardInterrupt:
108 # KeyboardInterrupt doesn't inherit from Exception.
109 raise
110 except SystemExit:
111 raise
112 except ReplExit:
113 raise
114 except BaseException as e:
115 self._handle_exception(e)
116 else:
117 if isinstance(result, exit):
118 # When `exit` is evaluated without parentheses.
119 # Automatically trigger the `ReplExit` exception.
120 raise ReplExit
121
122 # Print.
123 if result is not None:
124 self._show_result(result)
125 if self.insert_blank_line_after_output:
126 self.app.output.write("\n")
127
128 # Loop.
129 self.current_statement_index += 1
130 self.signatures = []
131
132 except KeyboardInterrupt as e:
133 # Handle all possible `KeyboardInterrupt` errors. This can
134 # happen during the `eval`, but also during the
135 # `show_result` if something takes too long.
136 # (Try/catch is around the whole block, because we want to
137 # prevent that a Control-C keypress terminates the REPL in
138 # any case.)
139 self._handle_keyboard_interrupt(e)
140
141 def _get_output_printer(self) -> OutputPrinter:
142 return OutputPrinter(

Callers 1

runMethod · 0.95

Calls 5

evalMethod · 0.95
_handle_exceptionMethod · 0.95
_show_resultMethod · 0.95
writeMethod · 0.45

Tested by

no test coverage detected