Description
Several functions use mutable default arguments, a classic Python bug where mutations to the default value are shared across all calls:
-
api/project.py:96 — process_git_history:
def process_git_history(self, ignore: Optional[List[str]] = []) -> GitGraph:
-
api/analyzers/source_analyzer.py:184 — analyze_local_folder:
def analyze_local_folder(self, path: str, g: Graph, ignore: Optional[list[str]] = []) -> None:
-
api/graph.py:482 — connect_entities:
def connect_entities(self, relation: str, src_id: int, dest_id: int, properties: dict = {}) -> None:
Impact
If any of these functions mutate their default argument (e.g., ignore.append(...) or properties['key'] = ...), the mutation persists across subsequent calls, causing hard-to-debug state leakage.
Suggested Fix
Use None as the default and create a new list/dict inside the function:
def process_git_history(self, ignore: Optional[List[str]] = None) -> GitGraph:
if ignore is None:
ignore = []
Note: analyze_sources in project.py already uses this pattern correctly.
Context
Found during code review of PR #522.
Description
Several functions use mutable default arguments, a classic Python bug where mutations to the default value are shared across all calls:
api/project.py:96—process_git_history:api/analyzers/source_analyzer.py:184—analyze_local_folder:api/graph.py:482—connect_entities:Impact
If any of these functions mutate their default argument (e.g.,
ignore.append(...)orproperties['key'] = ...), the mutation persists across subsequent calls, causing hard-to-debug state leakage.Suggested Fix
Use
Noneas the default and create a new list/dict inside the function:Note:
analyze_sourcesinproject.pyalready uses this pattern correctly.Context
Found during code review of PR #522.