MCPcopy Index your code
hub / github.com/python/cpython / showsyntaxerror

Method showsyntaxerror

Lib/idlelib/pyshell.py:709–733  ·  view source on GitHub ↗

Override Interactive Interpreter method: Use Colorizing Color the offending position instead of printing it and pointing at it with a caret.

(self, filename=None, **kwargs)

Source from the content-addressed store, hash-verified

707 \n""".format(filename))
708
709 def showsyntaxerror(self, filename=None, **kwargs):
710 """Override Interactive Interpreter method: Use Colorizing
711
712 Color the offending position instead of printing it and pointing at it
713 with a caret.
714
715 """
716 tkconsole = self.tkconsole
717 text = tkconsole.text
718 text.tag_remove("ERROR", "1.0", "end")
719 type, value, tb = sys.exc_info()
720 msg = getattr(value, 'msg', '') or value or "<no detail available>"
721 lineno = getattr(value, 'lineno', '') or 1
722 offset = getattr(value, 'offset', '') or 0
723 if offset == 0:
724 lineno += 1 #mark end of offending line
725 if lineno == 1:
726 pos = "iomark + %d chars" % (offset-1)
727 else:
728 pos = "iomark linestart + %d lines + %d chars" % \
729 (lineno-1, offset-1)
730 tkconsole.colorize_syntax_error(text, pos)
731 tkconsole.resetoutput()
732 self.write("SyntaxError: %s\n" % msg)
733 tkconsole.showprompt()
734
735 def showtraceback(self):
736 "Extend base class method to reset output properly"

Callers 1

execfileMethod · 0.45

Calls 5

writeMethod · 0.95
colorize_syntax_errorMethod · 0.80
resetoutputMethod · 0.80
showpromptMethod · 0.80
tag_removeMethod · 0.45

Tested by

no test coverage detected