Skip to content

Commit

Permalink
make type hint private
Browse files Browse the repository at this point in the history
  • Loading branch information
nstarman committed Jun 19, 2024
1 parent 959e932 commit 231786b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions astropy/cosmology/parameter/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


_VT = TypeVar("_VT") # the type of the VParameter value
FValidateCallableT: TypeAlias = Callable[["Cosmology", "Parameter", Any], _VT]
_FValidateCallable: TypeAlias = Callable[["Cosmology", "Parameter", Any], _VT]


class Sentinel(Enum):
Expand Down Expand Up @@ -56,11 +56,11 @@ def __set__(self, obj: Parameter, value: Any) -> None:

@dataclass(frozen=True)
class _FValidateField(Generic[_VT]):
default: FValidateCallableT[_VT] | str = "default"
default: _FValidateCallable[_VT] | str = "default"

def __get__(
self, obj: Parameter | None, objcls: type[Parameter] | None
) -> FValidateCallableT[_VT] | str:
) -> _FValidateCallable[_VT] | str:
if obj is None: # calling `Parameter.fvalidate` from the class
return self.default
return obj._fvalidate # calling `Parameter.fvalidate` from an instance
Expand Down Expand Up @@ -153,8 +153,8 @@ class Parameter(Generic[_VT]):
"""

def __post_init__(self) -> None:
self._fvalidate_in: FValidateCallableT[_VT] | str
self._fvalidate: FValidateCallableT[_VT]
self._fvalidate_in: _FValidateCallable[_VT] | str
self._fvalidate: _FValidateCallable[_VT]
object.__setattr__(self, "__doc__", self.doc)
# Now setting a dummy attribute name. The cosmology class will call
# `__set_name__`, passing the real attribute name. However, if Parameter is not
Expand Down Expand Up @@ -225,7 +225,7 @@ def __set__(self, cosmology: Cosmology, value: Any) -> None:
# -------------------------------------------
# validate value

def validator(self, fvalidate: FValidateCallableT[_VT]) -> Self:
def validator(self, fvalidate: _FValidateCallable[_VT]) -> Self:
"""Make new Parameter with custom ``fvalidate``.
Note: ``Parameter.fvalidator`` must be the top-most descriptor decorator.
Expand Down Expand Up @@ -261,21 +261,21 @@ def validate(self, cosmology: Cosmology, value: Any) -> _VT:
@overload
@staticmethod
def register_validator(
key: str, fvalidate: FValidateCallableT[_VT]
) -> FValidateCallableT[_VT]: ...
key: str, fvalidate: _FValidateCallable[_VT]
) -> _FValidateCallable[_VT]: ...

@overload
@staticmethod
def register_validator(
key: str, fvalidate: None = None
) -> Callable[[FValidateCallableT[_VT]], FValidateCallableT[_VT]]: ...
) -> Callable[[_FValidateCallable[_VT]], _FValidateCallable[_VT]]: ...

@staticmethod
def register_validator(
key: str, fvalidate: FValidateCallableT[_VT] | None = None
key: str, fvalidate: _FValidateCallable[_VT] | None = None
) -> (
FValidateCallableT[_VT]
| Callable[[FValidateCallableT[_VT]], FValidateCallableT[_VT]]
_FValidateCallable[_VT]
| Callable[[_FValidateCallable[_VT]], _FValidateCallable[_VT]]
):
"""Decorator to register a new kind of validator function.
Expand Down

0 comments on commit 231786b

Please sign in to comment.