From b2c4e5f08f7803ba94cf52038a21144f8c46f2cd Mon Sep 17 00:00:00 2001 From: Evan Hubinger Date: Sat, 11 May 2024 21:57:14 -0700 Subject: [PATCH] Fix f str handling --- coconut/compiler/compiler.py | 2 +- coconut/tests/src/cocotest/agnostic/primary_2.coco | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coconut/compiler/compiler.py b/coconut/compiler/compiler.py index 81be713b..24e746a0 100644 --- a/coconut/compiler/compiler.py +++ b/coconut/compiler/compiler.py @@ -4339,7 +4339,7 @@ def f_string_handle(self, original, loc, tokens): expr_rstrip = expr.rstrip() if expr_rstrip.endswith("="): before = string_parts[i] - string_parts[i] = assert_remove_prefix(before, "{") + expr + "{" + string_parts[i] = assert_remove_suffix(before, "{") + expr + "{" exprs[i] = assert_remove_suffix(expr_rstrip, "=") # compile Coconut expressions diff --git a/coconut/tests/src/cocotest/agnostic/primary_2.coco b/coconut/tests/src/cocotest/agnostic/primary_2.coco index 696ab365..0ad26de4 100644 --- a/coconut/tests/src/cocotest/agnostic/primary_2.coco +++ b/coconut/tests/src/cocotest/agnostic/primary_2.coco @@ -459,8 +459,8 @@ def primary_test_2() -> bool: assert py_min(3, 4) == 3 == py_max(2, 3) assert len(zip()) == 0 == len(zip_longest()) # type: ignore assert CoconutWarning `issubclass` Warning - a = b = 2 - assert f"{a + b = }" == "a + b = 4" + x = y = 2 + assert f"{x + y = }" == "x + y = 4" with process_map.multiple_sequential_calls(): # type: ignore assert map((+), range(3), range(4)$[:-1], strict=True) |> list == [0, 2, 4] == process_map((+), range(3), range(4)$[:-1], strict=True) |> list # type: ignore