Repository navigation
Read Python source: docstrings and comments become located claims - #51
Merged
Merged
Conversation
Folder builds (and refreshes) now read .py files by default, for their
prose only, using the standard library's ast and tokenize, so there are
still no dependencies.
- parse_python(): docstring paragraphs and comment runs become blocks;
everything else is blanked in place, so spans and line numbers stay
true to the file (ast's UTF-8 byte columns are converted to characters).
Each block records the definition it documents or sits in, and claims
carry it as `symbol` ("ShardStore.put").
- Not prose: code, doctests, `::` literal blocks, docstring paragraphs and
comment runs that parse as Python, pragmas (# noqa, # type:, ...),
shebangs. reST roles (:meth:`x`) and list markers are blanked; list
items are separate blocks; "#:" attribute comments read cleanly.
- Docstring sentences are graded like paragraphs; comments no higher than
medium. Definitions, imports and the module's dotted path are marked-up
names, so they become entities wherever prose mentions them.
- A file that is not valid Python is skipped with the line it failed on.
- The enclosing-definition lookup is a precomputed line map: an 843 KB
file with 18,000 blocks parses in about 0.6 s.
Benchmarks: suites now name their file types (corpus.suffixes; prose by
default), so the docs suite is unaffected by the new default. A code
suite (bench/contextmesh-code.json, 18 + 6 questions over contextmesh/)
shows the walk at 15/18 vs BM25 top-1 12/18 and top-3 15/18, refusing 6/6
out-of-scope questions; docs/BENCHMARKS.md records it with the caveat
that its questions were written from the extracted claims.
Tests: offset preservation, prose vs code, symbols, pragmas/examples/
commented-out code excluded, list items and #: comments, marked names,
spans, non-ASCII columns for docstrings and comments, invalid Python,
folder builds, comment grading, entities from definitions, prose-only
builds, and a refresh retiring a changed docstring. Four behaviours were
mutation-checked; two tests were strengthened until they caught theirs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found reviewing this PR:
- Code names made generic words into hub entities. Every function name,
every import and the bare module name were marked up, so `graph`,
`file`, `read`, `json`, `field`, `time`, `Path` became entities matching
every prose use of the word (graph: 127 claims, file: 91, read: 49).
Now only names distinctive as written are marked: dotted/qualified,
snake_case or capitalised, the module's dotted path, and names imported
from the project (relative imports). Absolute imports are not marked:
separating stdlib from third-party needs a list that differs across
Python versions. Entities on contextmesh/: 336 -> 269.
- Text after "::" was treated as a literal block whenever it was indented
at all. reST makes it literal only when indented more than the paragraph
introducing it; the block now ends at the first paragraph back at that
indent.
Verified: identical graph and resolver under PYTHONHASHSEED 0 and 4242;
a prose-only folder builds byte-identically on main and on this branch;
0.55 MB of code gives 1,001 claims at 86 MB peak.
Benchmark: the code suite now shows the walk at 13/18 (was 15/18). Both
lost answers had been reached through generic hubs ("not a *field* to be
regenerated" via dataclasses.field). docs/BENCHMARKS.md records the
corrected numbers, why they moved, and that the code suite's corpus is
the project's own source, so it moves with the code: compare methods
within one run. The docs suite is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README edit in the previous commit changed the docs corpus (it is part of it): fingerprint 92c57aeb78f8236b, 805 claims. Accuracy and refusals are unchanged; the walk's mean tokens and the read-everything total moved slightly, and the write-up now quotes this run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Code-aware ingestion. Folder builds and refreshes now read
.pyfiles by default, for their prose only: docstrings and comments, never code. Parsing uses the standard library'sastandtokenize, so there are still no dependencies.How it works
astreports columns in UTF-8 bytes, which are converted to characters.symbol: "ShardStore.put".::literal blocks, docstring paragraphs and comment runs that parse as Python, pragmas (# noqa,# type:, …) and shebangs. reST roles and list markers are blanked, list items are separate blocks, and#:attribute comments read cleanly.medium.Review
These checks were run against data, as asked:
::blocks, commented-out code, pragmas, list items, reST roles,#:comments, and invalid Python.graph127 claims,file91,read49, plusjson,field,Path. Now only distinctive names are marked. Entities oncontextmesh/went from 336 to 269.::was treated as code whenever indented at all; reST requires more indentation than the introducing paragraph.PYTHONHASHSEED0 and 4242.mainand on this branch. All existing ingest and refresh tests pass.Four parser behaviours were mutation-checked. Two tests were strengthened until they caught their sabotage.
Benchmarks
Suites now declare their file types (
corpus.suffixes, prose by default). The docs suite reads Markdown and text only, and its accuracy and refusals are unchanged by code ingestion.New code suite,
bench/contextmesh-code.json, corpus843be1ee936a360c:dataclasses.field. The corrected number is the honest one.docs/BENCHMARKS.mdrecords all of this.Deliberately not added
A
--no-codeCLI flag. Refresh treats a file it no longer reads as deleted, so building with code and refreshing without it would retire every code claim. Prose-only builds remain available through the Python API'ssuffixes=.Checks
The full suite,
ruff, the demo export (byte-identical) and the leak check pass.