Display the syntax error that just occurred.
(self, filename=None)
| 500 | sys.stderr.write(data) |
| 501 | |
| 502 | def showsyntaxerror(self, filename=None): |
| 503 | """Display the syntax error that just occurred.""" |
| 504 | # Override for avoid using sys.excepthook PY-12600 |
| 505 | type, value, tb = sys.exc_info() |
| 506 | sys.last_type = type |
| 507 | sys.last_value = value |
| 508 | sys.last_traceback = tb |
| 509 | if filename and type is SyntaxError: |
| 510 | # Work hard to stuff the correct filename in the exception |
| 511 | try: |
| 512 | msg, (dummy_filename, lineno, offset, line) = value.args |
| 513 | except ValueError: |
| 514 | # Not the format we expect; leave it alone |
| 515 | pass |
| 516 | else: |
| 517 | # Stuff in the right filename |
| 518 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
| 519 | sys.last_value = value |
| 520 | list = traceback.format_exception_only(type, value) |
| 521 | sys.stderr.write("".join(list)) |
| 522 | |
| 523 | def showtraceback(self, *args, **kwargs): |
| 524 | """Display the exception that just occurred.""" |
no test coverage detected