Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support annotated-types #201

Open
amacfie opened this issue Mar 24, 2023 · 1 comment
Open

Support annotated-types #201

amacfie opened this issue Mar 24, 2023 · 1 comment

Comments

@amacfie
Copy link
Contributor

amacfie commented Mar 24, 2023

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.

@pschanely
Copy link
Owner

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!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants