Skip to content

Commit

Permalink
Refine type hint for ReparamMessenger
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzo committed Feb 27, 2024
1 parent e0e3a82 commit 401e55b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions pyro/poutine/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from pyro.poutine.lift_messenger import LiftMessenger
from pyro.poutine.markov_messenger import MarkovMessenger
from pyro.poutine.mask_messenger import MaskMessenger
from pyro.poutine.reparam_messenger import ReparamMessenger
from pyro.poutine.reparam_messenger import ReparamHandler, ReparamMessenger
from pyro.poutine.replay_messenger import ReplayMessenger
from pyro.poutine.runtime import NonlocalExit
from pyro.poutine.scale_messenger import ScaleMessenger
Expand Down Expand Up @@ -152,7 +152,7 @@ def block(

@overload
def block(
fn: Callable[_P, _T] = ...,
fn: Callable[_P, _T],
hide_fn: Optional[Callable[["Message"], Optional[bool]]] = None,
expose_fn: Optional[Callable[["Message"], Optional[bool]]] = None,
hide_all: bool = True,
Expand Down Expand Up @@ -186,7 +186,7 @@ def broadcast(

@overload
def broadcast(
fn: Callable[_P, _T] = ...,
fn: Callable[_P, _T],
) -> Callable[_P, _T]: ...


Expand All @@ -206,7 +206,7 @@ def collapse(

@overload
def collapse(
fn: Callable[_P, _T] = ...,
fn: Callable[_P, _T],
*args: Any,
**kwargs: Any,
) -> Callable[_P, _T]: ...
Expand Down Expand Up @@ -269,7 +269,7 @@ def enum(

@overload
def enum(
fn: Callable[_P, _T] = ...,
fn: Callable[_P, _T],
first_available_dim: Optional[int] = None,
) -> Callable[_P, _T]: ...

Expand Down Expand Up @@ -371,14 +371,14 @@ def reparam(
def reparam(
fn: Callable[_P, _T],
config: Union[Dict[str, "Reparam"], Callable[["Message"], Optional["Reparam"]]],
) -> Callable[_P, _T]: ...
) -> ReparamHandler[_P, _T]: ...


@_make_handler(ReparamMessenger)
def reparam( # type: ignore[empty-body]
fn: Callable[_P, _T],
config: Union[Dict[str, "Reparam"], Callable[["Message"], Optional["Reparam"]]],
) -> Union[ReparamMessenger, Callable[_P, _T]]: ...
) -> Union[ReparamMessenger, ReparamHandler[_P, _T]]: ...


@overload
Expand All @@ -391,7 +391,7 @@ def replay(

@overload
def replay(
fn: Callable[_P, _T] = ...,
fn: Callable[_P, _T],
trace: Optional["Trace"] = None,
params: Optional[Dict[str, "torch.Tensor"]] = None,
) -> Callable[_P, _T]: ...
Expand Down Expand Up @@ -467,7 +467,7 @@ def substitute( # type: ignore[empty-body]

@overload
def trace(
fn: None = None,
fn: None = ...,
graph_type: Optional[Literal["flat", "dense"]] = None,
param_only: Optional[bool] = None,
) -> TraceMessenger: ...
Expand Down
2 changes: 1 addition & 1 deletion pyro/poutine/reparam_messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
self.config = config
self._args_kwargs = None

def __call__(self, fn: Callable[_P, _T]) -> Callable[_P, _T]:
def __call__(self, fn: Callable[_P, _T]) -> "ReparamHandler[_P, _T]":
return ReparamHandler(self, fn)

def _pyro_sample(self, msg: "Message") -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyro/poutine/trace_messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __exit__(self, *args, **kwargs) -> None:
identify_dense_edges(self.trace)
return super().__exit__(*args, **kwargs)

def __call__(self, fn: Callable[_P, _T]) -> Callable[_P, _T]:
def __call__(self, fn: Callable[_P, _T]) -> "TraceHandler[_P, _T]":
"""
TODO docs
"""
Expand Down

0 comments on commit 401e55b

Please sign in to comment.