11import ast
22import pycodestyle
33
4+
45class CodeReviewer :
56 def __init__ (self ):
67 self .feedback = []
@@ -27,10 +28,12 @@ def _check_indentation(self, tree):
2728 for node in ast .walk (tree ):
2829 if isinstance (node , ast .FunctionDef ):
2930 if node .body and not isinstance (node .body [0 ], ast .Expr ):
30- self .feedback .append (f"Function '{ node .name } ' should have a docstring or 'pass' statement." )
31+ self .feedback .append (
32+ f"Function '{ node .name } ' should have a docstring or 'pass' statement." )
3133 elif isinstance (node , (ast .For , ast .While , ast .If , ast .With )):
3234 if not isinstance (node .body [0 ], ast .Expr ):
33- self .feedback .append (f"Indentation Error: Missing 'pass' statement for '{ ast .dump (node )} '." )
35+ self .feedback .append (
36+ f"Indentation Error: Missing 'pass' statement for '{ ast .dump (node )} '." )
3437
3538 def _check_undefined_vars (self , tree ):
3639 undefined_vars = set ()
@@ -47,19 +50,22 @@ def _check_code_style(self, code):
4750 style_guide = pycodestyle .StyleGuide ()
4851 result = style_guide .check_code (code )
4952 if result .total_errors :
50- self .feedback .append ("Code style issues found. Please check and fix them." )
53+ self .feedback .append (
54+ "Code style issues found. Please check and fix them." )
5155
5256 def _check_comments (self , code ):
5357 lines = code .split ('\n ' )
5458 for i , line in enumerate (lines ):
5559 if line .strip ().startswith ('#' ):
5660 # Check for empty comments or comments without space after '#'
5761 if len (line .strip ()) == 1 or line .strip ()[1 ] != ' ' :
58- self .feedback .append (f"Improve comment style in line { i + 1 } : '{ line .strip ()} '" )
62+ self .feedback .append (
63+ f"Improve comment style in line { i + 1 } : '{ line .strip ()} '" )
5964
6065 def get_feedback (self ):
6166 return self .feedback
6267
68+
6369if __name__ == "__main__" :
6470 # Example Python code to analyze
6571 python_code = """
0 commit comments