Skip to content

fix: keep docstring-only Python chunks valid - #12346

Merged
sjrl merged 3 commits into
deepset-ai:mainfrom
Elonon901001:fix/python-code-splitter-docstring-only
Oct 15, 2026
Merged

sjrl merged 3 commits into
deepset-ai:mainfrom
Elonon901001:fix/python-code-splitter-docstring-only

Conversation

@Elonon901001

Copy link
Copy Markdown
Contributor

Summary

Fixes #12330.

When strip_docstrings=True removes the only statement in a function or class, keep the generated chunk valid by inserting an indented pass. Add a regression test that parses docstring-only functions and classes with ast.parse, plus the required release note.

Validation

  • hatch run test:unit --no-cov test/components/preprocessors/test_python_code_splitter.py -q — 71 passed.
  • git diff --check

I used an AI assistant to help prepare this PR, reviewed the changes, and ran the relevant tests.

@Elonon901001
Elonon901001 requested a review from a team as a code owner August 14, 2026 09:20
@Elonon901001
Elonon901001 requested review from julian-risch and removed request for a team August 14, 2026 09:20
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@Elonon901001 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @Elonon901001, thanks for your interest in contributing to Haystack! 🙏

⚠️ Issue #12330 is already being addressed by open pull request(s) #12331. Before opening a PR for an issue, please check whether a PR is already linked to it, and consider contributing to the existing PR instead. We may close duplicate PRs to keep the review queue manageable.

This is an automated message to help us keep the review queue healthy.

@CLAassistant

CLAassistant commented Aug 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Elonon901001, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from julian-risch August 14, 2026 10:38
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Aug 14, 2026
@HaystackBot
HaystackBot marked this pull request as draft August 14, 2026 10:38
@HaystackBot
HaystackBot marked this pull request as ready for review August 14, 2026 14:37
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @Elonon901001! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Oct 10, 2026

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/preprocessors
  python_code_splitter.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl
sjrl merged commit e8497db into deepset-ai:main Oct 15, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PythonCodeSplitter with strip_docstrings=True emits invalid Python for docstring-only function/method/class bodies

5 participants