Skip to content

refactor(edges): drop 608 lines of shadowed duplicate code - #52

Merged
lexasub merged 1 commit into
mainfrom
refactor/remove-shadowed-edge-extractor-code
Aug 1, 2026
Merged

refactor(edges): drop 608 lines of shadowed duplicate code#52
lexasub merged 1 commit into
mainfrom
refactor/remove-shadowed-edge-extractor-code

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Re: #10

What's here

edge_extractor.py defines four module-level functions twice. Python keeps the last definition, so the first copy of each has never executed:

function shadowed copy live copy
_node_text 660–662 1282–1283
_find_enclosing_type 671–680 1286–1294
_find_enclosing_callable 683–692 1297–1305
_add_type_relation_edges 695–1279 1308–1371

The last one is the interesting case. It spans 585 lines because a block was indented one level too deep during the extract-methods refactor, nesting a second copy of ten EdgeExtractor methods inside it as local functions — including a second _extract_call_edges carrying the same for n in [] defect as the real one (that's the bug fixed in #50). None of it is reachable.

edge_extractor.py: 1371 → 759 lines. EdgeExtractor itself (lines 31–657) is untouched.

Why this is safe

Deleting a shadowed definition is a no-op by construction — the interpreter was already discarding it. I verified rather than asserted it: extracted the source of each live callable via inspect.getsource before and after, and all five are byte-identical (ignoring docstrings).

_node_text                   live code identical to HEAD: True
_find_enclosing_type         live code identical to HEAD: True
_find_enclosing_callable     live code identical to HEAD: True
_add_type_relation_edges     live code identical to HEAD: True
_containment_edge_kind       live code identical to HEAD: True
5/5 live functions byte-identical (docstrings excluded)

_containment_edge_kind is included as a control — it has no duplicate and is untouched.

The one content change

When these functions were duplicated, the surviving copies lost their docstrings — the documented originals were the ones being discarded. So I carried the four docstrings back onto the live copies. That's the only thing in this diff that isn't a deletion, and it's why the numbers are −608/+4 rather than a pure −608.

On #10 itself

The split that issue asks for has already happened — extract_edges delegates to _extract_containment_edges, _extract_import_edges, _extract_call_edges and six more. The issue also points at ast_rag/ast_parser.py, which no longer exists. So I've treated it as "clean up what that refactor left behind" rather than redoing it. Happy to close it as done, or leave it open if you had further decomposition in mind — the remaining length is in EdgeExtractor's per-language branches, which could go further if you want.

Verification

ruff check ast_rag/         All checks passed!
ruff format --check         1 file already formatted
pytest tests/               3 failed, 174 passed, 2 xfailed

Identical to main — same three pre-existing failures, which #51 fixes. This branch is independent of both #50 and #51 and touches no line either of them touches.

edge_extractor.py defines four module-level functions twice. Python keeps the
last definition, so the first copy of each has never executed:

  _node_text                 660-662     shadowed by 1282-1283
  _find_enclosing_type       671-680     shadowed by 1286-1294
  _find_enclosing_callable   683-692     shadowed by 1297-1305
  _add_type_relation_edges   695-1279    shadowed by 1308-1371

The last of those is the interesting one. It spans 585 lines because a block
was indented one level too deep during the extract-methods refactor, nesting a
second copy of ten EdgeExtractor methods inside it as local functions --
including a second _extract_call_edges carrying the same `for n in []` defect
as the real one. None of it is reachable.

This deletes the shadowed copies, which is a no-op by construction: the
interpreter was already discarding them. Verified by extracting each live
callable's source before and after -- all five are byte-identical.

The surviving copies had lost their docstrings when they were duplicated, so
those are carried back over. That is the only content change.

edge_extractor.py: 1371 -> 759 lines. EdgeExtractor itself (lines 31-657) is
untouched.

Re: #10 -- the split this issue asks for has already happened; extract_edges
delegates to _extract_containment_edges / _extract_import_edges /
_extract_call_edges and six more. The issue also points at ast_rag/ast_parser.py,
which no longer exists. What remained was this debris from that refactor.

Suite unchanged from main: 3 failed, 174 passed, 2 xfailed (same three
pre-existing failures, addressed separately in #51).
@r0h1tb

r0h1tb commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI on this PR is red at the Lint with ruff step, which is pre-existing and unrelated to these changes — main fails identically.

Ruff is unpinned and [tool.ruff] never set select, so a newer ruff widened its default rule set and the tree went from clean to 496 findings with no code change. Running today's ruff against 16ae8bd — the last commit whose CI run was green — also reports 496.

Because lint runs before pytest, the Run tests step is skipped, so CI hasn't actually executed the suite since 2026-07-27.

#51 fixes that and is passing. Once it lands, this PR should go green on a re-run; I've verified all three CI steps locally in the meantime.

@lexasub
lexasub merged commit 43cdb9b into main Aug 1, 2026
1 check failed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in raged kanban Aug 1, 2026
@lexasub
lexasub deleted the refactor/remove-shadowed-edge-extractor-code branch August 1, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants