Fix Template.search() dropping zero-variable matches - #1632
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
Template.match() returns an empty dict when a template with no variable placeholders matches a subtree, and None when there is no match. search() tested the result for truthiness, so the empty dict was treated as "no match" and every zero-variable match was silently dropped. translate() therefore never replaced anything for such templates. search() now tests `res is not None`, matching the contract match() documents. Two existing search tests asserted the broken behaviour and are corrected; added a test that a genuinely different tree still yields nothing, and a TemplateTranslator test covering a variable-free translation. Closes lark-parser#1630
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1630
Template.match()returns{}for a match with no variables to bind andNonefor no match, butsearch()tested the result for truthiness — so{}was read as "no match" and every zero-variable match was dropped, leavingtranslate()a no-op for variable-free templates.search()now testsres is not None.The two existing search tests asserted the broken empty result and are corrected; added a test that a genuinely different tree still yields nothing, plus a
TemplateTranslatorcase for a variable-free translation. The three tests fail on master and pass with the fix; full suite is 1134 passed / 174 skipped.This change was prepared with AI assistance; the regression test was run locally and fails without the fix.