diff --git a/polyfactory/factories/base.py b/polyfactory/factories/base.py index 89949791..a394c8cb 100644 --- a/polyfactory/factories/base.py +++ b/polyfactory/factories/base.py @@ -491,7 +491,7 @@ def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> pattern=constraints.get("pattern"), ) - try: + with suppress(ValueError): collection_type = get_collection_type(annotation) if collection_type == dict: return handle_constrained_mapping( @@ -510,10 +510,6 @@ def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> min_items=constraints.get("min_length"), unique_items=constraints.get("unique_items", False), ) - except ValueError: - # implies the annotation was not a collection type - pass - if is_safe_subclass(annotation, date): return handle_constrained_date( faker=cls.__faker__,