Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Removal of the RedBaron package from experimental/search/symbol_search module #146

Merged
merged 5 commits into from
Jul 7, 2023
Merged
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
11 changes: 7 additions & 4 deletions automata/experimental/search/symbol_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ast import unparse as pyast_unparse
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union, cast

import numpy as np
Expand Down Expand Up @@ -111,11 +112,13 @@ def process_query(
def _find_pattern_in_modules(self, pattern: str) -> Dict[str, List[int]]:
"""Finds exact line matches for a given pattern string in all modules."""
matches = {}
for module_path, module in cast(
Iterable[Tuple[str, Optional[RedBaron]]], py_module_loader.items()
):
for module_path, module in py_module_loader.items():
print("Checking module = ", module)
if module:
lines = module.dumps().splitlines()
if isinstance(module, RedBaron):
lines = module.dumps().splitlines()
else:
lines = pyast_unparse(module).splitlines()
line_numbers = [i + 1 for i, line in enumerate(lines) if pattern in line.strip()]
if line_numbers:
matches[module_path] = line_numbers
Expand Down