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