Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,24 @@ def test_syntax_warning_infinite_recursion_in_file(self):
self.assertIn(rb"\1", stdout)
self.assertEqual(len(stderr.strip().splitlines()), 2)

def test_gh129093(self):
self.assertEqual(f'{1==2=}', '1==2=False')
self.assertEqual(f'{1 == 2=}', '1 == 2=False')
self.assertEqual(f'{1!=2=}', '1!=2=True')
self.assertEqual(f'{1 != 2=}', '1 != 2=True')

self.assertEqual(f'{(1) != 2=}', '(1) != 2=True')
self.assertEqual(f'{(1*2) != (3)=}', '(1*2) != (3)=True')

self.assertEqual(f'{1 != 2 == 3 != 4=}', '1 != 2 == 3 != 4=False')
self.assertEqual(f'{1 == 2 != 3 == 4=}', '1 == 2 != 3 == 4=False')

self.assertEqual(f'{f'{1==2=}'=}', "f'{1==2=}'='1==2=False'")
self.assertEqual(f'{f'{1 == 2=}'=}', "f'{1 == 2=}'='1 == 2=False'")
self.assertEqual(f'{f'{1!=2=}'=}', "f'{1!=2=}'='1!=2=True'")
self.assertEqual(f'{f'{1 != 2=}'=}', "f'{1 != 2=}'='1 != 2=True'")


if __name__ == "__main__":

unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix f-strings such as ``f'{expr=}'`` sometimes not displaying the full
expression when the expression contains ``!=``.
4 changes: 1 addition & 3 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ static int update_fstring_expr(struct tok_state *tok, char cur) {
case '}':
case '!':
case ':':
if (tok_mode->last_expr_end == -1) {
tok_mode->last_expr_end = strlen(tok->start);
}
tok_mode->last_expr_end = strlen(tok->start);
break;
default:
Py_UNREACHABLE();
Expand Down
Loading