gh-112343: pdb: Use tokenize to replace convenience variables (#112380)

This commit is contained in:
Tian Gao 2024-01-17 06:50:31 -08:00 committed by GitHub
parent f49752552e
commit 5c351fc85a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 1 deletions

View file

@ -847,9 +847,12 @@ def test_convenience_variables():
>>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
... '$_frame.f_lineno', # Check frame convenience variable
... '$ _frame', # This should be a syntax error
... '$a = 10', # Set a convenience variable
... '$a', # Print its value
... 'p "$a"', # Print the string $a
... 'p $a + 2', # Do some calculation
... 'p f"$a = {$a}"', # Make sure $ in string is not converted and f-string works
... 'u', # Switch frame
... '$_frame.f_lineno', # Make sure the frame changed
... '$a', # Make sure the value persists
@ -869,11 +872,17 @@ def test_convenience_variables():
-> try:
(Pdb) $_frame.f_lineno
3
(Pdb) $ _frame
*** SyntaxError: invalid syntax
(Pdb) $a = 10
(Pdb) $a
10
(Pdb) p "$a"
'$a'
(Pdb) p $a + 2
12
(Pdb) p f"$a = {$a}"
'$a = 10'
(Pdb) u
> <doctest test.test_pdb.test_convenience_variables[1]>(2)test_function()
-> util_function()