pyglove
pyglove copied to clipboard
Use `pg.typing` as type annotations
PyGlove provides a runtime typing feature through pg.typing
, for example, a symbolic class can be created via:
from dataclasses import dataclass
import pyglove as pg
@pg.symbolize([
('x', pg.typing.Int(min_value=1, max_value=2)),
('y', pg.typing.Callable([pg.typing.Int(max_value=0)], returns=pg.typing.Bool))
])
@dataclass
def Foo:
x: int
y: Callable[[int], bool]
There is a redundancy in this definition. Ideally, users should be able to do:
@pg.symbolize
@dataclass
def Foo:
x: pg.typing.Int(min_value=1, max_value=2)
y: pg.typing.Callable([pg.typing.Int(max_value=0)], returns=pg.typing.Bool())
And this code should work for both static type check (PyType) and runtime type check.
Additionally, we hope x: int
can be recognized by PyGlove as a shortcut to x: pg.typing.Int()
.