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

Method showsyntaxerror

IPython/core/interactiveshell.py:2260–2284  ·  view source on GitHub ↗

Display the syntax error that just occurred. This doesn't display a stack trace because there isn't one. If a filename is given, it is stuffed in the exception instead of what was there before (because Python's parser always uses " " when reading from a strin

(self, filename=None, running_compiled_code=False)

Source from the content-addressed store, hash-verified

2258 self.showing_traceback = False
2259
2260 def showsyntaxerror(self, filename=None, running_compiled_code=False):
2261 """Display the syntax error that just occurred.
2262
2263 This doesn't display a stack trace because there isn't one.
2264
2265 If a filename is given, it is stuffed in the exception instead
2266 of what was there before (because Python's parser always uses
2267 "<string>" when reading from a string).
2268
2269 If the syntax error occurred when running a compiled code (i.e. running_compile_code=True),
2270 longer stack trace will be displayed.
2271 """
2272 etype, value, last_traceback = self._get_exc_info()
2273
2274 if filename and issubclass(etype, SyntaxError):
2275 try:
2276 value.filename = filename
2277 except:
2278 # Not the format we expect; leave it alone
2279 pass
2280
2281 # If the error occurred when executing compiled code, we should provide full stacktrace.
2282 elist = traceback.extract_tb(last_traceback) if running_compiled_code else []
2283 stb = self.SyntaxTB.structured_traceback(etype, value, elist)
2284 self._showtraceback(etype, value, stb)
2285
2286 # This is overridden in TerminalInteractiveShell to show a message about
2287 # the %paste magic.

Callers 5

showtracebackMethod · 0.95
showindentationerrorMethod · 0.95
run_cell_asyncMethod · 0.95
test_non_syntaxerrorMethod · 0.80

Calls 3

_get_exc_infoMethod · 0.95
_showtracebackMethod · 0.95
structured_tracebackMethod · 0.45

Tested by 2

test_non_syntaxerrorMethod · 0.64