gh-93883: elide traceback indicators when possible (#93994) · python/cpython@da71751 · GitHub
Skip to content

Commit da71751

Browse files
authored
gh-93883: elide traceback indicators when possible (#93994)
* gh-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).
1 parent c9118af commit da71751

9 files changed

Lines changed: 113 additions & 137 deletions

File tree

Doc/library/traceback.rst

Lines changed: 4 additions & 9 deletions

Doc/whatsnew/3.11.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ when dealing with deeply nested dictionary objects and multiple function calls,
117117
Traceback (most recent call last):
118118
File "query.py", line 37, in <module>
119119
magic_arithmetic('foo')
120-
^^^^^^^^^^^^^^^^^^^^^^^
121120
File "query.py", line 18, in magic_arithmetic
122121
return add_counts(x) / 25
123122
^^^^^^^^^^^^^

Lib/idlelib/idle_test/test_run.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from idlelib import run
44
import io
55
import sys
6-
from test.support import captured_output, captured_stderr, has_no_debug_ranges
6+
from test.support import captured_output, captured_stderr
77
import unittest
88
from unittest import mock
99
import idlelib
@@ -33,14 +33,9 @@ def __eq__(self, other):
3333
run.print_exception()
3434

3535
tb = output.getvalue().strip().splitlines()
36-
if has_no_debug_ranges():
37-
self.assertEqual(11, len(tb))
38-
self.assertIn('UnhashableException: ex2', tb[3])
39-
self.assertIn('UnhashableException: ex1', tb[10])
40-
else:
41-
self.assertEqual(13, len(tb))
42-
self.assertIn('UnhashableException: ex2', tb[4])
43-
self.assertIn('UnhashableException: ex1', tb[12])
36+
self.assertEqual(11, len(tb))
37+
self.assertIn('UnhashableException: ex2', tb[3])
38+
self.assertIn('UnhashableException: ex1', tb[10])
4439

4540
data = (('1/0', ZeroDivisionError, "division by zero\n"),
4641
('abc', NameError, "name 'abc' is not defined. "

Lib/test/test_cmd_line_script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,10 @@ def test_pep_409_verbiage(self):
549549
script_name = _make_test_script(script_dir, 'script', script)
550550
exitcode, stdout, stderr = assert_python_failure(script_name)
551551
text = stderr.decode('ascii').split('\n')
552-
self.assertEqual(len(text), 6)
552+
self.assertEqual(len(text), 5)
553553
self.assertTrue(text[0].startswith('Traceback'))
554554
self.assertTrue(text[1].startswith(' File '))
555-
self.assertTrue(text[4].startswith('NameError'))
555+
self.assertTrue(text[3].startswith('NameError'))
556556

557557
def test_non_ascii(self):
558558
# Mac OS X denies the creation of a file with an invalid UTF-8 name.

Lib/test/test_doctest.py

Lines changed: 1 addition & 3 deletions

0 commit comments

Comments
 (0)