Skip to content

Add type hints to all functions, classes, and methods#139

Closed
Copilot wants to merge 11 commits intomainfrom
copilot/add-python-type-hints
Closed

Add type hints to all functions, classes, and methods#139
Copilot wants to merge 11 commits intomainfrom
copilot/add-python-type-hints

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 15, 2026

Adds comprehensive type annotations throughout the package. Functions accepting array-like inputs (numpy/cupy/jax) now use Array from array-api-typing to properly accommodate the Python Array API standard.

Changes

Core modules:

  • backend.py - Module loading, backend switching
  • utils.py - Distribution functions
  • conversions.py - Parameter conversions
  • hyperpe.py - Likelihood classes
  • vt.py - Selection functions

Model modules:

  • models/mass.py - 13 functions, 5 classes
  • models/redshift.py - Cosmological models
  • models/spin.py - 8 functions, 3 classes
  • models/interped.py - Interpolation models

Experimental modules:

  • experimental/cosmo_models.py, jax.py, numpyro.py

Type hint patterns

# Array-like inputs compatible with numpy/cupy/jax using array-api-typing
from array_api_typing import Array

def beta_dist(xx: Array, alpha: float, beta: float, scale: float | Array = 1) -> Array:
    ...

# Backend-agnostic module variables with proper typing
from types import ModuleType

xp: ModuleType = np
scs: Any = scipy.special

# Dictionary parameters and returns
def __call__(self, parameters: dict[str, Any]) -> Any:
    ...

Uses Python 3.10+ syntax (dict[str, Any], list[str], | unions) and collections.abc.Callable for callable types.

Dependencies added:

  • array-api-typing - Provides proper typing for Python Array API standard-compliant arrays

All 230 tests pass. No runtime behavior changes.

Original prompt

Add python type hints to all functions/classes/methods in this package. Many functions accept as inputs anything satisfying the python array api standard.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits February 15, 2026 22:57
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>
from scipy import special as scs

xp = np
xp: Any = np
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ModuleType.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to xp: ModuleType = np in commit f157fa5.


@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:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xx should be something satisfying the array api. You can use the array-api-typing package

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.24%. Comparing base (ce9af49) to head (f157fa5).
⚠️ Report is 1 commits behind head on main.

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              
Flag Coverage Δ
python3.10 95.24% <100.00%> (+0.09%) ⬆️
python3.11 95.24% <100.00%> (+0.09%) ⬆️
python3.12 95.24% <100.00%> (+0.09%) ⬆️
python3.13 95.24% <100.00%> (+0.09%) ⬆️

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.

Copilot AI and others added 3 commits February 15, 2026 23:21
- 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>
Copilot AI changed the title [WIP] Add type hints to all functions and classes in package Add type hints to all functions, classes, and methods Feb 15, 2026
Copilot AI requested a review from ColmTalbot February 15, 2026 23:37
…eters

Co-authored-by: ColmTalbot <25602909+ColmTalbot@users.noreply.github.com>
@ColmTalbot
Copy link
Copy Markdown
Owner

Closing this, it seems it was a bit ambitious for copilot with this prompt.

@ColmTalbot ColmTalbot closed this Feb 16, 2026
@ColmTalbot ColmTalbot deleted the copilot/add-python-type-hints branch February 16, 2026 14:26
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