"""
AutoCodeReview
Generated by Eden via recursive self-improvement
2025-11-02 09:40:53.667030
"""

import ast
from collections import defaultdict

class AutoCodeReview:
    """
    A class for automatically reviewing Python code based on common coding standards.
    
    This capability can be used to analyze existing SAGEs or any other Python code base,
    providing suggestions and improvements to the code quality.
    """

    def __init__(self, source_code):
        self.source_code = source_code
        self.tree = ast.parse(source_code)
        self.visitor = CodeVisitor()
        self.visitor.visit(self.tree)

    @staticmethod
    def review_code(file_path):
        with open(file_path, 'r') as file:
            code = file.read()
        return AutoCodeReview(code).get_review()

    def get_review(self):
        """
        Returns a dictionary containing the suggestions and issues found in the source code.
        
        :return: A dictionary with keys "issues" and "suggestions", each containing lists of problems and recommendations respectively.
        """
        return self.visitor.get_results()

class CodeVisitor(ast.NodeVisitor):
    def __init__(self):
        self.issues = []
        self.suggestions = []

    def visit_Assign(self, node):
        if not isinstance(node.targets[0], ast.Name) or not isinstance(node.value, (ast.List, ast.Tuple)):
            self.issues.append(f"Line {node.lineno}: Avoid using complex assignments on a single line.")
        
        super().generic_visit(node)

    def visit_Return(self, node):
        if not isinstance(node.value, (ast.Num, ast.Str, ast.NameConstant)):
            self.suggestions.append(f"Line {node.lineno}: Return simpler data types to improve readability.")
        
        super().generic_visit(node)

    def get_results(self):
        return {"issues": self.issues, "suggestions": self.suggestions}

# Example usage
code_to_review = """
def example_function(x, y):
    z = x * y + 1
    if z > 0:
        return True
    else:
        return False
"""

reviewer = AutoCodeReview(code_to_review)
print(reviewer.get_review())