Make PyO3 introspection optional when stubs are disabled #4423
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 236 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.327
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4423"
general
weight: 0.35
UebelAndre
Custom
rust_pyo3_toolchaindefinitions currently requirepyo3_introspectioneven when their extensions usestubs = False. Removing the attribute's mandatory constraint alone is insufficient:py_pyo3_libraryunconditionally depends on the stub generator, which resolves the introspection library during analysis before the implementation checks whether stubs are enabled.Make
pyo3_introspectionoptional and havepyo3_extensionsupply the stub generator dependency only when stub generation is enabled. Forstubs = None, aconfig_settingselects the dependency using the existingexperimental_stubgenflag. ExplicitTrueorFalsecontinues to override that flag. The flag's default remains unchanged.The stub generator becomes an optional executable attribute on the internal rule, with visibility allowing the macro to supply it from caller packages. If stubs are requested without an introspection library, analysis reports a clear error explaining how to supply the library or disable stubs.
This allows consumers to reuse an existing PyO3 dependency without introducing an unused introspection dependency. Toolchains that provide introspection retain their existing stub-generation behavior.
Testing
Ran
bazel test //test/...fromextensions/pyo3on Linux x86-64: all 33 tests pass.Added 12 analysis regression cases covering all combinations of:
The tests check whether a
PyO3StubGenaction is created and verify the diagnostic when enabled stubs require missing introspection. Disabled cases successfully analyze without that dependency. Existing tests also verify generated stub contents, Python imports and calls, runfiles, compilation modes, and wheel packaging.