Skip to content
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

gh-93883: elide traceback indicators when possible #93994

Merged
merged 13 commits into from Jul 11, 2022

Conversation

belm0
Copy link
Contributor

@belm0 belm0 commented Jun 19, 2022

Elide traceback column indicators when the entire line of the
frame is implicated. This reduces traceback length and draws
more attention to the remaining (very relevant) indicators.

Example:

Traceback (most recent call last):
  File "query.py", line 99, in <module>
    bar()
  File "query.py", line 66, in bar
    foo()
  File "query.py", line 37, in foo
    magic_arithmetic('foo')
  File "query.py", line 18, in magic_arithmetic
    return add_counts(x) / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user(user1) + query_user(user2)
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count(db, response['a']['b']['c']['user'], retry=True)
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable

TODO:

  • C traceback implementation
  • update documentation

See also the original feature issue: gh-88116.

@belm0 belm0 requested a review from iritkatriel as a code owner Jun 19, 2022
@belm0 belm0 marked this pull request as draft Jun 19, 2022
@belm0 belm0 force-pushed the trackback_elide_indicators branch 2 times, most recently from 9e77485 to f8b316f Compare Jun 19, 2022
@arhadthedev
Copy link
Contributor

@arhadthedev arhadthedev commented Jun 19, 2022

For backlinking purposes the parent issue is gh-93883 (until the link autoiinsertion is returned back; cannot find that PR).

belm0 added 5 commits Jun 24, 2022
Elide traceback column indicators when the entire line of the
frame is implicated.  This reduces traceback length and draws
even more attention to the remaining (very relevant) indicators.

Example:
```
Traceback (most recent call last):
  File "query.py", line 99, in <module>
    bar()
  File "query.py", line 66, in bar
    foo()
  File "query.py", line 37, in foo
    magic_arithmetic('foo')
  File "query.py", line 18, in magic_arithmetic
    return add_counts(x) / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user(user1) + query_user(user2)
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count(db, response['a']['b']['c']['user'], retry=True)
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
```

WORK IN PROGRESS

TODO:
  * C traceback implementation
  * update documentation
@belm0 belm0 force-pushed the trackback_elide_indicators branch from 472339e to c06257b Compare Jun 24, 2022
blurb-it bot and others added 4 commits Jun 24, 2022
Rather than going out of our way to provide indicator coverage
in every traceback test suite, the indicator test suite should
be responible for sufficient coverage (e.g. by adding a basic
exception group test to ensure that margin strings are covered).
@belm0 belm0 marked this pull request as ready for review Jun 24, 2022
@belm0 belm0 requested a review from terryjreedy as a code owner Jun 24, 2022
@terryjreedy terryjreedy requested a review from pablogsal Jun 24, 2022
@terryjreedy
Copy link
Member

@terryjreedy terryjreedy commented Jun 24, 2022

I approve of the idea of the change and, of course, adjusting the IDLE test.

I would like to see this backported as I consider the noise a visual bug in the new feature.

@@ -387,17 +387,16 @@ def get_exception(self, callable):

def test_basic_caret(self):
def f():
raise ValueError("basic caret tests")
if True: raise ValueError("basic caret tests")
Copy link
Member

@pablogsal pablogsal Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, this is a bit confusing the first time I just saw it. I understand that this is so the raise doesn't get elided because is fully covered, but maybe we can do the same with a ternary operation raise ValueError("blech") or ValueError("never executed"). I don't have a string opinion to be honest, just that is a bit confusing :)

Copy link
Contributor Author

@belm0 belm0 Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rightly noted. I had a pending commit to explain that idiom. Let's see how it looks after adding that.

Lib/test/test_traceback.py Outdated Show resolved Hide resolved
@@ -1459,10 +1457,8 @@ def exc():
f' + Exception Group Traceback (most recent call last):\n'
f' | File "{__file__}", line {self.callable_line}, in get_exception\n'
f' | exception_or_callable()\n'
f' | ^^^^^^^^^^^^^^^^^^^^^^^\n'
Copy link
Member

@pablogsal pablogsal Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit concerned that we are missing some test coverage with exception groups + debug ranges here. We should make sure we have at least one specific exception group test that covers debug ranges as well.

Copy link
Contributor Author

@belm0 belm0 Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes-- that was my intention with the added test_caret_exception_group() test. I thought it would be better to leave the onus on the CaretTests suite.

Python/traceback.c Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
belm0 and others added 2 commits Jun 28, 2022
belm0 added 2 commits Jun 28, 2022
  * explain "if True:" idiom for caret tests
  * document test_caret_exception_group() test
  * add eliding explanation to summary in traceback.c
@belm0
Copy link
Contributor Author

@belm0 belm0 commented Jun 28, 2022

@pablogsal would you add this PR to the summary table at #88116 (comment) ?

@belm0 belm0 requested a review from pablogsal Jun 28, 2022
@belm0
Copy link
Contributor Author

@belm0 belm0 commented Jul 10, 2022

@pablogsal hoping it will only take a few minutes of your time to confirm the requested changes, and possible to packport this to 3.11 in time for the final release 🙏. Thank you!

Copy link
Member

@pablogsal pablogsal left a comment

Changes LGTM. I'm merging this PR so it makes it in today's release.

Great work @belm0 🎉🚀 And thanks for the patience ;)

@pablogsal pablogsal merged commit da71751 into python:main Jul 11, 2022
14 checks passed
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Jul 11, 2022

Thanks @belm0 for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 11, 2022
)

* pythongh-93883: elide traceback indicators when possible

Elide traceback column indicators when the entire line of the
frame is implicated.  This reduces traceback length and draws
even more attention to the remaining (very relevant) indicators.

Example:
```
Traceback (most recent call last):
  File "query.py", line 99, in <module>
    bar()
  File "query.py", line 66, in bar
    foo()
  File "query.py", line 37, in foo
    magic_arithmetic('foo')
  File "query.py", line 18, in magic_arithmetic
    return add_counts(x) / 25
           ^^^^^^^^^^^^^
  File "query.py", line 24, in add_counts
    return 25 + query_user(user1) + query_user(user2)
                ^^^^^^^^^^^^^^^^^
  File "query.py", line 32, in query_user
    return 1 + query_count(db, response['a']['b']['c']['user'], retry=True)
                               ~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
```

Rather than going out of our way to provide indicator coverage
in every traceback test suite, the indicator test suite should
be responible for sufficient coverage (e.g. by adding a basic
exception group test to ensure that margin strings are covered).
(cherry picked from commit da71751)

Co-authored-by: John Belmonte <john@neggie.net>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Jul 11, 2022

GH-94734 is a backport of this pull request to the 3.11 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants