Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Running the code sample from#122071 in 3.13.0b4 or main exits the interpreter due totraceback.StackSummary._should_show_carets raising an exception:
>>>exec(compile("tuple()[0]","s","exec"))Traceback (mostrecentcalllast):Exceptionignoredintheinternaltracebackmachinery:Traceback (mostrecentcalllast):File"~\PycharmProjects\cpython\Lib\traceback.py",line139,in_print_exception_bltinreturnprint_exception(exc,limit=BUILTIN_EXCEPTION_LIMIT,file=file,colorize=colorize)File"~\PycharmProjects\cpython\Lib\traceback.py",line130,inprint_exceptionte.print(file=file,chain=chain,colorize=colorize)File"~\PycharmProjects\cpython\Lib\traceback.py",line1448,inprintforlineinself.format(chain=chain,colorize=colorize):File"~\PycharmProjects\cpython\Lib\traceback.py",line1384,informatyieldfrom_ctx.emit(exc.stack.format(colorize=colorize))File"~\PycharmProjects\cpython\Lib\traceback.py",line747,informatformatted_frame=self.format_frame_summary(frame_summary,colorize=colorize)File"~\PycharmProjects\cpython\Lib\traceback.py",line583,informat_frame_summaryshow_carets=self._should_show_carets(start_offset,end_offset,all_lines,anchors)File"~\PycharmProjects\cpython\Lib\traceback.py",line701,in_should_show_caretsstatement=tree.body[0]IndexError:listindexoutofrangeTraceback (mostrecentcalllast):File"~\PycharmProjects\cpython\Lib\code.py",line91,inruncodeexec(code,self.locals)File"<python-input-2>",line1,in<module>File"s",line1,in<module>IndexError:tupleindexoutofrangeDuringhandlingoftheaboveexception,anotherexceptionoccurred:Traceback (mostrecentcalllast):File"~\PycharmProjects\cpython\Lib\runpy.py",line198,in_run_module_as_mainreturn_run_code(code,main_globals,None,File"~\PycharmProjects\cpython\Lib\runpy.py",line88,in_run_codeexec(code,run_globals)File"~\PycharmProjects\cpython\Lib\_pyrepl\__main__.py",line6,in<module>__pyrepl_interactive_console()File"~\PycharmProjects\cpython\Lib\_pyrepl\main.py",line59,ininteractive_consolerun_multiline_interactive_console(console)File"~\PycharmProjects\cpython\Lib\_pyrepl\simple_interact.py",line156,inrun_multiline_interactive_consolemore=console.push(_strip_final_indent(statement),filename=input_name,_symbol="single")# type: ignore[call-arg]File"~\PycharmProjects\cpython\Lib\code.py",line303,inpushmore=self.runsource(source,filename,symbol=_symbol)File"~\PycharmProjects\cpython\Lib\_pyrepl\console.py",line200,inrunsourceself.runcode(code)File"~\PycharmProjects\cpython\Lib\code.py",line95,inruncodeself.showtraceback()File"~\PycharmProjects\cpython\Lib\_pyrepl\console.py",line168,inshowtracebacksuper().showtraceback(colorize=self.can_colorize)File"~\PycharmProjects\cpython\Lib\code.py",line147,inshowtracebacklines=traceback.format_exception(ei[0],ei[1],last_tb.tb_next,colorize=colorize)File"~\PycharmProjects\cpython\Lib\traceback.py",line155,informat_exceptionreturnlist(te.format(chain=chain,colorize=colorize))File"~\PycharmProjects\cpython\Lib\traceback.py",line1384,informatyieldfrom_ctx.emit(exc.stack.format(colorize=colorize))File"~\PycharmProjects\cpython\Lib\traceback.py",line747,informatformatted_frame=self.format_frame_summary(frame_summary,colorize=colorize)File"~\PycharmProjects\cpython\Lib\traceback.py",line583,informat_frame_summaryshow_carets=self._should_show_carets(start_offset,end_offset,all_lines,anchors)File"~\PycharmProjects\cpython\Lib\traceback.py",line701,in_should_show_caretsstatement=tree.body[0]IndexError:listindexoutofrange[Thread31424.0x8ec0exitedwithcode1][Thread31424.0x15dcexitedwithcode1][Thread31424.0x8b8cexitedwithcode1][Inferior1 (process31424)exitedwithcode01]
We can either protect the_should_show_carets call withsuppress(Exception) here:
Lines 581 to 583 in2762c6c
| withsuppress(Exception): | |
| anchors=_extract_caret_anchors_from_line_segment(segment) | |
| show_carets=self._should_show_carets(start_offset,end_offset,all_lines,anchors) |
Or guard againsttree.body being empty here:
Lines 700 to 701 in2762c6c
| tree=ast.parse('\n'.join(all_lines)) | |
| statement=tree.body[0] |
(or both?)
Should I submit a PR with one of the fixes above? Any preferences?
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Windows, Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done