Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(parser): avoid duplicate Python decorators (#1767)

cipher-v72133deb3e8a
diff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.py
index 546cc4100..1209cf811 100644
--- a/packages/core/src/repowise/core/ingestion/parser.py
+++ b/packages/core/src/repowise/core/ingestion/parser.py
@@ -736,10 +736,6 @@ class ASTParser:
# Visibility
modifier_texts = [_node_text(m, src) for m in modifier_nodes]
- if def_node.parent and def_node.parent.type == "decorated_definition":
- for sibling in def_node.parent.children:
- if sibling.type == "decorator":
- modifier_texts.append(_node_text(sibling, src))
# Rust: outer attributes (#[...]) are preceding siblings of the item
rust_attrs: list[str] = []
diff --git a/packages/core/src/repowise/core/ingestion/queries/python.scm b/packages/core/src/repowise/core/ingestion/queries/python.scm
index f04b12188..9966f585b 100644
--- a/packages/core/src/repowise/core/ingestion/queries/python.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/python.scm
@@ -40,7 +40,7 @@
; Decorated function or class — captures the decorator as a modifier
(decorated_definition
- (decorator) @symbol.modifiers
+ (decorator)+ @symbol.modifiers
(function_definition
name: (identifier) @symbol.name
parameters: (parameters) @symbol.params
@@ -48,7 +48,7 @@
)
(decorated_definition
- (decorator) @symbol.modifiers
+ (decorator)+ @symbol.modifiers
(class_definition
name: (identifier) @symbol.name
) @symbol.def
diff --git a/tests/unit/ingestion/parser/test_python.py b/tests/unit/ingestion/parser/test_python.py
index 12406a468..e8f226f72 100644
--- a/tests/unit/ingestion/parser/test_python.py
+++ b/tests/unit/ingestion/parser/test_python.py
@@ -86,6 +86,26 @@ class TestPythonParser:
)
assert calc_add.parent_name == "Calculator"
+ def test_function_single_decorator_recorded_once(self, parser: ASTParser) -> None:
+ fi = _make_file_info("pkg/routes.py", "python")
+ result = parser.parse_file(
+ fi,
+ b"@app.get('/users')\ndef list_users():\n return []\n",
+ )
+ list_users = next(s for s in result.symbols if s.name == "list_users")
+ assert list_users.decorators == ["@app.get('/users')"]
+
+ def test_function_multiple_decorators_recorded_once_in_source_order(
+ self, parser: ASTParser
+ ) -> None:
+ fi = _make_file_info("pkg/routes.py", "python")
+ result = parser.parse_file(
+ fi,
+ b"@cache\[email protected]('/items')\ndef create_item():\n pass\n",
+ )
+ create_item = next(s for s in result.symbols if s.name == "create_item")
+ assert create_item.decorators == ["@cache", "@app.post('/items')"]
+
def test_private_visibility(self, parser: ASTParser) -> None:
fi = _make_file_info("pkg/calc.py", "python")
result = parser.parse_file(fi, PYTHON_SOURCE)