8000 gh-129093: Fix f-string debug text sometimes getting cut off when exp… · python/cpython@767cf70 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 767cf70

Browse files
authored
gh-129093: Fix f-string debug text sometimes getting cut off when expression contains ! (#129159)
1 parent 01bcf13 commit 767cf70

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Lib/test/test_fstring.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,5 +1757,23 @@ def get_code(s):
17571757
for s in ["", "some string"]:
17581758
self.assertEqual(get_code(f"'{s}'"), get_code(f"f'{s}'"))
17591759

1760+
def test_gh129093(self):
1761+
self.assertEqual(f'{1==2=}', '1==2=False')
1762+
self.assertEqual(f'{1 == 2=}', '1 == 2=False')
1763+
self.assertEqual(f'{1!=2=}', '1!=2=True')
1764+
self.assertEqual(f'{1 != 2=}', '1 != 2=True')
1765+
1766+
self.assertEqual(f'{(1) != 2=}', '(1) != 2=True')
1767+
self.assertEqual(f'{(1*2) != (3)=}', '(1*2) != (3)=True')
1768+
1769+
self.assertEqual(f'{1 != 2 == 3 != 4=}', '1 != 2 == 3 != 4=False')
1770+
self.assertEqual(f'{1 == 2 != 3 == 4=}', '1 == 2 != 3 == 4=False')
1771+
1772+
self.assertEqual(f'{f'{1==2=}'=}', "f'{1==2=}'='1==2=False'")
1773+
self.assertEqual(f'{f'{1 == 2=}'=}', "f'{1 == 2=}'='1 == 2=False'")
1774+
self.assertEqual(f'{f'{1!=2=}'=}', "f'{1!=2=}'='1!=2=True'")
1775+
self.assertEqual(f'{f'{1 != 2=}'=}', "f'{1 != 2=}'='1 != 2=True'")
1776+
1777+
17601778
if __name__ == '__main__':
17611779
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix f-strings such as ``f'{expr=}'`` sometimes not displaying the full
2+
expression when the expression contains ``!=``.

Parser/lexer/lexer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ _PyLexer_update_fstring_expr(struct tok_state *tok, char cur)
212212
case '}':
213213
case '!':
214214
case ':':
215-
if (tok_mode->last_expr_end == -1) {
216-
tok_mode->last_expr_end = strlen(tok->start);
217-
}
215+
tok_mode->last_expr_end = strlen(tok->start);
218216
break;
219217
default:
220218
Py_UNREACHABLE();

0 commit comments

Comments
 (0)
0