Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cldk/analysis/python/backend.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -156,7 +156,8 @@ def get_callables_overview(self) -> List[PyCallableOverview]:
@abstractmethod
def get_method_bodies(self, signatures: List[str]) -> Dict[str, str]:
"""Source bodies for the given callable signatures, keyed by signature. Signatures with no
matching callable are omitted."""
matching callable are omitted, as are callables whose ``code`` is ``None`` (e.g. synthesized
callables the analyzer emits with no source text) — every returned value is a real ``str``."""

@abstractmethod
def get_decorated_callables(self, markers: List[str]) -> List[PyCallableOverview]:
Expand Down
5 changes: 3 additions & 2 deletions cldk/analysis/python/codeanalyzer/codeanalyzer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -583,9 +583,10 @@ def get_callables_overview(self) -> List[PyCallableOverview]:
return [_overview(c, class_sig, kind) for c, class_sig, kind in self._iter_callables()]

def get_method_bodies(self, signatures: List[str]) -> Dict[str, str]:
"""Return ``{signature: code}`` for the requested signatures that exist."""
"""Return ``{signature: code}`` for the requested signatures that exist and have a body
(omits callables whose ``code`` is ``None``)."""
wanted = set(signatures)
return {c.signature: c.code for c, _, _ in self._iter_callables() if c.signature in wanted}
return {c.signature: c.code for c, _, _ in self._iter_callables() if c.signature in wanted and c.code is not None}

def get_decorated_callables(self, markers: List[str]) -> List[PyCallableOverview]:
"""Return overviews of callables decorated with any of ``markers``."""
Expand Down
4 changes: 2 additions & 2 deletions cldk/analysis/python/neo4j/neo4j_backend.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -498,12 +498,12 @@ def get_callables_overview(self) -> List[PyCallableOverview]:

def get_method_bodies(self, signatures: List[str]) -> Dict[str, str]:
rows = self._run(
"MATCH (c:PyCallable) WHERE c._module IN $mods AND c.signature IN $sigs "
"MATCH (c:PyCallable) WHERE c._module IN $mods AND c.signature IN $sigs AND c.code IS NOT NULL "
"RETURN c.signature AS signature, c.code AS code",
mods=self._modules,
sigs=list(signatures),
)
return {r["signature"]: r.get("code") for r in rows}
return {r["signature"]: r["code"] for r in rows}

def get_decorated_callables(self, markers: List[str]) -> List[PyCallableOverview]:
rows = self._run(
Expand Down
3 changes: 2 additions & 1 deletion cldk/analysis/python/python_analysis.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -552,7 +552,8 @@ def get_method_bodies(self, signatures: List[str]) -> Dict[str, str]:

Returns:
A dict mapping each signature to its source body. Signatures with no matching callable
are omitted.
are omitted, as are callables whose ``code`` is ``None`` — every returned value is a
real ``str``.
"""
return self.backend.get_method_bodies(signatures)

Expand Down