fix(extract): stop Python property-accessor decorators minting stub nodes
`@x.setter` / `@x.getter` / `@x.deleter` are the property-descriptor
protocol, not references to corpus symbols named setter/getter/deleter.
The Python decorator-edge pass (#2154) ran `ensure_named_node` on the
decorator's head symbol, so every property with a setter/deleter/getter
redefinition fabricated a sourceless stub node and a false `references`
(context=decorator) edge onto it — the same provenance pollution the
builtin-decorator noise list already guards against for `@property`.
`_python_is_property` already recognizes the `.getter` form for the
read-semantics; the decorator-edge path now mirrors it and skips any
`.setter`/`.getter`/`.deleter` decorator. Imported decorators reached
through an attribute (`@app.route`) are unaffected.
Regression test asserts no decorator edge and no sourceless stub for a
property with setter and deleter accessors.
(cherry picked from commit 2dc8972c67)
This commit is contained in:
1 parent
7536dc0665
commit
c36516988e
2 files changed
+42
No files matched your search
@@ -89,6 +89,14 @@ _PYTHON_DECORATOR_NOISE = frozenset({
|
||||
"final", "no_type_check", "runtime_checkable", "dataclass",
|
||||
})
|
||||
|
||||
# `@x.setter` / `@x.getter` / `@x.deleter` are the property-descriptor protocol,
|
||||
# not references to corpus symbols named setter/getter/deleter. Emitting a
|
||||
# decorator edge for them fabricates a sourceless stub on nearly every file with
|
||||
# a property setter, and the bare `deleter`/`getter` stub collapses into a
|
||||
# cross-file god node. `_python_is_property` already excludes `.getter` for the
|
||||
# read-semantics; the decorator-edge path mirrors it here.
|
||||
_PYTHON_PROPERTY_ACCESSOR_SUFFIXES = (".setter", ".getter", ".deleter")
|
||||
|
||||
def _python_collect_type_refs(node, source: bytes, generic: bool, out: list[tuple[str, str]]) -> None:
|
||||
"""Walk a Python type annotation; append (name, role) where role is 'type' or 'generic_arg'.
|
||||
|
||||
@@ -7280,6 +7288,14 @@ def _extract_generic(
|
||||
for child in node.children:
|
||||
if child.type != "decorator":
|
||||
continue
|
||||
# `@x.setter` / `@x.getter` / `@x.deleter` is the
|
||||
# property-descriptor protocol, not a reference to a
|
||||
# corpus symbol; emitting an edge mints a sourceless
|
||||
# stub (and a `deleter`/`getter` god node).
|
||||
deco_expr = next(iter(child.named_children), None)
|
||||
deco_text = _read_text(deco_expr, source) if deco_expr is not None else ""
|
||||
if deco_text.endswith(_PYTHON_PROPERTY_ACCESSOR_SUFFIXES):
|
||||
continue
|
||||
deco_name = _python_decorator_name(child, source)
|
||||
# Builtin/stdlib decorators are noise: no stub nodes,
|
||||
# no false rewires onto same-named local definitions.
|
||||
|
||||
@@ -225,3 +225,29 @@ def test_undecorated_function_emits_no_decorator_edge(tmp_path):
|
||||
" pass\n")
|
||||
r = extract([f], cache_root=tmp_path)
|
||||
assert _deco_edges(r, _func_nid("pkg/plain.py", "plain")) == set()
|
||||
|
||||
|
||||
def test_property_accessor_decorators_emit_no_edge_or_stub(tmp_path):
|
||||
# `@x.setter` / `@x.getter` / `@x.deleter` are the property-descriptor
|
||||
# protocol, not references to corpus symbols. Pre-fix they minted a
|
||||
# sourceless stub (`setter`/`getter`/`deleter`) on every property with a
|
||||
# setter and a decorator edge onto it — provenance pollution, and the bare
|
||||
# `deleter`/`getter` stub became a cross-file god node.
|
||||
f = _write(tmp_path / "pkg" / "prop.py",
|
||||
"class Config:\n"
|
||||
" @property\n"
|
||||
" def name(self):\n"
|
||||
" return self._n\n"
|
||||
" @name.setter\n"
|
||||
" def name(self, v):\n"
|
||||
" self._n = v\n"
|
||||
" @name.deleter\n"
|
||||
" def name(self):\n"
|
||||
" del self._n\n")
|
||||
r = extract([f], cache_root=tmp_path)
|
||||
assert _deco_edges(r, _method_nid("pkg/prop.py", "Config", "name")) == set()
|
||||
node_ids = {n["id"] for n in r["nodes"]}
|
||||
assert _make_id("setter") not in node_ids
|
||||
assert _make_id("deleter") not in node_ids
|
||||
# No sourceless stub was fabricated at all.
|
||||
assert all(n.get("source_file") for n in r["nodes"])
|
||||
Reference in new issue
Block a user