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

Method checksyntax

Lib/idlelib/runscript.py:79–107  ·  view source on GitHub ↗
(self, filename)

Source from the content-addressed store, hash-verified

77 return True
78
79 def checksyntax(self, filename):
80 self.shell = shell = self.flist.open_shell()
81 saved_stream = shell.get_warning_stream()
82 shell.set_warning_stream(shell.stderr)
83 with open(filename, 'rb') as f:
84 source = f.read()
85 if b'\r' in source:
86 source = source.replace(b'\r\n', b'\n')
87 source = source.replace(b'\r', b'\n')
88 if source and source[-1] != ord(b'\n'):
89 source = source + b'\n'
90 editwin = self.editwin
91 text = editwin.text
92 text.tag_remove("ERROR", "1.0", "end")
93 try:
94 # If successful, return the compiled code
95 return compile(source, filename, "exec")
96 except (SyntaxError, OverflowError, ValueError) as value:
97 msg = getattr(value, 'msg', '') or value or "<no detail available>"
98 lineno = getattr(value, 'lineno', '') or 1
99 offset = getattr(value, 'offset', '') or 0
100 if offset == 0:
101 lineno += 1 #mark end of offending line
102 pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
103 editwin.colorize_syntax_error(text, pos)
104 self.errorbox("SyntaxError", "%-20s" % msg)
105 return False
106 finally:
107 shell.set_warning_stream(saved_stream)
108
109 def run_custom_event(self, event):
110 return self.run_module_event(event, customize=True)

Callers 2

check_module_eventMethod · 0.95
run_module_eventMethod · 0.95

Calls 10

errorboxMethod · 0.95
open_shellMethod · 0.80
get_warning_streamMethod · 0.80
set_warning_streamMethod · 0.80
colorize_syntax_errorMethod · 0.80
openFunction · 0.50
compileFunction · 0.50
readMethod · 0.45
replaceMethod · 0.45
tag_removeMethod · 0.45

Tested by

no test coverage detected