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)
| 2067 | print(self.InteractiveTB.stb2text(stb)) |
| 2068 | |
| 2069 | def showsyntaxerror(self, filename=None, running_compiled_code=False): |
| 2070 | """Display the syntax error that just occurred. |
| 2071 | |
| 2072 | This doesn't display a stack trace because there isn't one. |
| 2073 | |
| 2074 | If a filename is given, it is stuffed in the exception instead |
| 2075 | of what was there before (because Python's parser always uses |
| 2076 | "<string>" when reading from a string). |
| 2077 | |
| 2078 | If the syntax error occurred when running a compiled code (i.e. running_compile_code=True), |
| 2079 | longer stack trace will be displayed. |
| 2080 | """ |
| 2081 | etype, value, last_traceback = self._get_exc_info() |
| 2082 | |
| 2083 | if filename and issubclass(etype, SyntaxError): |
| 2084 | try: |
| 2085 | value.filename = filename |
| 2086 | except: |
| 2087 | # Not the format we expect; leave it alone |
| 2088 | pass |
| 2089 | |
| 2090 | # If the error occurred when executing compiled code, we should provide full stacktrace. |
| 2091 | elist = traceback.extract_tb(last_traceback) if running_compiled_code else [] |
| 2092 | stb = self.SyntaxTB.structured_traceback(etype, value, elist) |
| 2093 | self._showtraceback(etype, value, stb) |
| 2094 | |
| 2095 | # This is overridden in TerminalInteractiveShell to show a message about |
| 2096 | # the %paste magic. |