Skip to content

Type-hint domain and parameterization information for parameters #674

@williambdean

Description

@williambdean

I made a distribution explorer tool which is based on Annotated type hints which I think would be cool to bring to PyMC eco.

It doesn't have to be done the same way, but Annotated type hints were pretty easy to work and encode arbitrary metadata

from typing import Annotated

Real = Annotated[float, "Real"]
PositiveReal = Annotated[float, "PositiveReal"]


def foo(mu: Real, sigma: PositiveReal): 
    ...

mu_type = foo.__annotations__["mu"] # typing.Annotated[float, 'Real']
mu_type.__metadata__ # ('Real',)

In my solution, I didn't tackle different parameterization but I suspect it could be done with a similar approach.

def foo(mu: Real, sigma: Annotated[PositiveReal, 1], tau: Annotated[PositiveReal, 2]):
  ...

foo.__annotations__
"
{'mu': typing.Annotated[float, 'Real'],
 'sigma': typing.Annotated[float, 'PositiveReal', 1],
 'tau': typing.Annotated[float, 'PositiveReal', 2]}
"

Would love to hear thoughts on this idea!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions