Skip to content

Use docrep to deduplicate shared parameter docstrings#55

Draft
endolith wants to merge 2 commits into
masterfrom
cursor/docrep-docstrings-a67f
Draft

Use docrep to deduplicate shared parameter docstrings#55
endolith wants to merge 2 commits into
masterfrom
cursor/docrep-docstrings-a67f

Conversation

@endolith
Copy link
Copy Markdown
Owner

@endolith endolith commented May 11, 2026

Summary

Issue #6 suggested using docrep so repeated NumPy-style parameter descriptions are maintained in one place.

This change adds a small docrep dependency and a shared DocstringProcessor in elsim/_docstrings.py, then replaces the duplicated blocks for:

  • utilities — the same array_like / 2D utilities wording is reused in strategies (honest_rankings, honest_normed_scores, approval_optimal, vote_for_k) and utility_winner.
  • n_voters / n_cands / random_state — shared across random_utilities, impartial_culture, and normal_electorate (the latter uses keep_params slices so dims / corr / disp stay in the middle).

Runtime behavior is unchanged; only __doc__ is assembled at import time. All tests and doctests pass (218 passed).

tests/test_docstrings.py invokes the doc-anchor stub functions so every line of the new anchor code is covered under Codecov, and checks that docrep expanded __doc__ strings include the expected parameter names.

Tradeoffs

  • Pros: Single source of truth for repeated parameter prose; matches the approach discussed in Use docrep to simplify docstrings? #6; library is lightweight (depends on six only) and supports Python ≥3.6 per project metadata.
  • Cons: One more install dependency; docstrings are no longer fully literal in source (placeholders like %(election_common.parameters)s); contributors need to know the docrep pattern for new reuse.
Open in Web Open in Cursor 

Use docrep (per discussion in issue #6) so repeated Parameters text for
utilities and for election generator size/RNG options lives in one place.
Introduce elsim._docstrings with a shared DocstringProcessor and anchor
stubs; elections reuses n_voters/n_cands/random_state via substitutions
and keep_params slices for normal_electorate.

Co-authored-by: endolith <endolith@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.49%. Comparing base (8a7213f) to head (1264cce).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #55      +/-   ##
==========================================
+ Coverage   96.31%   96.49%   +0.17%     
==========================================
  Files          19       20       +1     
  Lines         489      513      +24     
==========================================
+ Hits          471      495      +24     
  Misses         18       18              
Flag Coverage Δ
no-numba 95.71% <100.00%> (+0.21%) ⬆️
numba 89.66% <100.00%> (+0.50%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Codecov flagged the pass lines in _utilities_2d_param_doc and
_election_common_param_doc as never executed; call them from tests and
assert expanded docstrings contain expected parameter names.

Co-authored-by: endolith <endolith@gmail.com>
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.

2 participants