-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
linecache.getline TypeError when formatting tracebacks in stacks containing an async list comprehension #88612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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) 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' |
I bissected this to 088a15c and submitted a patch making traceback.FrameSummary take into consideration that lineno might be None, I believe this is probably the correct fix. |
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 #70968, the traceback will look like the following: File "/home/anubis/git/cpython/rep.py", line 13, in <module> which is different from 3.9 File "/home/anubis/git/cpython/rep.py", line 13, in <module> I bisected the second issue to b37181e which moves generators to bytecode, and when doing so changes the behavior to set lineno to -1. I have opened a #70969 to fixing this. |
Mark, can you take a look at this? |
This appears to be a duplicate of https://bugs.python.org/issue44297 |
With the latest 3.10, I get: File "/home/mark/test/test.py", line 13, in <module> Thomas, can you confirm? |
Beta 4 is in a few days. Can someone confirm of this is fixed or if it still needs a patch? |
Feel free to reopen if we are missing anything |
If I understand correctly this should be fixed? In which 3.10.* version should this be fixed? The reason why I'm asking is that I ran into this issue when using Dask (2022.02.0) with multithreading on Python 3.10.2: Exception in thread Profile:
Traceback (most recent call last):
File "./lib/python3.10/site-packages/distributed/profile.py", line 115, in process
d = state["children"][ident]
KeyError: '_all_objs;./lib/python3.10/site-packages/bokeh/embed/bundle.py;357'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "./lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "./lib/python3.10/site-packages/distributed/profile.py", line 274, in _watch
process(frame, None, recent, omit=omit)
File "./lib/python3.10/site-packages/distributed/profile.py", line 119, in process
"description": info_frame(frame),
File "./lib/python3.10/site-packages/distributed/profile.py", line 72, in info_frame
line = linecache.getline(co.co_filename, frame.f_lineno, frame.f_globals).lstrip()
File "./lib/python3.10/linecache.py", line 31, in getline
if 1 <= lineno <= len(lines):
TypeError: '<=' not supported between instances of 'int' and 'NoneType' |
This was fixed in 3.10.0 if I am not mistaken. Could you provide a reproducer, please? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: