Repository navigation
fix(r): recognize contains as a class inheritance keyword - #4902
ayushcodes10 wants to merge 2 commits into
Conversation
R6Class spells its superclass argument inherit, but setClass and setRefClass both spell the identical argument contains instead. Only inherit was checked, so a setRefClass or setClass that inherits via contains silently lost its inheritance edge, with no error, since both class constructor forms are routed through the same member scanning function. Recognize contains alongside inherit when looking for a class's superclass argument, reusing the exact same base name lookup, external class node creation and inherits edge already in place for inherit.
Covers a setRefClass that inherits via contains now getting its inherits edge, plus a control confirming R6Class's own inherit keyword still works alongside it.
|
Thanks for the pull request, @ayushcodes10. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Fixes missing inheritance edges for S4 and Reference Classes by treating contains like R6's inherit when add_class_members reads a class constructor's arguments, so setRefClass("Derived", contains = "Base") now links Derived to Base. The superclass value still goes through a single-name lookup, so how it handles contains values that aren't one plain class name, such as vectors and "VIRTUAL", is the part to watch. Adds tests covering the setRefClass case and an R6Class control that confirms inherit still works.
Worth a look
contains = c(...)vector is not split into individual superclass edges —graphify/extractors/r.py:236· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 43 functions depend on the 43 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_r()— 9 callers, 7 callees
Verification — 43 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 43 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
1 of 479 test file(s) selected (0%) via static blast radius.
tests/test_r_extractor.py— impact, changed-test
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in extract\_r (not a proof).
The verifier ran both versions of extract\_r on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 more finding(s) on lines outside this diff (see the check run).
…for video + extractors The four @ayushcodes10 extractor fixes (#4902 R, #4900 elixir, #4899 dart, #4897 fortran) change per-file AST output and are AST-cached; they share the global 31->32 bump already landed via #4908/#4895. Extend the comment to credit them, and add the 0.9.100 changelog entries for #4842 and the four. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.100, now on PyPI (pip install graphifyy==0.9.100). R setClass/setRefClass contains= inheritance emits an inherits edge. Thanks for the fix, @ayushcodes10. |
Bug
add_class_members(shared bysetClass/setRefClassandR6Class-family class definitions) only ever recognized the keyinheritwhen looking for a class's superclass argument. That's R6Class's own spelling. ButsetClassandsetRefClass(S4/R5 classes) both spell the identical argumentcontainsinstead — e.g.Derived <- setRefClass("Derived", contains = "Base", ...). Since onlyinheritwas checked, every S4/R5 inheritance relationship was silently dropped — noinheritsedge emitted at all, with no error.No existing issue or PR covers this; found via self-audit of
graphify/extractors/r.py(markdown.pyhad nothing unclaimed — it's extremely heavily iterated, and every plausible gap checked was already fixed and documented with an issue number). Checked the open R-touching PRs (#2150, #2065 — no overlap; #1759 is a stale, pre-tree-sitter regex-based R extractor proposal that predates and doesn't touch the current implementation) — no overlap.Fix
Changed the single-key check to a set membership check:
if key in {"inherit", "contains"}, reusing the exact same base-name lookup, external-class node creation, andinheritsedge emission already in place forinherit.add_class_membersis only ever called from the twosetClass/setRefClass/R6-constructor call sites, so there's no risk ofcontainsmeaning something unrelated elsewhere.Tests
Added to
tests/test_r_extractor.py:test_r_setrefclass_contains_inheritance_is_recognised— regression: asetRefClassthat inherits viacontains = "Base"now gets itsinheritsedge.test_r6class_inherit_still_recognised(control): R6Class's owninheritkeyword still works unchanged alongside the newcontainshandling.Verification
git show upstream/v8:...swapped into place (restored byte-identical afterward): the regression test fails, the control passes both before and after.2 failed, 9116 passed, 82 skipped, 1 xfailed— the 2 failures are the pre-existing flakes intest_erlang_extractor.pyand the skill backtick test, unrelated to this change.python3 -m tools.skillgen --check:check OK: 134 artifact(s) match committed output and expected/.