(self, source, filename="<input>", symbol="single")
| 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 |
nothing calls this directly
no test coverage detected