Repository navigation
Conversation
|
@Aurantium-47 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
anakin87
left a comment
There was a problem hiding this comment.
Thanks for working on this!
-
Please simplify the implementation by starting from the first decorator's AST line and walking backward until we find the
@marker. That should also handle multiline decorators in an efficient way. -
Could you also enable "Allow edits by maintainers" on this PR so we can make small refinements if needed?
Walk backward from the first decorator AST line to its opening @ marker instead of tokenizing the whole source. Cover multiline decorators, unusual whitespace, Unicode expressions and newline variants while preserving exact chunk content and metadata.
anakin87
left a comment
There was a problem hiding this comment.
I left a few comments.
"Allow edits by maintainers" is still disabled on this PR. See https://github.com/deepset-ai/haystack/blob/main/CONTRIBUTING.md#working-from-github-forks for help.
| upgrade: | ||
| - | | ||
| Re-split Python sources whose first class member is decorated if their chunks were | ||
| produced with ``PythonCodeSplitter(preserve_class_definition=True)``. Previously, | ||
| the first member's decorators could be copied into other members' chunks. No | ||
| configuration changes are required. | ||
| fixes: | ||
| - | | ||
| ``PythonCodeSplitter`` now excludes member decorators from the class signature | ||
| prepended to separate member chunks, preserving each member's original decorators | ||
| instead of duplicating them or applying them to unrelated methods. | ||
| Parenthesized multiline decorators are kept with their definitions, and their | ||
| start-line metadata points to the opening decorator marker. |
There was a problem hiding this comment.
Let's simplify the release note
| upgrade: | |
| - | | |
| Re-split Python sources whose first class member is decorated if their chunks were | |
| produced with ``PythonCodeSplitter(preserve_class_definition=True)``. Previously, | |
| the first member's decorators could be copied into other members' chunks. No | |
| configuration changes are required. | |
| fixes: | |
| - | | |
| ``PythonCodeSplitter`` now excludes member decorators from the class signature | |
| prepended to separate member chunks, preserving each member's original decorators | |
| instead of duplicating them or applying them to unrelated methods. | |
| Parenthesized multiline decorators are kept with their definitions, and their | |
| start-line metadata points to the opening decorator marker. | |
| fixes: | |
| - | | |
| ``PythonCodeSplitter`` now keeps decorators with the methods or classes they | |
| belong to, without copying them to other chunks. This also works with | |
| multiline decorators. |
| if ( | ||
| isinstance(first_statement, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)) | ||
| and first_statement.decorator_list | ||
| ): |
There was a problem hiding this comment.
Could we move the type check into _definition_start and accept ast.stmt, so we don't repeat it in the callers?
|
|
||
|
|
||
| class TestDecorators: | ||
| @pytest.mark.parametrize( |
There was a problem hiding this comment.
I'd remove these tests and reduce the new test combinations:
- a first method with
@property, with class preservation on/off - a method with a multiline decorator and a comment
- a top-level function with a multiline decorator, with LF/CRLF/CR
We can check exact chunk content and line metadata without repeating the general metadata checks. I'd put the first test in TestPreserveClassDefinition and the other two in TestDecorators.
Centralize statement type handling in the decorator boundary helper. Replace the broad regression matrix with the requested focused content and line-range checks, and use the concise fixes release note.
|
Hi @Aurantium-47, 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 |
|
Hi @Aurantium-47, just a friendly reminder: this PR is still in draft because the Contributor License Agreement (CLA) hasn't been signed yet. We'd love to review your contribution! Please sign the CLA via the link in the |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
Thanks for signing the CLA, @Aurantium-47! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
Related Issues
No matching bug report found. The original Python splitter feature is #11354. This is separate from the docstring stripping fix in #13309 and qualified-name metadata work in #11875.
Proposed Changes:
PythonCodeSplitter(preserve_class_definition=True)currently includes the first class member's decorators in the reusable class signature. This duplicates them on that member and copies them onto unrelated later members. For example, a first@propertymakes the chunk for a later ordinary method look like another property.Use the first decorator marker as the member boundary. AST expression line numbers alone are insufficient for parenthesized multiline decorators: the expression can begin after the
@(line. A single lexical pass maps decorator-expression lines to their opening marker; the same boundary helper is used for class signatures, class headers, members and top-level definitions. Only a logical line's first meaningful@counts, not matrix multiplication. Newlines are normalized for lexing only; output slices retain original source spelling.This also keeps parenthesized decorators with their definitions and reports their actual marker in
start_line. Ordinary decorator and undecorated metadata is unchanged. This does not redesign the existing bare class-header chunk or promise independently executable chunks.How did you test it?
All project execution used Hatch, with Python 3.12.14 and a reduced local test environment (not included in this PR).
test/components/preprocessors/test_python_code_splitter.py: 134 passed, one existing Document-mutation warning; independently rerun with the same result.76fc2d3d7492ec243eed40eb939a836f2a8b29da: 46 failed, 14 passed. They cover first methods, async methods, nested classes, outer classes, top-level functions, parenthesized decorators, comments, preservation on/off, LF/CRLF/CR, exact ordered content and source metadata.class_signaturefield was excluded from that compatibility comparison.--follow-imports=silent, release-note backtick check, andgit diff --checkpassed.Notes for the reviewer
This implementation, tests and PR description were generated by AI assistants. A separate AI reviewer reviewed the revised patch and independently reran the checks described above. The account owner has reviewed and understood the changes. Tests were executed by the preparing AI assistant and independent AI reviewer.
The additional token pass has a measurable cost. Five-run median extraction-only measurements for 1,000 synthetic definitions were 9.52 ms → 17.06 ms for plain functions and 13.24 ms → 24.50 ms for decorated functions, approximately 1.8x at that stage. These are not end-to-end throughput measurements. The implementation tokenizes once per input, not once per definition.
The release note advises re-splitting affected sources and documents the parenthesized-decorator start-line correction. CLA signature status has not been verified; no agreement has been accepted on the contributor's behalf.
Checklist
fix:PR title.