Open amacfie opened 1 year ago
So glad that someone else has thought of this too! I've been following annotated-types for a bit, and talking a little about a CrossHair integration.
Even without contracts, crosshair could play a role here, because essentially any annotated return type is already a contract; e.g. something like this could be checked by crosshair:
def factorize(Annotated[int, Gt(1)] product) -> list[Annotated[int, Predicate(is_prime)]]:
...
I am in the middle of some intense performance work, but esp with your nudge, I think this should be next-ish in the prioritization queue. (or if someone finding this wants to take a stab at it in the meantime, I'll help!)
The annotated-types project https://github.com/annotated-types/annotated-types provides a format for expressing constraints, like string length, integer bounds, or general predicates, by using
Annotated
in type annotations.Pydantic is using it in V2 and FastAPI has adopted
Annotated
in v0.95 (I'm not sure about annotated-types).I'm assuming annotated-types doesn't have the full power of contracts, e.g. how do you relate outputs to inputs. So it should be supported in conjunction with contract syntax.