diff --git a/src/renaissance/integrations/python/ast/rst_node.py b/src/renaissance/integrations/python/ast/rst_node.py index bdee5159..543b02a2 100644 --- a/src/renaissance/integrations/python/ast/rst_node.py +++ b/src/renaissance/integrations/python/ast/rst_node.py @@ -289,7 +289,7 @@ def __contains__(self, item) -> bool: """AI: Return whether item(s) are found among this node's children.""" if not isinstance(item, list): item = [item] - return bool(find_in_list(self.children, item)) + return find_in_list(self.children, item) >= 0 def __getitem__(self, key): """Allow indexing/slicing into node to access children. diff --git a/src/renaissance/syntax_tree/match_finder.py b/src/renaissance/syntax_tree/match_finder.py index 38c447d1..027e66b3 100644 --- a/src/renaissance/syntax_tree/match_finder.py +++ b/src/renaissance/syntax_tree/match_finder.py @@ -271,12 +271,12 @@ def find_variants(src: Sequence, cmp: Sequence, expansion=None, start: int = 0, def find_in_list(src: Sequence, cmp: Sequence, exp=None, start: int = 0) -> int: - """AI: Return the end index of the first full match of cmp within src starting at start, or -2 if none.""" + """AI: Return the end index of the first full match of cmp within src starting at start, or MIS_MATCH if none.""" if exp is None: exp = {} variants = find_variants(src, cmp, exp, start) if not variants: - return -2 + return MIS_MATCH exp.update(variants[0].exp) # [0] most greedy # [-1] least greedy diff --git a/test/python/ast/test_patternic_style.py b/test/python/ast/test_patternic_style.py index a18f880f..5595b11e 100644 --- a/test/python/ast/test_patternic_style.py +++ b/test/python/ast/test_patternic_style.py @@ -137,8 +137,8 @@ def test_match_one_is_not_equal(self) -> None: def test_is_match_all_stmt(self) -> None: """AI: Verify a MATCH_ALL placeholder pattern's node is contained within the parsed module.""" atu = self.factory.create_from_text("ba(55)\nca(555)\nlo(4444)\nna=55", "test.py") - match_all = self.pattern_factory.create("$$pa") - assert_that(match_all.node, is_in(atu)) + match_all = self.pattern_factory.create_statement("$$pa") + assert_that(match_all, is_in(atu)) def test_is_exact_match(self) -> None: """AI: Verify the first statement in the module equals an independently parsed identical statement."""