docs(context): fix unrunnable ContextGraph docstring example - #921
docs(context): fix unrunnable ContextGraph docstring example#921pravit-amp wants to merge 3 commits into
Conversation
The module docstring's Example Usage block called add_node/add_edge with keyword arguments they do not accept. add_node(node_id, node_type, ...) takes node_type positionally and has no properties parameter, so the documented call raised TypeError; add_edge's parameter is edge_type, so type= fell through to **properties and polluted edge metadata while appearing to work. Two of the three broken forms failed silently rather than raising, storing a nested properties dict or a stray type key instead of erroring. Add regression tests that execute the documented calls and assert the docstring itself does not reintroduce the invalid kwargs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoFix ContextGraph docstring example and add regression tests
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
The guards added in the previous commit could pass while checking nothing. _example_block() terminated the capture at the first "\n\n". The Example Usage block already contains ">>> " spacer lines, so any reformatting that turned one into a bare blank line would truncate the capture -- potentially to empty -- and the guards would then scan a block that no longer held the add_node/add_edge calls they exist to police. Both guards also iterated over re.findall() without asserting a match. Zero matches meant zero assertions and a green test, so the two failure modes compounded: a truncated block produced no matches, and no matches produced a pass. Terminate the block at the next top-level section header (^\S) or end of docstring instead, so blank lines inside the example are harmless, and assert the captured block, the parsed statement list, and each guard's match list are all non-empty. Extract statements with doctest.DocTestParser rather than a line regex. This also catches a call reformatted across "..." continuation lines, which the ">>> graph.add_node(.*" pattern silently skipped, and lets test_documented_calls_execute exec the docstring's own statements instead of a retyped copy that could drift from it. Full doctest.testmod isn't usable here: add_node/add_edge return True and the docs carry no expected-output lines, so it reports 4 spurious failures. Narrow the kwarg check to (?<![\w])type\s*= so a legitimate node_type= or edge_type= in the docs no longer trips a guard aimed at bare type=. Verified by mutating the module docstring and re-running the guards: extra blank lines with a valid example still pass; regressed add_node/add_edge, a type= on a continuation line, deleted calls, and a deleted section all fail; a legitimate node_type= passes. 6 passed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Description
The
Example Usageblock in theContextGraphmodule docstring could not be run as written. Three lines passed keyword arguments the target methods do not accept.add_node(node_id, node_type, content=None, **properties)takesnode_typepositionally and has nopropertiesparameter, so the documented call raisedTypeError.add_edge's parameter isedge_type, sotype=fell through to**propertiesand polluted edge metadata while appearing to work.Two of the three broken forms failed silently rather than raising — storing a nested
propertiesdict or a straytypekey instead of erroring — which is why this was worth a regression guard rather than just a text fix.Type of Change
Related Issues
Closes #920
Changes Made
semantica/context/context_graph.py:75-77— passnode_type/edge_typepositionally and node properties as**kwargstests/context/test_context_graph_docstring_example.py— new regression tests (6): execute the documented calls, assert node properties are stored flat rather than nested, assert the edge type is not a stray metadata key, and fail if the docstring reintroducestype=/properties=on those linesTesting
python -m build)Verified the regression guard actually fails: restored the original docstring, confirmed 2 of the 6 tests fail with their diagnostic messages, then restored the fix and confirmed all 6 pass.
Scope check: every
add_node(/add_edge(call site in the repo already uses the correct form. The remainingtype=hits are NetworkX graphs (semantica/split/methods.py:1190,tests/kg/test_link_predictor.py), a different API.Test Commands
Documentation
Breaking Changes
Breaking Changes: No
The change is confined to a docstring plus a new test file. No signatures, behaviour, or public API affected.
Checklist
Additional Notes
Two deliberate scope decisions, flagged for reviewers:
black/isortwant to reformat pre-existing regions ofcontext_graph.py(import ordering, the..kgimport block, trailing whitespace on the untouched>>>lines at 73/81). I did not apply any of it — it is unrelated to this fix and would bury a 3-line diff in noise. Happy to open a separate formatting PR if that is wanted.find_precedents("loan_approval", limit=5)at line 91 may be a fourth defective line. The signature isfind_precedents(decision_id, limit=10), but the example passes a category. It returns[]rather than raising, so the example runs — it just demonstrates incorrect usage. There is a separatefind_precedents_by_scenariothat may be what was intended. I left it out because the correct fix depends on maintainer intent and would pull a design question into a docs PR. Happy to include it here or file it separately, whichever you prefer.