Skip to content

Fix package structure and public imports (closes #9)#47

Merged
endolith merged 2 commits into
masterfrom
cursor/issue-9-package-imports-303b
May 15, 2026
Merged

Fix package structure and public imports (closes #9)#47
endolith merged 2 commits into
masterfrom
cursor/issue-9-package-imports-303b

Conversation

@endolith
Copy link
Copy Markdown
Owner

Summary

Resolves issue #9 by tightening the public API of elsim, elsim.elections, and elsim.strategies, switching subpackage __init__ modules to absolute imports (PEP 8), and documenting subpackages without :imported-members: so Sphinx does not pull in unrelated third-party symbols.

Changes

  • Root elsim: from elsim import elections, methods, strategies and an explicit __all__ listing elections, methods, strategies, and __version__.
  • elsim.methods: absolute imports from elsim.methods.<module>, plus __all__ so dir(elsim.methods) matches the intended voting-method entry points.
  • elsim.elections / elsim.strategies: stop using import *; re-export only the public callables from private implementation modules elsim.elections._core and elsim.strategies._core (files renamed from elections.py / strategies.py so the loaded submodule no longer appears as a same-named public attribute on the package).
  • Implementation modules: use _np, _numbers, and existing _cdist / _honest_rankings aliases so NumPy, SciPy, and stdlib imports are not public surface area on elsim.elections._core or elsim.strategies._core.

Note on elections_rng

It remains on elsim.elections._core for internal use but is no longer re-exported from elsim.elections; callers should pass random_state where supported. No in-repo usages referenced the package-level name.

Verification

  • pytest tests/ (191 passed)
  • pytest elsim/elections/_core.py elsim/strategies/_core.py --doctest-modules (7 passed)
Open in Web Open in Cursor 

@what-the-diff
Copy link
Copy Markdown

what-the-diff Bot commented May 11, 2026

PR Summary

  • Refinement of Documentation
    Removed a certain command (:imported-members: directive) from the instruction manual related to three modules namely elsim.elections, elsim.methods, and elsim.strategies. This removal leads to cleaner and less confusing documentation.

  • Enhancement in Import Statements
    The initiation file (__init__.py) in the elsim folder now uses definitive (absolute) import statements. This enables more precise identification and usage of required modules, thereby increasing the overall reliability of the codebase.

  • Explicit Definition of Public Symbols
    Added __all__ statements in multiple modules, specifically elections, methods, strategies. This helps in clearly indicating what symbols are available for use when these modules are imported, making it easier for developers.

  • File Renaming & Import Updates
    Renamed a file (elsim/elections/elections.py) to elsim/elections/_core.py and updated all related import statements. This redesignation more accurately represents the file contents and could help with project organization and understanding.

  • Consistent Use of Numpy
    Promoted overall consistency in the use of the numpy library by incorporating an alias across all modules. An alias streamlines the coding process and makes the code easier to read.

  • Code Refactoring in _core.py Files
    Refined various functions in _core.py files aiming for consistency and clarity. This includes consistent use of the numpy functions with the newly introduced alias.

  • Modification of Public Symbol Declarations
    Adjusted the __all__ statements in both the methods and strategies modules to include all voting methods and strategies. This results in a more complete and comprehensive selection of available items when importing these modules.

@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.37%. Comparing base (4e6d55e) to head (7822157).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
+ Coverage   96.35%   96.37%   +0.01%     
==========================================
  Files          19       17       -2     
  Lines         494      496       +2     
==========================================
+ Hits          476      478       +2     
  Misses         18       18              
Flag Coverage Δ
no-numba 95.76% <100.00%> (+0.01%) ⬆️
numba 88.10% <100.00%> (+0.04%) ⬆️

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.

- Use absolute imports in package __init__ files per PEP 8.
- Replace star imports with explicit re-exports and __all__ on elsim,
  elections, strategies, and methods.
- Rename elections/elections.py and strategies/strategies.py to _core.py
  so the implementation submodule is private and does not shadow the
  package name in dir().
- Use private NumPy/SciPy/numbers aliases in election and strategy core
  modules so implementation imports are not part of the public namespace.
- Drop :imported-members: from Sphinx automodule configs now that the
  package modules no longer re-export third-party objects.

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

This renames elections.py, which I'm not a fan of.

@endolith endolith force-pushed the cursor/issue-9-package-imports-303b branch from b170d14 to bf6353e Compare May 15, 2026 03:58
@endolith endolith marked this pull request as ready for review May 15, 2026 04:00
@endolith endolith force-pushed the cursor/issue-9-package-imports-303b branch from bf6353e to 7822157 Compare May 15, 2026 04:11
@endolith endolith merged commit 5462e65 into master May 15, 2026
19 checks passed
@endolith endolith deleted the cursor/issue-9-package-imports-303b branch May 15, 2026 04:12
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.

Fix package structure, absolute imports

2 participants