Open petergaultney opened 3 weeks ago
Hi @petergaultney!
I hadn't considered datetime
support, but since it's in the standard library it seems like a reasonable thing to support. I added it in #155; can try to get it in a release soon. I'll also try to make error messages for types that we don't support less cryptic.
In the meantime here's an immediate workaround:
from datetime import datetime
from typing import Annotated
import tyro
def main(
dt: Annotated[
datetime,
# lambda function is a hack because `datetime.fromisoformat` signature can't be inspected at runtime...
tyro.conf.arg(constructor=lambda string: datetime.fromisoformat(string)),
],
) -> None:
print(dt)
tyro.cli(main)
This should be supported in tyro>=0.8.9
!
I apologize if I'm missing something; I used the documentation search feature and did not find anything.
I tried just naively hooking things up and passing both an ISO8601 datetime string and a unix timestamp in, but both result in an error about string not being compatible with integer. I don't have the error handy but I can go recreate it if that would be useful.