diff --git a/astropy/cosmology/realizations.py b/astropy/cosmology/realizations.py index e7fb75faf65..5e30f6f2ca8 100644 --- a/astropy/cosmology/realizations.py +++ b/astropy/cosmology/realizations.py @@ -22,6 +22,7 @@ import pathlib import sys +from typing import TYPE_CHECKING from astropy.utils.data import get_pkg_data_path from astropy.utils.state import ScienceState @@ -29,6 +30,9 @@ 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( @@ -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 @@ -71,7 +75,7 @@ def __getattr__(name): return cosmo -def __dir__(): +def __dir__() -> list[str]: """Directory, including lazily-imported objects.""" return __all__ @@ -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: