set_schema
Returns a schema that matches a set of a given schema, e.g.:
from pydantic_core import SchemaValidator, core_schema
schema = core_schema.set_schema(
items_schema=core_schema.int_schema(), min_length=0, max_length=10
)
v = SchemaValidator(schema)
assert v.validate_python({1, '2', 3}) == {1, 2, 3}
def set_schema(
items_schema: CoreSchema | None = None,
min_length: int | None = None,
max_length: int | None = None,
fail_fast: bool | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None
) - > SetSchema
Returns a schema that matches a set of a given schema.
Parameters
| Name | Type | Description |
|---|---|---|
| items_schema | `CoreSchema | None` = None |
| min_length | `int | None` = None |
| max_length | `int | None` = None |
| fail_fast | `bool | None` = None |
| strict | `bool | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `SerSchema | None` = None |
Returns
| Type | Description |
|---|---|
SetSchema | A dictionary representing the set validation schema, containing the specified constraints and item definitions. |