-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_python.py
More file actions
64 lines (53 loc) · 2.05 KB
/
Copy pathcheck_python.py
File metadata and controls
64 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Check Python files for common issues."""
import ast
import os
def check_file(filepath):
issues = []
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Try to parse the file
tree = ast.parse(content)
# Check for undefined names
defined_names = set()
used_names = set()
for node in ast.walk(tree):
if isinstance(node, ast.Name):
used_names.add(node.id)
elif isinstance(node, ast.FunctionDef):
defined_names.add(node.name)
elif isinstance(node, ast.ClassDef):
defined_names.add(node.name)
elif isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name):
defined_names.add(target.id)
# Check for used but undefined names (basic check)
for name in used_names:
if name not in defined_names and name not in ['print', 'len', 'str', 'int', 'float', 'list', 'dict', 'set', 'tuple', 'bool', 'None', 'True', 'False', 'self', 'cls']:
# Skip common builtins and imports
pass
except SyntaxError as e:
issues.append(f"Syntax error: {e}")
except Exception as e:
issues.append(f"Error: {e}")
return issues
def main():
backend_dir = r"D:\Vs Code\VS code\aether\backend\app"
total_issues = 0
for root, dirs, files in os.walk(backend_dir):
for file in files:
if file.endswith('.py'):
filepath = os.path.join(root, file)
issues = check_file(filepath)
if issues:
print(f"\n{filepath}:")
for issue in issues:
print(f" {issue}")
total_issues += len(issues)
if total_issues == 0:
print("No issues found!")
else:
print(f"\nTotal issues: {total_issues}")
if __name__ == "__main__":
main()