PEP 746: TypedMetadata for type checking of PEP 593 Annotated

The entire motivation section of that pep then goes on to point exclusively at cases outside the type system and using this as a surrogate for things yet to be included in the type system, and does not suggest that type checkers would be the consumer of the annotations, and even directly states (including what has survived to the living specification) that tools may choose what annotations they consume, this seems to preclude mandating that this be part of the type system to me when viewed with proper context.

I don’t think there’s anything preventing a backport via something as simple as:

typing_extensions.Refinement[int, "< 5"]

this might not be the ideal expression of this, but considering that I imagine refinement types would be limited in what they allow for valid constraints, not allowing arbitrary constraints, it’s certainly not the worst.

Maybe that’s even just a better form in general than the specific new syntax, but I don’t really like it being “stringly-typed”

1 Like