From cc0ee034f426f683965e7b060e5b431880a8f3c8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 17 May 2023 16:15:09 -0700 Subject: [PATCH] aider: Added a check to ensure that part appears in whole exactly once in try_dotdotdots. # Context: USER: in try_dotdotdots, after checking that part is in whole add a check that part is in whole exactly 1 time ASSISTANT: ```python aider/utils.py <<<<<<< ORIGINAL if part not in whole: raise ValueError("No perfect matching chunk in edit block with ...") whole = whole.replace(part, replace) ======= if whole.count(part) != 1: raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once") whole = whole.replace(part, replace, 1) >>>>>>> UPDATED ``` --- aider/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index ab977f079..0b10f838a 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -50,10 +50,10 @@ def try_dotdotdots(whole, part, replace): whole += replace continue - if part not in whole: - raise ValueError("No perfect matching chunk in edit block with ...") + if whole.count(part) != 1: + raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once") - whole = whole.replace(part, replace) + whole = whole.replace(part, replace, 1) return whole