MCPcopy Index your code
hub / github.com/RustPython/RustPython / runsource

Method runsource

Lib/_pyrepl/console.py:176–213  ·  view source on GitHub ↗
(self, source, filename="<input>", symbol="single")

Source from the content-addressed store, hash-verified

174 self.write(''.join(lines))
175
176 def runsource(self, source, filename="<input>", symbol="single"):
177 try:
178 tree = self.compile.compiler(
179 source,
180 filename,
181 "exec",
182 ast.PyCF_ONLY_AST,
183 incomplete_input=False,
184 )
185 except (SyntaxError, OverflowError, ValueError):
186 self.showsyntaxerror(filename, source=source)
187 return False
188 if tree.body:
189 *_, last_stmt = tree.body
190 for stmt in tree.body:
191 wrapper = ast.Interactive if stmt is last_stmt else ast.Module
192 the_symbol = symbol if stmt is last_stmt else "exec"
193 item = wrapper([stmt])
194 try:
195 code = self.compile.compiler(item, filename, the_symbol)
196 except SyntaxError as e:
197 if e.args[0] == "'await' outside function":
198 python = os.path.basename(sys.executable)
199 e.add_note(
200 f"Try the asyncio REPL ({python} -m asyncio) to use"
201 f" top-level 'await' and run background asyncio tasks."
202 )
203 self.showsyntaxerror(filename, source=source)
204 return False
205 except (OverflowError, ValueError):
206 self.showsyntaxerror(filename, source=source)
207 return False
208
209 if code is None:
210 return True
211
212 self.runcode(code)
213 return False

Callers

nothing calls this directly

Calls 5

showsyntaxerrorMethod · 0.95
basenameMethod · 0.80
add_noteMethod · 0.80
wrapperFunction · 0.50
runcodeMethod · 0.45

Tested by

no test coverage detected