-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Support multi-line error locations in traceback and other related improvements (PEP-657, 3.11) #106922
Comments
Hi @williamwen42! Thanks a lot for opening the issue. I think all of these make sense and would be great improvements! Do you plan to contribute these improvements or the issue is just for the proposal itself? |
@pablogsal I can contribute these improvements since I already have prototypes written. I also want to double check if we're okay with changing the default traceback behavior from one line to multiline. |
Ok, let's do it then. Please, ping me in the PR as soon as is available! Just to make this clear: this needs changes in both the traceback module and the default traceback logic in C.
I will be supportive and have the feeling that it won't be controversial but we may need to discuss it. In any case the discussion would be much easier if we have a PR to play with. Maybe, if is not too bothersome, you can split that particular aspect in a separate PR, but is not a requirement. Thanks a lot for the help ❤️ |
@williamwen42 any news on this? |
…rentheses (pythonGH-108959) (cherry picked from commit 6275c67) Co-authored-by: Pablo Galindo Salgado <[email protected]>
…rentheses (pythonGH-108959) (cherry picked from commit 6275c67) Co-authored-by: Pablo Galindo Salgado <[email protected]>
…arentheses (GH-108959) (#109148) Co-authored-by: Pablo Galindo Salgado <[email protected]>
…arentheses (GH-108959) (#109147) Co-authored-by: Pablo Galindo Salgado <[email protected]>
@pablogsal I'm still working on the C implementation. I've been distracted with work/travel in the last month but I'm planning to return to complete this in the near future. |
Ok, just be aware that I have treated (3) as a bugfix in #108959 so that's not required anymore. I can take care of (2) if I get some spare cycles but I will certainly leave (1) to you :) |
@williamwen42 I think there is one thing we should consider. Think of the following example:
This currently shows:
but that is odd as the line that shows |
@pablogsal hmm, I currently get
on main |
Ah, apologies. I was testing this on top of #112732 and looks I screwed up something on that PR because that part is missing. This means this is working on main but we don't cover it with a test. Would you like to add a test for it? |
I think 'Traceback (most recent call last):\n'
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
' callable()\n'
' ~~~~~~~~^^\n'
f' File "{__file__}", line {lineno_f+8}, in f_with_call\n'
' a = (g(1).y)(\n'
' ~~~~~~~~~\n'
' 2\n'
' ~\n'
' )(3)(4)\n'
' ~^^^\n'
f' File "{__file__}", line {lineno_f+4}, in f\n'
' raise RuntimeError("fail")\n' |
I don't think it does because my PR was showing the wrong output and the CI was passing. I can look closer tomorrow |
Ah forget that, the problem is that the colorising code in my PR was just being used outside most tests in the test suite. This means I should add more tests on my side. 😅 Sorry for the misunderstanding |
Hi tl;dr: for python3 < 3.13 frameSummary.line attribute becomes None when i create a method using exec with given code string due to which i couldn't see content of traceback line in my error traceback. Wanted to know if you have any suggestion for solving this to point me in right direction Thanks |
@pablogsal will #112097 be backported to 3.11 and 3.12? |
Unfortunately no since it's a new feature |
Feature or enhancement
We propose a few improvements and fixes to PEP-657, namely:
Pitch
We already implemented these items in PyTorch here: pytorch/pytorch#104676. We're seeing if these may be worth adding to CPython.
Rationale for 1
Multi-line expressions can negate the utility of PEP-657, for example:
Current traceback:
Better traceback:
Rationale for 2
Helpful for identifying function calls that cause errors in chained function calls. We may as well do it since we're already doing it for subscripts. For example:
Current traceback:
Better traceback:
Rationale for 3
The binary op anchors are computed by taking the next non-space character after the left subexpression. This is incorrect in some simple cases:
We should expect
The fix is that we should continue advancing the anchor until we find a non-space character that is also not in
)\#
(for\#
, we should move the anchor to the next line).Subscript has a similar issue as well. We should continue advancing the left anchor until we find
[
, and the right anchor should be the end of the entire subscript expression.cc @pablogsal @isidentical @ammaraskar @iritkatriel @ezyang
Linked PRs
The text was updated successfully, but these errors were encountered: