Repository navigation
Conversation
|
@astroknot-sheep is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @astroknot-sheep, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thanks for signing the CLA, @astroknot-sheep! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
chrikrah
left a comment
There was a problem hiding this comment.
@astroknot-sheep from my side this can be merged.
non-blocking: only the strip_docstrings=True fallback your description names kept the full range, (3, 35).
# git archive 1b8e4fa9c, Python 3.12.3; haystack resolves into each tree
$ python -m pytest test/components/preprocessors/test_python_code_splitter.py -q -p no:cacheprovider
75 passed # head 1b8e4fa9c
1 failed, 74 passed # python_code_splitter.py from base 622967d
# probe, 30-line body, length 8, overlap 2: method with decorator, CRLF and docstring
# cases all map each piece to its own lines; with strip_docstrings=True: (3, 35) x5
# not run: the rest of test/components/preprocessors
Want an issue for mapping that case?
|
Thanks a lot for testing this so carefully, @chrikrah! Yes, the |
|
Thanks for signing the CLA, @astroknot-sheep! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
|
It's festive season back here in India, so I am running a bit busy rn.
…On Fri, 6 Nov 2026 at 6:19 PM, Sebastian Husch Lee ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/components/preprocessors/test_python_code_splitter.py
<#13437 (comment)>
:
> + def test_secondary_split_pieces_report_their_own_line_range(self):
+ body = "".join(f" value_{i} = compute_something_long({i}, factor={i * 3})\n" for i in range(30))
+ source = "import os\n\n# helper\n\ndef big():\n" + body + "\n\ndef small():\n return 1\n"
+ splitter = PythonCodeSplitter(
+ min_effective_lines=1, max_effective_lines=5, secondary_split_length=8, secondary_split_overlap=2
+ )
+ result = splitter.run(documents=[Document(content=source)])
+ secondary = [c for c in result["documents"] if c.meta.get("secondary_split")]
+ assert len(secondary) > 1
+
+ lines = source.splitlines(keepends=True)
+ for chunk in secondary:
+ start, end = chunk.meta["start_line"], chunk.meta["end_line"]
+ assert 5 <= start <= end <= 35
+ # The lines the metadata points at are the code in the chunk.
+ assert chunk.content.strip().endswith("".join(lines[start - 1 : end]).strip())
Could you fix the failing mypy check here? chunk.content is str | None:
test/components/preprocessors/test_python_code_splitter.py:868: error: Item "None" of "str | None" has no attribute "strip" [union-attr]
⬇️ Suggested change
- assert chunk.content.strip().endswith("".join(lines[start - 1 : end]).strip())
+ assert chunk.content is not None
+ assert chunk.content.strip().endswith("".join(lines[start - 1 : end]).strip())
—
Reply to this email directly, view it on GitHub
<#13437?email_source=notifications&email_token=AZFUEAGUCLAQ7IUSW6JJWZL5XXCF5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKOBQGAZDQMRWGIZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#pullrequestreview-5800282622>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZFUEABZZPPA43MFX4ACR4T5XXCF5AVCNFSNUABFKJSXA33TNF2G64TZHMZDEMJWGU2DMNZYHNEXG43VMU5TMMBTGI3TQMRTGU2KC5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AZFUEACSUZDFBJHL4JBCWNL5XXCF5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKOBQGAZDQMRWGIZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/AZFUEAFTNJGUJF5GBBIUPYL5XXCF5A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKOBQGAZDQMRWGIZKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
….content for mypy
|
Thanks @sjrl! Applied both suggestions: single backticks in the docstring, and the |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks @sjrl! Updated the docs and added the clamp comment as you asked. Splitter tests, mypy and ruff are green locally. |
Related Issues
Proposed Changes:
When an oversized function or method goes through the line-based secondary split, every piece got a deep copy of the whole unit's metadata, including
start_line/end_line. So all pieces of one function pointed at the same full range._secondary_splitnow maps each piece back to the file lines it covers, using thesplit_idx_startoffsetDocumentSplitteralready sets. The unit source ends atunit.end_lineand may begin a few lines earlier (blank lines and comments before thedef), so the first physical line isend_line - line_count(source) + 1. Each piece's range is clamped to the function'sstart_line..end_line, which matches how primary chunks treat leading blank lines and comments. Lines are counted withio.StringIO(newline=""), the same\n/\r\n/\rrule_extract_unitsuses after #13301.When
strip_docstrings=Trueremoved a docstring, the unit source no longer lines up with the file, so those pieces keep the function's full range as before.How did you test it?
test_secondary_split_pieces_report_their_own_line_range: checks that each piece'sstart_line..end_lineslice of the source matches the piece content, and that the ranges are increasing and span the function. It fails on main and passes with the fix.pytest test/components/preprocessors/test_python_code_splitter.py: 75 passed.ruff check/ruff format --checkclean.Notes for the reviewer
Other metadata (
unit_kinds,qualified_name,secondary_split_index, ...) is unchanged. Only the line range is narrowed per piece. The class docstring mentions this.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests.