Mailing List Archive

[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension
New submission from Thomas Grainger <tagrain@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@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Ned Batchelder <ned@nedbatchelder.com>:


----------
nosy: +nedbat

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Thomas Grainger <tagrain@gmail.com>:


----------
nosy: +Mark.Shannon -nedbat

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Thomas Grainger <tagrain@gmail.com>:


----------
nosy: +nedbat

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Filipe Laíns <lains@riseup.net>:


----------
nosy: +iritkatriel

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Filipe Laíns <lains@riseup.net>:


----------
keywords: +patch
nosy: +FFY00
nosy_count: 4.0 -> 5.0
pull_requests: +25366
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/26781

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Filipe Laíns <lains@riseup.net> added the comment:

I bissected this to 088a15c49d99ecb4c3bef93f8f40dd513c6cae3b and submitted a patch making traceback.FrameSummary take into consideration that lineno might be None, I believe this is probably the correct fix.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Filipe Laíns <lains@riseup.net>:


----------
pull_requests: +25367
pull_request: https://github.com/python/cpython/pull/26782

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Filipe Laíns <lains@riseup.net> added the comment:

Upon further investigation, there are actually two issues here. The first would be the one I identified already, traceback.FrameSummary not being prepared for lineno being None, but there is also a regression in lineno being invalid in this situation in the first place.

With only GH-26781, the traceback will look like the following:


File "/home/anubis/git/cpython/rep.py", line 13, in <module>
next(bar().__await__(), None)
File "/home/anubis/git/cpython/rep.py", line 10, in bar
return [chunk async for chunk in foo()]
File "/home/anubis/git/cpython/rep.py", line None, in <listcomp>
File "/home/anubis/git/cpython/rep.py", line 6, in foo
traceback.print_stack()
working!


which is different from 3.9



File "/home/anubis/git/cpython/rep.py", line 13, in <module>
next(bar().__await__(), None)
File "/home/anubis/git/cpython/rep.py", line 10, in bar
return [chunk async for chunk in foo()]
File "/home/anubis/git/cpython/rep.py", line 10, in <listcomp>
return [chunk async for chunk in foo()]
File "/home/anubis/git/cpython/rep.py", line 6, in foo
traceback.print_stack()
working!


I bisected the second issue to b37181e69209746adc2119c471599a1ea5faa6c8 which moves generators to bytecode, and when doing so changes the behavior to set lineno to -1. I have opened a GH-26782 to fixing this.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:

Mark, can you take a look at this?

----------
nosy: +pablogsal
versions: +Python 3.11 -Python 3.10

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Change by Pablo Galindo Salgado <pablogsal@gmail.com>:


----------
priority: normal -> release blocker

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Mark Shannon <mark@hotpy.org> added the comment:

This appears to be a duplicate of https://bugs.python.org/issue44297

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue44446] linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension [ In reply to ]
Mark Shannon <mark@hotpy.org> added the comment:

With the latest 3.10, I get:

File "/home/mark/test/test.py", line 13, in <module>
next(bar().__await__(), None)
File "/home/mark/test/test.py", line 10, in bar
return [chunk async for chunk in foo()]
File "/home/mark/test/test.py", line 10, in <listcomp>
return [chunk async for chunk in foo()]
File "/home/mark/test/test.py", line 6, in foo
traceback.print_stack()
working!


Thomas, can you confirm?

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue44446>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com