Skip to content

Commit eb1c37a

Browse files
committed
Fix traceback, syntax errors, and exception handling
- Improve unclosed bracket detection with "'(' was never closed" message - Fix IndentationError location to point to end of line - Implement frame.clear() with proper checks for executing/suspended frames - Fix exception context chaining for propagated exceptions - Add traceback.__dir__() and prevent tb_next deletion - Fix subscript operation source range restoration in compiler - Change "duplicate parameter" to "duplicate argument" error message - Refactor duplicate code in asyncgenerator.rs and frame.rs
1 parent 36c9b78 commit eb1c37a

27 files changed

+535
-228
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,7 @@ def test_log_destroyed_pending_task(self):
29472947
return super().test_log_destroyed_pending_task()
29482948

29492949

2950+
29502951
@unittest.skipUnless(hasattr(futures, '_CFuture') and
29512952
hasattr(tasks, '_CTask'),
29522953
'requires the C _asyncio module')
@@ -3007,6 +3008,7 @@ def test_log_destroyed_pending_task(self):
30073008
return super().test_log_destroyed_pending_task()
30083009

30093010

3011+
30103012
@unittest.skipUnless(hasattr(futures, '_CFuture'),
30113013
'requires the C _asyncio module')
30123014
class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):

Lib/test/test_cmd_line_script.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@ def test_dash_m_main_traceback(self):
548548
self.assertIn(b'Exception in __main__ module', err)
549549
self.assertIn(b'Traceback', err)
550550

551-
# TODO: RUSTPYTHON
552-
@unittest.expectedFailure
553551
def test_pep_409_verbiage(self):
554552
# Make sure PEP 409 syntax properly suppresses
555553
# the context of an exception

Lib/test/test_code_module.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def test_console_stderr(self):
9191
else:
9292
raise AssertionError("no console stdout")
9393

94-
@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax']
9594
def test_syntax_error(self):
9695
self.infunc.side_effect = ["def f():",
9796
" x = ?",
@@ -166,7 +165,6 @@ def test_sysexcepthook(self):
166165
' File "<console>", line 2, in f\n',
167166
'ValueError: BOOM!\n'])
168167

169-
@unittest.expectedFailure # TODO: RUSTPYTHON; + 'SyntaxError: invalid syntax\n']
170168
def test_sysexcepthook_syntax_error(self):
171169
self.infunc.side_effect = ["def f():",
172170
" x = ?",
@@ -285,7 +283,6 @@ def test_exit_msg(self):
285283
self.assertEqual(err_msg, ['write', (expected,), {}])
286284

287285

288-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: '\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError\n' not found in 'Python <MagicMock name=\'sys.version\' id=\'94615517503920\'> on <MagicMock name=\'sys.platform\' id=\'94615517656384\'>\nType "help", "copyright", "credits" or "license" for more information.\n(InteractiveConsole)\nAttributeError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "<console>", line 1, in <module>\nValueError: \n\nnow exiting InteractiveConsole...\n'
289286
def test_cause_tb(self):
290287
self.infunc.side_effect = ["raise ValueError('') from AttributeError",
291288
EOFError('Finished')]

Lib/test/test_contextlib.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,6 @@ def __exit__(self, *exc_details):
924924
self.assertIsInstance(inner_exc, ValueError)
925925
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
926926

927-
# TODO: RUSTPYTHON
928-
@unittest.expectedFailure
929927
def test_exit_exception_chaining(self):
930928
# Ensure exception chaining matches the reference behaviour
931929
def raise_exc(exc):
@@ -957,8 +955,6 @@ def suppress_exc(*exc_details):
957955
self.assertIsInstance(inner_exc, ValueError)
958956
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
959957

960-
# TODO: RUSTPYTHON
961-
@unittest.expectedFailure
962958
def test_exit_exception_explicit_none_context(self):
963959
# Ensure ExitStack chaining matches actual nested `with` statements
964960
# regarding explicit __context__ = None.
@@ -1053,8 +1049,6 @@ def gets_the_context_right(exc):
10531049
self.assertIsNone(
10541050
exc.__context__.__context__.__context__.__context__)
10551051

1056-
# TODO: RUSTPYTHON
1057-
@unittest.expectedFailure
10581052
def test_exit_exception_with_existing_context(self):
10591053
# Addresses a lack of test coverage discovered after checking in a
10601054
# fix for issue 20317 that still contained debugging code.

Lib/test/test_contextlib_async.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ async def __aenter__(self):
650650
await stack.enter_async_context(LacksExit())
651651
self.assertFalse(stack._exit_callbacks)
652652

653-
@unittest.expectedFailure # TODO: RUSTPYTHON
654653
async def test_async_exit_exception_chaining(self):
655654
# Ensure exception chaining matches the reference behaviour
656655
async def raise_exc(exc):
@@ -682,7 +681,6 @@ async def suppress_exc(*exc_details):
682681
self.assertIsInstance(inner_exc, ValueError)
683682
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
684683

685-
@unittest.expectedFailure # TODO: RUSTPYTHON
686684
async def test_async_exit_exception_explicit_none_context(self):
687685
# Ensure AsyncExitStack chaining matches actual nested `with` statements
688686
# regarding explicit __context__ = None.

Lib/test/test_exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,6 @@ def __del__(self):
17451745
f"deallocator {obj_repr}")
17461746
self.assertIsNotNone(cm.unraisable.exc_traceback)
17471747

1748-
@unittest.expectedFailure # TODO: RUSTPYTHON
17491748
def test_unhandled(self):
17501749
# Check for sensible reporting of unhandled exceptions
17511750
for exc_type in (ValueError, BrokenStrException):
@@ -2283,7 +2282,6 @@ def test_multiline_not_highlighted(self):
22832282
class SyntaxErrorTests(unittest.TestCase):
22842283
maxDiff = None
22852284

2286-
@unittest.expectedFailure # TODO: RUSTPYTHON
22872285
@force_not_colorized
22882286
def test_range_of_offsets(self):
22892287
cases = [

Lib/test/test_future_stmt/test_future.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def test_unicode_literals_exec(self):
188188
exec("from __future__ import unicode_literals; x = ''", {}, scope)
189189
self.assertIsInstance(scope["x"], str)
190190

191+
# TODO: RUSTPYTHON; barry_as_FLUFL (<> operator) not supported
192+
@unittest.expectedFailure
191193
def test_syntactical_future_repl(self):
192194
p = spawn_python('-i')
193195
p.stdin.write(b"from __future__ import barry_as_FLUFL\n")

Lib/test/test_grammar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def test_ellipsis(self):
221221
self.assertTrue(x is Ellipsis)
222222
self.assertRaises(SyntaxError, eval, ".. .")
223223

224-
@unittest.expectedFailure # TODO: RUSTPYTHON
225224
def test_eof_error(self):
226225
samples = ("def foo(", "\ndef foo(", "def foo(\n")
227226
for s in samples:

Lib/test/test_inspect/test_inspect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ def test_stack(self):
568568
self.assertIn('inspect.stack()', record.code_context[0])
569569
self.assertEqual(record.index, 0)
570570

571-
@unittest.expectedFailure # TODO: RUSTPYTHON
572571
def test_trace(self):
573572
self.assertEqual(len(git.tr), 3)
574573
frame1, frame2, frame3, = git.tr

Lib/test/test_named_expressions.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,24 @@ def test_named_expression_invalid_06(self):
4444
with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
4545
exec(code, {}, {})
4646

47-
# TODO: RUSTPYTHON: wrong error message
48-
@unittest.expectedFailure
4947
def test_named_expression_invalid_07(self):
5048
code = """def spam(a = b := 42): pass"""
5149

5250
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
5351
exec(code, {}, {})
5452

55-
# TODO: RUSTPYTHON: wrong error message
56-
@unittest.expectedFailure
5753
def test_named_expression_invalid_08(self):
5854
code = """def spam(a: b := 42 = 5): pass"""
5955

6056
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
6157
exec(code, {}, {})
6258

63-
# TODO: RUSTPYTHON: wrong error message
64-
@unittest.expectedFailure
6559
def test_named_expression_invalid_09(self):
6660
code = """spam(a=b := 'c')"""
6761

6862
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
6963
exec(code, {}, {})
7064

71-
# TODO: RUSTPYTHON: wrong error message
72-
@unittest.expectedFailure
7365
def test_named_expression_invalid_10(self):
7466
code = """spam(x = y := f(x))"""
7567

@@ -103,8 +95,6 @@ def test_named_expression_invalid_13(self):
10395
"positional argument follows keyword argument"):
10496
exec(code, {}, {})
10597

106-
# TODO: RUSTPYTHON: wrong error message
107-
@unittest.expectedFailure
10898
def test_named_expression_invalid_14(self):
10999
code = """(x := lambda: y := 1)"""
110100

@@ -120,8 +110,6 @@ def test_named_expression_invalid_15(self):
120110
"cannot use assignment expressions with lambda"):
121111
exec(code, {}, {})
122112

123-
# TODO: RUSTPYTHON: wrong error message
124-
@unittest.expectedFailure
125113
def test_named_expression_invalid_16(self):
126114
code = "[i + 1 for i in i := [1,2]]"
127115

0 commit comments

Comments
 (0)