Skip to content

Commit

Permalink
change: refacored code in checker.py
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelrahman0w committed Jan 29, 2024
1 parent eb6efec commit e79ac1a
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions ouro/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,21 @@ def cycles(self) -> Dict:
def get_possible_origins(
self, cycles: Dict, num_possibilities: int = 3
) -> List[str]:
paths = []

if self.categorize:
for cycle in cycles.values():
for category in cycle.values():
for cycle_info in category:
paths.extend(cycle_info["path_from_import_to_file"])
cycle_iter = (
cycle_info
for cycle in cycles.values()
for category in cycle.values()
for cycle_info in category
)
else:
for cycle in cycles.values():
for cycle_info in cycle:
paths.extend(cycle_info["path_from_import_to_file"])
cycle_iter = (
cycle_info for cycle in cycles.values() for cycle_info in cycle
)

paths = [
cycle_info["path_from_import_to_file"] for cycle_info in cycle_iter
]
if not paths:
return []

Expand All @@ -146,20 +149,10 @@ def get_possible_origins(

possible_origins = []
for path in most_common_paths:
if self.categorize:
if path in cycles and any(
path in cycle_info["path_from_import_to_file"]
for cycle in cycles.values()
for category in cycle.values()
for cycle_info in category
):
possible_origins.append(path)
else:
if path in cycles and any(
path in cycle_info["path_from_import_to_file"]
for cycle in cycles.values()
for cycle_info in cycle
):
possible_origins.append(path)
if path in cycles and any(
path in cycle_info["path_from_import_to_file"]
for cycle_info in cycle_iter
):
possible_origins.append(path)

return possible_origins

0 comments on commit e79ac1a

Please sign in to comment.