I have a struct field that is a collection of str (e.g., Sequence[str]) and I want to restrict each element of the collection to a pattern, but pattern is supported only for str fields, not collection types.
As a simple example, I might want my field to be annotated like so:
TypeError: Can only set `pattern` on a str type - type `typing.Annotated[typing.Sequence[str], msgspec.Meta(pattern='[A-Z0-9]{1,50}', min_length=1, max_length=50)]` is invalid
Description
I have a struct field that is a collection of str (e.g.,
Sequence[str]
) and I want to restrict each element of the collection to apattern
, butpattern
is supported only forstr
fields, not collection types.As a simple example, I might want my field to be annotated like so:
This corresponds to JSON Schema property type like this:
But msgspec produces an error like so: