[错误]: Python @property 读取不会产生边,因此 callers_of 和 find_dead_code 都会错过每个消费者

作者: peyck创建于 2026年9月19日更新于 2026年9月19日
标签bug
  1. Create a repo with two files. engine.py: class Engine: def run(self) -> str: return "ok" class Orchestrator: def init(self) -> None: self._engine = Engine() @property def secondary_engine(self) -> Engine: """Read as an attribute, never called with ().""" return self._engine consumer.py: from engine import Orchestrator class Holder: def init(self) -> None: self.orch = Orchestrator() def via_self(self) -> str: """Receiver is self -> resolves.”” return self.helper() def helper(self) -> str: return "x" def reads_property(self) -> str: """Receiver is an attribute chain -> property read, no edge at all.”” engine = self.orch.secondary_engine return engine.run() 2. git init && git add -A && git commit -m init 3. code-review-graph build 4. Query callers of the property, e.g. via the MCP tool: query_graph(pattern="callers_of", target="/engine.py::Orchestrator.secondary_engine") Tested on 2.3.9 (also reproduces on 2.3.2), Python 3.11, Linux. Expected vs actual behavior Expected: callers_of("engine.py::Orchestrator.secondary_engine") reports Holder.reads_property, which reads the property on line 17. Actual: it reports 0 callers. Reading a @property never creates an edge, so the property node exists with nothing pointing at it. All CALLS edges produced by the build above: consumer.py::Holder.init -> engine.py::Orchestrator (line 6) consumer.py::Holder.reads_property -> run (line 18) consumer.py::Holder.via_self -> consumer.py::Holder.helper (line 10) consumer.py::entrypoint -> consumer.py::Holder (line 22) consumer.py::entrypoint -> consumer.py::Holder.reads_property (line 22) engine.py::Orchestrator.init -> engine.py::Engine (line 8) Two defects are visible: 1. The property read on line 17 produces no edge at all. Not an unresolved one, none. 2. The call on line 18 has the bare target "run" instead of engine.py::Engine.run, because the receiver is a local whose type is not inferred. callers_of reflects both: consumer.py::Holder.helper via self.helper() -> 1 (correct) engine.py::Engine.run via engine.run() -> 0 (bare target) engine.py::Orchestrator.secondary_engine via

内容来源: tirth8205/code-review-graph