Skip to content

Commit

Permalink
update SequenceValidator strict default
Browse files Browse the repository at this point in the history
  • Loading branch information
andresliszt committed Mar 21, 2024
1 parent 145720e commit b9dfaf2
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pydantic/_internal/_std_types_schema.py
Expand Up @@ -274,7 +274,7 @@ class SequenceValidator:
item_source_type: type[Any]
min_length: int | None = None
max_length: int | None = None
strict: bool = False
strict: bool | None = None

def serialize_sequence_via_list(
self, v: Any, handler: core_schema.SerializerFunctionWrapHandler, info: core_schema.SerializationInfo
Expand All @@ -298,7 +298,6 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH
items_schema = None
else:
items_schema = handler.generate_schema(self.item_source_type)

metadata = {'min_length': self.min_length, 'max_length': self.max_length, 'strict': self.strict}

if self.mapped_origin in (list, set, frozenset):
Expand All @@ -325,8 +324,7 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: GetCoreSchemaH
)
else:
coerce_instance_wrap = partial(core_schema.no_info_after_validator_function, self.mapped_origin)
# Due that we are using list schema in deque/Counter, strict should be overwritten if it's given
metadata['strict'] = False

constrained_schema = core_schema.list_schema(items_schema, **metadata)

check_instance = core_schema.json_or_python_schema(
Expand Down Expand Up @@ -397,7 +395,7 @@ def sequence_like_prepare_pydantic_annotations(
return (
source_type,
[
SequenceValidator(mapped_origin, item_source_type, **metadata, strict=_config.get('strict', False)),
SequenceValidator(mapped_origin, item_source_type, **metadata),
*remaining_annotations,
],
)
Expand Down

0 comments on commit b9dfaf2

Please sign in to comment.