Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/renaissance/integrations/python/ast/rst_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/renaissance/syntax_tree/match_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/python/ast/test_patternic_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading