generator_schema
Returns a schema that matches a generator value, e.g.:
```py
from typing import Iterator
from pydantic_core import SchemaValidator, core_schema
def gen() - > Iterator[int]:
yield 1
schema = core_schema.generator_schema(items_schema=core_schema.int_schema())
v = SchemaValidator(schema)
v.validate_python(gen())
```
Unlike other types, validated generators do not raise ValidationErrors eagerly,
but instead will raise a ValidationError when a violating value is actually read from the generator.
This is to ensure that "validated" generators retain the benefit of lazy evaluation.
def generator_schema(
items_schema: CoreSchema | None = None,
min_length: int | None = None,
max_length: int | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: IncExSeqOrElseSerSchema | None = None
) - > GeneratorSchema
Returns a schema that matches a generator value. Unlike other types, validated generators do not raise ValidationErrors eagerly, but instead will raise a ValidationError when a violating value is actually read from the generator. This is to ensure that "validated" generators retain the benefit of lazy evaluation.
Parameters
| Name | Type | Description |
|---|---|---|
| items_schema | `CoreSchema | None` = None |
| min_length | `int | None` = None |
| max_length | `int | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `IncExSeqOrElseSerSchema | None` = None |
Returns
| Type | Description |
|---|---|
GeneratorSchema | A core schema object representing a generator type with optional item validation and length constraints. |