Skip to content

[FIX][pyOpenMS] Give keyword arguments the defaults their C++ signatures declare - #10137

Merged
timosachsenberg merged 1 commit into
developfrom
claude/fix-binding-keyword-defaults
Sep 14, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
claude/fix-binding-keyword-defaults

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Four bindings declared a parameter with no default after parameters that had one. nanobind accepts that, but the resulting signature cannot be expressed in Python, so nanobind.stubgen emitted stubs that are not valid Python:

_pyopenms_datastructures.pyi:782: non-default argument follows default argument
_pyopenms_misc.pyi:1000:        non-default argument follows default argument

Each of the four arguments already has a default in the C++ signature that the binding simply did not carry over, so they become optional with those values:

Binding Argument C++ default
MultipleTesting.lfdr transf LfdrTransform::Probit
IDMapper.annotate (FeatureMap overload) spectra PeakMap()
IDMapper.annotate (ConsensusMap overload) spectra PeakMap()
SwathFile.loadMzML plugin_consumer nullptr → None

⚠️ Behaviour change

While checking lfdr against MultipleTesting.h, two of its other defaults turned out to be wrong as well. The binding declared gridsize = 100 and cut = 0.05; the C++ signature and its Doxygen documentation use 512 and 3.0. Python callers who omitted those arguments therefore silently got different results than C++ callers. They now match, which changes lfdr() output for such calls.

Note on the enum move

MultipleTesting's nested Pi0Method and LfdrTransform enums move ahead of the method chain. nanobind converts default values to Python objects while the binding is being created, so LfdrTransform::Probit has to be a registered type by the time lfdr() is bound — registering the enums afterwards, as before, would raise during module import. Both remain reachable at the same names (MultipleTesting.LfdrTransform, MultipleTesting.Pi0Method).

Verification

Linux x86_64 / CPython 3.11, full OpenMS + pyOpenMS build:

  • A scan of all 15 binding files reports 0 remaining default-ordering violations (was 4 — ast.parse only reports the first error per file, which is why the stubs only surfaced 2).
  • All 18 generated .pyi files parse; previously 2 did not.
  • lfdr(p_values, pi0) returns exactly what the explicit (…, Probit, 1.5, 1e-8, 512, 3.0) call returns.
  • Both IDMapper.annotate overloads work without the spectra argument.
  • pyOpenMS suite unchanged: 5957 passed, 94 skipped, 10 xfailed, 7 xpassed, 0 failed.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dtk9KoddQxGPNyZkCPDKnT


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected Python binding defaults to match the corresponding C++ behavior.
    • Made optional parameters work correctly for IDMapper.annotate and SwathFile.loadMzML.
    • Fixed Python type stubs that previously failed to parse.
  • Breaking Changes

    • Updated MultipleTesting.lfdr defaults for gridsize and cut, which may change results when these arguments are omitted.

…res declare

Four bindings declared a parameter with no default after parameters that had
one. nanobind accepts that, but the resulting signature cannot be expressed in
Python, so nanobind.stubgen emitted stubs that are not valid Python:

    _pyopenms_datastructures.pyi:782: non-default argument follows default argument
    _pyopenms_misc.pyi:1000:        non-default argument follows default argument

Each of the four arguments has a default in the C++ signature that the binding
simply did not carry over, so they become optional with those values:

  - MultipleTesting.lfdr       transf           -> LfdrTransform.Probit
  - IDMapper.annotate          spectra          -> MSExperiment()   (FeatureMap overload)
  - IDMapper.annotate          spectra          -> MSExperiment()   (ConsensusMap overload)
  - SwathFile.loadMzML         plugin_consumer  -> None             (C++: nullptr)

BREAKING: while checking lfdr against MultipleTesting.h, two of its other
defaults turned out to be wrong as well. The binding declared gridsize = 100
and cut = 0.05; the C++ signature and its documentation use 512 and 3.0. Python
callers who omitted those arguments therefore got different results than C++
callers. They now match, which changes lfdr() output for such calls.

MultipleTesting's nested Pi0Method and LfdrTransform enums move ahead of the
method chain. nanobind converts default values to Python objects while the
binding is being created, so LfdrTransform::Probit has to be a registered type
by the time lfdr() is bound; registering the enums afterwards, as before, would
raise during module import.

Verified on Linux x86_64 / CPython 3.11:
- a scan of all 15 binding files reports no remaining ordering violations;
- all 18 generated .pyi files parse (previously 2 did not);
- lfdr() called with only p_values and pi0 returns exactly what the explicit
  (Probit, 1.5, 1e-8, 512, 3.0) call returns, and both enums are still reachable
  as MultipleTesting.LfdrTransform / MultipleTesting.Pi0Method;
- both IDMapper.annotate overloads work without the spectra argument;
- the pyOpenMS suite is unchanged: 5957 passed, 94 skipped, 10 xfailed,
  7 xpassed, 0 failed.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Dtk9KoddQxGPNyZkCPDKnT

Copy link
Copy Markdown
Contributor Author

CI note: build-and-test (ubuntu-24.04-arm, g++) (job) failed, but not on this change.

The run-vcpkg action could not bootstrap vcpkg — four consecutive 504s on the download, so the job died in dependency setup before CMake or the compiler ran:

Downloading vcpkg-arm64-glibc...
curl: (22) The requested URL returned error: 504
curl: (22) The requested URL returned error: 504
curl: (22) The requested URL returned error: 504
curl: (22) The requested URL returned error: 504
##[error]run-vcpkg action execution failed: Last command execution failed with error code '1'.

This PR only touches pyOpenMS binding sources and the CHANGELOG, and build-and-test does not build pyOpenMS at all, so it cannot reach this step. It also looks like a wider upstream outage: three more jobs failed the same way within a few minutes, on #10136 (Chocolatey 504 fetching ccache) and #10138 (the same vcpkg bootstrap 504 on ubuntu-24.04-arm and macos-15).

(The rrsync error: reading from write-only server is not allowed earlier in the log is not the failure — the action logs Falling back to HTTP fetch... and the fallback succeeds.)

A re-run currently returns 403 This workflow is already running because sibling jobs are still in flight. I'll re-run this job once the run completes; if it fails a second time the failure is real and I'll dig into it properly.


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b59f714e-4e97-477b-be40-21fc749dab70

📥 Commits

Reviewing files that changed from the base of the PR and between 3befd8e and b3fbdbc.

📒 Files selected for processing (3)
  • CHANGELOG
  • src/pyOpenMS/bindings/bind_datastructures.cpp
  • src/pyOpenMS/bindings/bind_misc.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

PyOpenMS bindings now match C++ defaults for MultipleTesting.lfdr, IDMapper.annotate, and SwathFile.loadMzML. Nested enums are registered before lfdr binding. The changelog documents the default changes and their effect on type stubs.

Changes

PyOpenMS default alignment

Layer / File(s) Summary
MultipleTesting defaults
src/pyOpenMS/bindings/bind_datastructures.cpp, CHANGELOG
Pi0Method and LfdrTransform are registered before statistical methods. MultipleTesting.lfdr now defaults transf to Probit, gridsize to 512, and cut to 3.0.
Optional binding arguments
src/pyOpenMS/bindings/bind_misc.cpp
Both IDMapper.annotate overloads default spectra to an empty MSExperiment. SwathFile.loadMzML defaults plugin_consumer to None.

Suggested reviewers: claude

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to b3fbd

The updated Python defaults match the C++ APIs and introduce no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: updating pyOpenMS keyword-argument defaults to match the corresponding C++ signatures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-binding-keyword-defaults

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the bindings bright,
Defaults now hop to values right.
Probit leads the lfdr way,
Empty spectra wait today.
None greets plugins at the door,
And stubs parse cleanly evermore.

Comment @coderabbitai help to get the list of available commands.

@timosachsenberg
timosachsenberg merged commit f967f32 into develop Sep 14, 2026
25 of 27 checks passed
@timosachsenberg
timosachsenberg deleted the claude/fix-binding-keyword-defaults branch September 14, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants