[New-bugs-announce] [issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension

Thomas Grainger report at bugs.python.org
Thu Jun 17 14:49:12 EDT 2021


New submission from Thomas Grainger <tagrain at gmail.com>:

demo:

import traceback
import io

async def foo():
    yield 1
    traceback.print_stack(file=io.StringIO())
    yield 2

async def bar():
    return [chunk async for chunk in foo()]


next(bar().__await__(), None)
print("working!")


Traceback (most recent call last):
  File "/home/graingert/projects/anyio/foo.py", line 13, in <module>
    next(bar().__await__(), None)
  File "/home/graingert/projects/anyio/foo.py", line 10, in bar
    return [chunk async for chunk in foo()]
  File "/home/graingert/projects/anyio/foo.py", line -1, in <listcomp>
  File "/home/graingert/projects/anyio/foo.py", line 6, in foo
    traceback.print_stack(file=io.StringIO())
  File "/usr/lib/python3.10/traceback.py", line 203, in print_stack
    print_list(extract_stack(f, limit=limit), file=file)
  File "/usr/lib/python3.10/traceback.py", line 224, in extract_stack
    stack = StackSummary.extract(walk_stack(f), limit=limit)
  File "/usr/lib/python3.10/traceback.py", line 379, in extract
    f.line
  File "/usr/lib/python3.10/traceback.py", line 301, in line
    self._line = linecache.getline(self.filename, self.lineno).strip()
  File "/usr/lib/python3.10/linecache.py", line 31, in getline
    if 1 <= lineno <= len(lines):
TypeError: '<=' not supported between instances of 'int' and 'NoneType'

----------
messages: 396014
nosy: graingert
priority: normal
severity: normal
status: open
title: linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________


More information about the New-bugs-announce mailing list