Skip to content

Commit

Permalink
Add type annotations for cosmology realizations (astropy#15879)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Jan 13, 2024
1 parent 35652f1 commit 295ea9a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions astropy/cosmology/realizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@

import pathlib
import sys
from typing import TYPE_CHECKING

from astropy.utils.data import get_pkg_data_path
from astropy.utils.state import ScienceState

from . import _io # Ensure IO methods are registered, to read realizations # noqa: F401
from .core import Cosmology

if TYPE_CHECKING:
from typing import ClassVar

__doctest_requires__ = {"*": ["scipy"]}

_COSMOLOGY_DATA_DIR = pathlib.Path(
Expand All @@ -46,7 +50,7 @@
)


def __getattr__(name):
def __getattr__(name: str) -> Cosmology:
"""Make specific realizations from data files with lazy import from ``PEP 562``.
Raises
Expand All @@ -71,7 +75,7 @@ def __getattr__(name):
return cosmo


def __dir__():
def __dir__() -> list[str]:
"""Directory, including lazily-imported objects."""
return __all__

Expand Down Expand Up @@ -104,8 +108,8 @@ class default_cosmology(ScienceState):
Om0=0.30966, ...
"""

_default_value = "Planck18"
_value = "Planck18"
_default_value: ClassVar[str] = "Planck18"
_value: ClassVar[str | Cosmology] = "Planck18"

@classmethod
def validate(cls, value: Cosmology | str | None) -> Cosmology | None:
Expand Down

0 comments on commit 295ea9a

Please sign in to comment.