Replies: 1 comment 6 replies
-
I'm a big fan of this -- and I really like your API. Its a lot cleaner than anything I've thought of. Only potential problem I can see is that its a very open way to write things. E.G. it now enables infinite decorators, which could be fully customizable. That said, this is actually entirely doable by delegating to One more idea (not sure its better, just throwing it out there...): class FilmDetails(TypedDict):
title: str
year: int
film = typedtag(FilmDetails)
# example 1 - correct
@tag(class_=film, title='Casablanca', year=1942)
def movie():
...
# example 2 - mypy/pylance complain (typos)
@tag(class_=film, titel='Casablanca', yeer=1942)
def movie():
...
# example 3 - fails mypy/pylance, but pydantic would coerce year to int anyway
@tag(class_=film, title='Casablanca', year="1942")
def movie():
... But yeah, I think yours is nicer. Maybe the convention is that everyone uses A few more points:
Thanks for the suggestion! Definitely excited about this one. |
Beta Was this translation helpful? Give feedback.
-
To ensure decorated tag key/values conform to a specified schema, it would be great if Hamilton supported typing and validation of metadata. Perhaps a tag decorator generator that takes a TypedDict as input and returns a decorator class that supports static typing of tag inputs and also validates tag arguments using something like pydantic.
Related, tag merging would help teams annotate features using their own type-checked namespaces. For example,
Beta Was this translation helpful? Give feedback.
All reactions