Add type hints to all functions, classes, and methods#139
Add type hints to all functions, classes, and methods#139
Conversation
Co-authored-by: ColmTalbot <25602909+ColmTalbot@users.noreply.github.com>
- Added type hints to all functions, methods, and classes - Used Any for array-like types (numpy/cupy/jax arrays) - Used modern Python 3.10+ syntax (dict, list, tuple instead of Dict, List, Tuple) - Used collections.abc.Callable for callable types - Added -> None return type for __init__ methods - Kept existing docstrings unchanged - All tests pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Added type hints to all functions, methods, and classes - Used Any for array-like types (numpy, cupy, jax arrays) - Used modern Python 3.10+ type hints (dict[str, Any] instead of Dict) - Used Callable from collections.abc - All existing tests pass Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Added typing.Any import for array-like types - Added type hints to all function parameters and return types - Added type hints to all class methods including __init__ (-> None) - Used modern Python 3.10+ syntax (dict[str, Any] instead of Dict[str, Any]) - Used Any for array-like types (numpy, cupy, or jax arrays) - All existing docstrings and functionality remain unchanged Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Break long parameter lists into multiple lines for better readability Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gwpopulation/utils.py
Outdated
| from scipy import special as scs | ||
|
|
||
| xp = np | ||
| xp: Any = np |
There was a problem hiding this comment.
Changed to xp: ModuleType = np in commit f157fa5.
gwpopulation/utils.py
Outdated
|
|
||
| @apply_conditions(dict(alpha=(gt, 0), beta=(gt, 0), scale=(gt, 0))) | ||
| def beta_dist(xx, alpha, beta, scale=1): | ||
| def beta_dist(xx: Any, alpha: float, beta: float, scale: float | Any = 1) -> Any: |
There was a problem hiding this comment.
xx should be something satisfying the array api. You can use the array-api-typing package
There was a problem hiding this comment.
Updated to use Array from array-api-typing package for all array-like parameters. Also added array-api-typing to requirements.txt. Changes in commit f157fa5.
- Add type hints to all functions, methods, and classes - Use 'Any' for array-like types (numpy/cupy/jax arrays) - Use modern Python 3.10+ type syntax (dict, list instead of Dict, List) - Add '-> None' return type to __init__ methods - All existing tests pass (30 tests) - Docstrings remain unchanged Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
+ Coverage 95.15% 95.24% +0.09%
==========================================
Files 14 14
Lines 907 925 +18
==========================================
+ Hits 863 881 +18
Misses 44 44
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add type hints to all functions, methods, and classes - Use Any for array-like types (numpy/cupy/jax arrays) - Use modern Python 3.10+ syntax (dict[str, Any] vs Dict[str, Any]) - Add return type -> None to __init__ methods - Import typing.Any for array types - Keep all docstrings unchanged Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add comprehensive type hints to all functions, methods, and classes - Use Any for array-like types (numpy/cupy/jax arrays) - Use modern Python 3.10+ type hints (dict, list, tuple) - Add return type hints including -> None for __init__ - All docstrings and code functionality remain unchanged - All tests pass successfully Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Added type hints to all functions, methods, and classes in cosmo_models.py, jax.py, and numpyro.py - Used modern Python 3.10+ syntax (dict, list, tuple instead of Dict, List, Tuple) - Used 'Any' for array-like types compatible with numpy/cupy/jax arrays - Added necessary imports: typing.Any and collections.abc.Callable - Added return type hints including '-> None' for __init__ methods - Preserved all existing docstrings and code logic unchanged Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eters Co-authored-by: ColmTalbot <25602909+ColmTalbot@users.noreply.github.com>
|
Closing this, it seems it was a bit ambitious for copilot with this prompt. |
Adds comprehensive type annotations throughout the package. Functions accepting array-like inputs (numpy/cupy/jax) now use
Arrayfromarray-api-typingto properly accommodate the Python Array API standard.Changes
Core modules:
backend.py- Module loading, backend switchingutils.py- Distribution functionsconversions.py- Parameter conversionshyperpe.py- Likelihood classesvt.py- Selection functionsModel modules:
models/mass.py- 13 functions, 5 classesmodels/redshift.py- Cosmological modelsmodels/spin.py- 8 functions, 3 classesmodels/interped.py- Interpolation modelsExperimental modules:
experimental/cosmo_models.py,jax.py,numpyro.pyType hint patterns
Uses Python 3.10+ syntax (
dict[str, Any],list[str],|unions) andcollections.abc.Callablefor callable types.Dependencies added:
array-api-typing- Provides proper typing for Python Array API standard-compliant arraysAll 230 tests pass. No runtime behavior changes.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.