MCPcopy Index your code
hub / github.com/bpython/bpython / showsyntaxerror

Method showsyntaxerror

bpython/repl.py:154–173  ·  view source on GitHub ↗

Override the regular handler, the code's copied and pasted from code.py, as per showtraceback, but with the syntaxerror callback called and the text in a pretty colour.

(self, filename: str | None = None, **kwargs)

Source from the content-addressed store, hash-verified

152 return super().runsource(source, filename, symbol)
153
154 def showsyntaxerror(self, filename: str | None = None, **kwargs) -> None:
155 """Override the regular handler, the code's copied and pasted from
156 code.py, as per showtraceback, but with the syntaxerror callback called
157 and the text in a pretty colour."""
158 if self.syntaxerror_callback is not None:
159 self.syntaxerror_callback()
160
161 exc_type, value, sys.last_traceback = sys.exc_info()
162 sys.last_type = exc_type
163 sys.last_value = value
164 if filename and exc_type is SyntaxError and value is not None:
165 msg = value.args[0]
166 args = list(value.args[1])
167 # strip linechache line number
168 if self.bpython_input_re.match(filename):
169 args[0] = "<input>"
170 value = SyntaxError(msg, tuple(args))
171 sys.last_value = value
172 exc_formatted = traceback.format_exception_only(exc_type, value)
173 self.writetb(exc_formatted)
174
175 def showtraceback(self) -> None:
176 """This needs to override the default traceback thing

Callers

nothing calls this directly

Calls 2

writetbMethod · 0.95
matchMethod · 0.80

Tested by

no test coverage detected