Make builtin potential list alphabetical (and simplify public API export??)#757
Make builtin potential list alphabetical (and simplify public API export??)#757adrn wants to merge 2 commits intoGalacticDynamics:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #757 +/- ##
=======================================
Coverage 95.84% 95.84%
=======================================
Files 158 158
Lines 5963 5965 +2
=======================================
+ Hits 5715 5717 +2
Misses 248 248 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR alphabetizes the builtin potential list and simplifies the public API export mechanism by dynamically adding builtin potentials to __all__ instead of manually maintaining duplicate lists.
- Sorts the
__all__list inbuiltin/__init__.pyalphabetically for better maintainability - Replaces explicit import and
__all__entries with a dynamic approach usingfrom ._src.builtin import * - Automatically extends the main
__all__list with builtin potentials to reduce duplication
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/galax/potential/_src/builtin/init.py | Alphabetizes the __all__ list of builtin potential names |
| src/galax/potential/init.py | Removes manual builtin imports/exports and dynamically adds them via wildcard import |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| gNFWPotential, | ||
| ) | ||
| from ._src.builtin import * | ||
| from ._src.builtin import __all__ as _builtin_all |
There was a problem hiding this comment.
Using wildcard imports (from module import *) is generally discouraged as it makes it unclear what names are being imported and can lead to namespace pollution. Consider using explicit imports or importing the module and accessing attributes through it.
| from ._src.builtin import __all__ as _builtin_all | |
| from ._src.builtin import __all__ as _builtin_all | |
| for _name in _builtin_all: | |
| globals()[_name] = getattr(__import__(f"{__name__}._src.builtin", fromlist=[_name]), _name) |
| # isort: split | ||
| from ._src import register_funcs | ||
|
|
||
| __all__ = __all__ + list(_builtin_all) |
There was a problem hiding this comment.
[nitpick] The expression __all__ = __all__ + list(_builtin_all) modifies __all__ after it's been defined, making the final exported API less obvious. Consider using __all__.extend(_builtin_all) for clearer intent, or define __all__ completely in one place.
| __all__ = __all__ + list(_builtin_all) | |
| __all__.extend(_builtin_all) |
|
I like the idea of simplifying the |
This first sorts the list of potential names alphabetically in the builtin
__init__.py. I then also was puzzling at why we need another manual list of potential names ingalax/potential/__init__.pyfor the public API -- it's annoying to have to maintain the list of names in so many places! Can we just dynamically add to__all__like this, since anything exported at thebuiltin/__init__.pylevel should probably be public API anyway?