Generate schema for a Sequence, e.g. `Sequence[int]`.
(self, items_type: Any)
| 1764 | return core_schema.is_subclass_schema(type_param) |
| 1765 | |
| 1766 | def _sequence_schema(self, items_type: Any) -> core_schema.CoreSchema: |
| 1767 | """Generate schema for a Sequence, e.g. `Sequence[int]`.""" |
| 1768 | from ._serializers import serialize_sequence_via_list |
| 1769 | |
| 1770 | item_type_schema = self.generate_schema(items_type) |
| 1771 | list_schema = core_schema.list_schema(item_type_schema) |
| 1772 | |
| 1773 | json_schema = smart_deepcopy(list_schema) |
| 1774 | python_schema = core_schema.is_instance_schema(typing.Sequence, cls_repr='Sequence') |
| 1775 | if not typing_objects.is_any(items_type): |
| 1776 | from ._validators import sequence_validator |
| 1777 | |
| 1778 | python_schema = core_schema.chain_schema( |
| 1779 | [python_schema, core_schema.no_info_wrap_validator_function(sequence_validator, list_schema)], |
| 1780 | ) |
| 1781 | |
| 1782 | serialization = core_schema.wrap_serializer_function_ser_schema( |
| 1783 | serialize_sequence_via_list, schema=item_type_schema, info_arg=True |
| 1784 | ) |
| 1785 | return core_schema.json_or_python_schema( |
| 1786 | json_schema=json_schema, python_schema=python_schema, serialization=serialization |
| 1787 | ) |
| 1788 | |
| 1789 | def _iterable_schema(self, type_: Any) -> core_schema.GeneratorSchema: |
| 1790 | """Generate a schema for an `Iterable`.""" |
no test coverage detected