Skip to content

Commit f81c4e5

Browse files
ayushcodes10safishamsi
authored andcommitted
Warn when a cleanly parsed code file yields no symbols
A code file that parses with zero errors but still produces nothing beyond its own bare file node is usually a plain data literal the AST extractor has nothing to model (a const array, a module export of plain data), not a code file that legitimately has no symbols. Those two cases looked identical in the output: the file silently entered the graph as an isolated, zero edge node, and nothing reported it. A real corpus measured in the issue had 88 such nodes covering roughly 40 percent of the corpus, with not one edge among them. Add a complementary check next to the existing syntax error warning, gated on the opposite condition (no parse_errors and no extractor error) so the two can never double report the same file: a file already explained by a genuine parse error or a missing optional dependency is excluded here. Fixes Graphify-Labs#3946. (cherry picked from commit 3b3ee82)
1 parent e8b5d27 commit f81c4e5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎graphify/extract.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7653,6 +7653,39 @@ def _describe_syntax_error(rel: str, line: "int | None", kept: int) -> str:
76537653
file=sys.stderr, flush=True,
76547654
)
76557655

7656+
# #3946: a code file that parses CLEANLY (no parse_errors — distinct from
7657+
# the #2551/#2599 case just above, where _syntax_error_files already
7658+
# explains the loss) but still yields only its own bare file node is
7659+
# usually a plain data literal the AST extractor has nothing to model
7660+
# (`const BANK = [...]`), not a code file with no symbols. Nothing
7661+
# reported this before; the file silently entered the graph as a bare,
7662+
# zero-edge node, indistinguishable from a legitimately symbol-free file.
7663+
_symbolless_files: list[tuple[str, int]] = []
7664+
for i, _p in enumerate(paths):
7665+
_res = per_file[i] or {}
7666+
if _res.get("parse_errors") or _res.get("error"):
7667+
continue
7668+
if len(_res.get("nodes", [])) <= 1:
7669+
try:
7670+
_size = _p.stat().st_size
7671+
except OSError:
7672+
_size = 0
7673+
_symbolless_files.append((os.path.relpath(str(_p), str(root)).replace("\\", "/"), _size))
7674+
if _symbolless_files:
7675+
_total_bytes = sum(size for _, size in _symbolless_files)
7676+
_total_mb = _total_bytes / (1024 * 1024)
7677+
_shown_sl = ", ".join(rel for rel, _ in _symbolless_files[:5])
7678+
_more_sl = (
7679+
f" (+{len(_symbolless_files) - 5} more)"
7680+
if len(_symbolless_files) > 5 else ""
7681+
)
7682+
print(
7683+
f" warning: {len(_symbolless_files)} code file(s) yielded no symbols "
7684+
f"({_total_mb:.2f} MB); they may be data rather than code: "
7685+
f"{_shown_sl}{_more_sl}",
7686+
file=sys.stderr, flush=True,
7687+
)
7688+
76567689
for path, result in zip(paths, per_file):
76577690
if path.suffix in (".tf", ".tfvars", ".hcl"):
76587691
prepare_terraform(result, path, root)

0 commit comments

Comments
 (0)