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

Method runsource

Lib/code.py:39–76  ·  view source on GitHub ↗

Compile and run some source in the interpreter. Arguments are as for compile_command(). One of several things can happen: 1) The input is incorrect; compile_command() raised an exception (SyntaxError or OverflowError). A syntax traceback will be printed by

(self, source, filename="<input>", symbol="single")

Source from the content-addressed store, hash-verified

37 self.compile = CommandCompiler()
38
39 def runsource(self, source, filename="<input>", symbol="single"):
40 """Compile and run some source in the interpreter.
41
42 Arguments are as for compile_command().
43
44 One of several things can happen:
45
46 1) The input is incorrect; compile_command() raised an
47 exception (SyntaxError or OverflowError). A syntax traceback
48 will be printed by calling the showsyntaxerror() method.
49
50 2) The input is incomplete, and more input is required;
51 compile_command() returned None. Nothing happens.
52
53 3) The input is complete; compile_command() returned a code
54 object. The code is executed by calling self.runcode() (which
55 also handles run-time exceptions, except for SystemExit).
56
57 The return value is True in case 2, False in the other cases (unless
58 an exception is raised). The return value can be used to
59 decide whether to use sys.ps1 or sys.ps2 to prompt the next
60 line.
61
62 """
63 try:
64 code = self.compile(source, filename, symbol)
65 except (OverflowError, SyntaxError, ValueError):
66 # Case 1
67 self.showsyntaxerror(filename, source=source)
68 return False
69
70 if code is None:
71 # Case 2
72 return True
73
74 # Case 3
75 self.runcode(code)
76 return False
77
78 def runcode(self, code):
79 """Execute a code object.

Callers 1

pushMethod · 0.45

Calls 3

showsyntaxerrorMethod · 0.95
runcodeMethod · 0.95
compileMethod · 0.45

Tested by

no test coverage detected