]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-129093: Fix f-string debug text sometimes getting cut off when expression...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Wed, 22 Jan 2025 00:47:20 +0000 (00:47 +0000)
committerGitHub <noreply@github.com>
Wed, 22 Jan 2025 00:47:20 +0000 (00:47 +0000)
Lib/test/test_fstring.py
Misc/NEWS.d/next/Core_and_Builtins/2025-01-21-23-35-41.gh-issue-129093.0rvETC.rst [new file with mode: 0644]
Parser/tokenizer.c

index da1ab4ef5853e6bf30f34b23581fa70f266ee722..6cba2e8616eb729c163b476b24a69f2dabb60c2d 100644 (file)
@@ -1875,6 +1875,24 @@ print(f'''{{
             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()
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-01-21-23-35-41.gh-issue-129093.0rvETC.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-01-21-23-35-41.gh-issue-129093.0rvETC.rst
new file mode 100644 (file)
index 0000000..067d52e
--- /dev/null
@@ -0,0 +1,2 @@
+Fix f-strings such as ``f'{expr=}'`` sometimes not displaying the full
+expression when the expression contains ``!=``.
index 9e0dee8cc383d6bdc769f14b1b98b732db5c815c..7ba717d909124e0bd42e2d937f72b9bb30c730cc 100644 (file)
@@ -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();