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 June 19, 2022 05:04
@belm0 belm0 marked this pull request as draft June 19, 2022 05:05
@belm0 belm0 force-pushed the trackback_elide_indicators branch 2 times, most recently from 9e77485 to f8b316f Compare June 19, 2022 05:23
@arhadthedev
Copy link
Member

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

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 June 24, 2022 13:31
blurb-it bot and others added 4 commits June 24, 2022 14:06
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 June 24, 2022 14:26
@belm0 belm0 requested a review from terryjreedy as a code owner June 24, 2022 14:26
@terryjreedy
Copy link
Member

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

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 27, 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.

@@ -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

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

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 Outdated Show resolved Hide resolved
Python/traceback.c Outdated Show resolved Hide resolved
@pablogsal pablogsal merged commit da71751 into python:main Jul 11, 2022
@pablogsal pablogsal added the needs backport to 3.11 only security fixes label Jul 11, 2022
@miss-islington
Copy link
Contributor

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 pull request 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 <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 11, 2022
@bedevere-bot
Copy link

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

@kumaraditya303
Copy link
Contributor

This change broke all main branch CI and buildbots. See https://github.com/python/cpython/runs/7277260781?check_suite_focus=true

@belm0
Copy link
Contributor Author

belm0 commented Jul 11, 2022

This change broke all main branch CI and buildbots.

Sorry-- I hadn't rebased in a few weeks, perhaps automatic merge let some new test code through that needs revision. Looking...

belm0 added a commit to belm0/cpython that referenced this pull request Jul 11, 2022
PR python#93994 was merged without being rebased in a few weeks, and
some new test code using the old scheme passed through automatic merge.
@belm0
Copy link
Contributor Author

belm0 commented Jul 11, 2022

Fix is at #94737 hopefully. I'll be AFK for about 2 hours.

pablogsal pushed a commit that referenced this pull request Jul 11, 2022
PR #93994 was merged without being rebased in a few weeks, and
some new test code using the old scheme passed through automatic merge.
belm0 added a commit to belm0/cpython that referenced this pull request Jul 11, 2022
…onGH-93994)

* 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
```

(cherry picked from commit da71751)

Co-authored-by: John Belmonte <[email protected]>
belm0 added a commit to belm0/cpython that referenced this pull request Jul 11, 2022
…#94737)

PR python#93994 was merged without being rebased in a few weeks, and
some new test code using the old scheme passed through automatic merge.

(cherry picked from commit 1fdc35e)
belm0 added a commit to belm0/cpython that referenced this pull request Jul 11, 2022
…onGH-93994)

* 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 <[email protected]>
miss-islington pushed a commit that referenced this pull request Jul 11, 2022
…H-94740)

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
```

Automerge-Triggered-By: GH:pablogsal
nitzmahone pushed a commit to rolpdog/cffi-mirror that referenced this pull request Sep 8, 2022
nitzmahone pushed a commit to rolpdog/cffi-mirror that referenced this pull request Sep 9, 2022
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.

7 participants