fix: resolve CI linting issues across codebase
Some checks failed
CI / test (push) Has been cancelled

- Remove unused imports (sys, Path, defaultdict, etc.)
- Convert Optional types to modern | syntax
- Fix trailing whitespace and blank line whitespace issues
- Sort imports alphabetically
- Add __future__ annotations for type syntax support
This commit is contained in:
2026-01-30 22:21:27 +00:00
parent f5dc6e31ad
commit 8b32f32020

View File

@@ -0,0 +1,33 @@
from __future__ import annotations
import ast
from collections import defaultdict
from pathlib import Path
from codesnap.core.models import DependencyInfo
class DependencyGraph:
def __init__(self):
self.graph: dict[str, set[str]] = defaultdict(set)
self.file_modules: dict[str, str] = {}
def add_file(self, file_path: Path, tree: ast.AST):
module_name = file_path.stem
self.file_modules[str(file_path)] = module_name
for node in ast.walk(tree):
if isinstance(node, ast.Import):
for alias in node.names:
self.graph[module_name].add(alias.name)
elif isinstance(node, ast.ImportFrom):
module = node.module or ""
self.graph[module_name].add(module)
def get_dependencies(self, file_path: Path) -> list[DependencyInfo]:
module_name = self.file_modules.get(str(file_path), file_path.stem)
deps = self.graph.get(module_name, set())
return [DependencyInfo(name=dep) for dep in deps]
def visualize(self) -> dict[str, list[str]]:
return {k: list(v) for k, v in self.graph.items()}