Skip to content

Bug in linecache when raising exceptiongroup that contains ZeroDivisionError + other exception.#101517

@jonathanslenders

Description

@jonathanslenders

Bug report

Consider this code:

fromasyncioimportrun, TaskGroupasyncdefbad_function(): raiseZeroDivisionErrorasyncdefbad_function2(): raiseKeyErrorasyncdefmain(): try: asyncwithTaskGroup() astg: tg.create_task(bad_function()) tg.create_task(bad_function2()) except* ZeroDivisionErrorase: breakpoint() run(main())

Run it on Python 3.11 or 3.12:

--Return-- Traceback (most recent call last): File "....py", line 18, in <module> run(main()) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 190, in runreturn runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 118, in runreturnself._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 650, in run_until_completereturn future.result() ^^^^^^^^^^^^^^^ File ".....py", line -1, in main File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/bdb.py", line 94, in trace_dispatchreturnself.dispatch_return(frame, arg) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/bdb.py", line 153, in dispatch_returnself.user_return(frame, arg) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/pdb.py", line 372, in user_returnself.interaction(frame, None) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/pdb.py", line 434, in interactionself.print_stack_entry(self.stack[self.curindex]) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/pdb.py", line 1554, in print_stack_entryself.format_stack_entry(frame_lineno, prompt_prefix)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/bdb.py", line 573, in format_stack_entry line = linecache.getline(filename, lineno, frame.f_globals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/linecache.py", line 31, in getlineif1<= lineno <=len(lines): TypeError: '<=' not supported between instances of 'int' and 'NoneType'

One of the exceptions has to be a ZeroDivisionError for it to happen as far as I can see.

Your environment

  • CPython versions tested on: 3.11, 3.12
  • Operating system and architecture: Linux, M1, arm64

Linked PRs

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions