Skip to content

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

@jonathanslenders

Description

@jonathanslenders

Bug report

Consider this code:

from asyncio import run, TaskGroup async def bad_function(): raise ZeroDivisionError async def bad_function2(): raise KeyError async def main(): try: async with TaskGroup() as tg: tg.create_task(bad_function()) tg.create_task(bad_function2()) except* ZeroDivisionError as e: 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 run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 118, in run return self._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_complete return 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_dispatch return self.dispatch_return(frame, arg) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/bdb.py", line 153, in dispatch_return self.user_return(frame, arg) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/pdb.py", line 372, in user_return self.interaction(frame, None) File "/home/jonathan/.pyenv/versions/3.11.0/lib/python3.11/pdb.py", line 434, in interaction self.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_entry self.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 getline if 1 <= 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