Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HasConstantsNamespace #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cosmology/api/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING, Protocol, TypeVar, runtime_checkable

from cosmology.api._array_api import Array
from cosmology.api._namespace import HasConstantsNamespace

if TYPE_CHECKING:
from cosmology.api._constants import CosmologyConstantsNamespace
Expand All @@ -18,7 +19,7 @@


@runtime_checkable
class Cosmology(Protocol[Array, InputT]): # type: ignore[misc]
class Cosmology(HasConstantsNamespace, Protocol[Array, InputT]): # type: ignore[misc]
"""Cosmology API Protocol."""

@property
Expand Down
17 changes: 11 additions & 6 deletions src/cosmology/api/_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@


@runtime_checkable
class CosmologyNamespace(Protocol):
class HasConstantsNamespace(Protocol):
"""Protocol for objects that have a constants module."""

@property
def constants(self) -> CosmologyConstantsNamespace:
"""The constants namespace for this object."""
...


@runtime_checkable
class CosmologyNamespace(HasConstantsNamespace, Protocol):
"""Runtime-checkable Protocol for the Cosmology API namespace.

Examples
Expand Down Expand Up @@ -53,8 +63,3 @@ class CosmologyNamespace(Protocol):
be a `~cosmology.api.CosmologyConstantsNamespace`, but `isinstance` will not
check this.
"""

@property
def constants(self) -> CosmologyConstantsNamespace:
"""The cosmology constants API."""
...