[python-package] [ci] remove runtime docstring building, test with different PYTHONOPTIMIZE levels #7403

Open
jameslamb opened 9:51am on August 20, 2026 wants to merge 631 Ξ” into microsoft/lightgbm main from
python/no-runtime-doc-parsing

Pull Request Overview

  • Opened on August 19, 2026
  • Status Open
  • Commit count 16 with first commit July 26, 2026

Total Delta

631 Total Diff Delta

Open Days

Open 33 weekdays

Test Delta

276 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
31.5 days Authoring 3 commits before pull request opened for review
 
0.1 days Awaiting first review
 
18.5 days Revising work with 13 commits in response to 0 reviews that left 6 comments

Total time for pull request still awaiting merge (longer than repo's target): 50.1 business days

Author avatar

[python-package] [ci] remove runtime docstring building, test with different PYTHONOPTIMIZE levels

Fixes #7362
Contributes to #7327

The Python package has 7 scikit-learn compatible estimators, and there is a lot of overlap in their docstrings. To keep them consistent, the estimators reference build up their docstrings at import time from templates and inherited docstrings, like this:

https://github.com/lightgbm-org/LightGBM/blob/3cd99268f09615b2e2da6e93269a7e6db199b342/python-package/lightgbm/sklearn.py#L1555-L1561

This proposes removing that stuff in favor of just using literal docstrings.

Changes in this PR


  • removes all the import-time docstring-templating stuff, in favor of literal docstrings

  • adds unit tests to ensure the docstrings remain consistent with each other

  • adds tests in CI that import lightgbm works when run under PYTHONOPTIMIZE=1 and PYTHONOPTIMIZE=2

Benefits of this change


  • allows lightgbm to be imported when using PYTHONOPTIMIZE=2 (fixes #7362)

  • very slightly reduces import time (in my local testing, by around 10ms)

  • makes it easier to reason about the docs and edit them

How I tested this

Comments Threads Pending Resolution

Resolved Comment Threads