Skip to content

Commit 6961eaa

Browse files
authored
fix: don't blindly suppress ValueError (#450)
1 parent 1a0da0d commit 6961eaa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

polyfactory/factories/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def create_factory(
492492
)
493493

494494
@classmethod
495-
def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> Any: # noqa: C901, PLR0911
495+
def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> Any: # noqa: C901, PLR0911, PLR0912
496496
try:
497497
constraints = cast("Constraints", field_meta.constraints)
498498
if is_safe_subclass(annotation, float):
@@ -541,16 +541,18 @@ def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) ->
541541
pattern=constraints.get("pattern"),
542542
)
543543

544-
with suppress(ValueError):
544+
try:
545545
collection_type = get_collection_type(annotation)
546+
except ValueError:
547+
collection_type = None
548+
if collection_type is not None:
546549
if collection_type == dict:
547550
return handle_constrained_mapping(
548551
factory=cls,
549552
field_meta=field_meta,
550553
min_items=constraints.get("min_length"),
551554
max_items=constraints.get("max_length"),
552555
)
553-
554556
return handle_constrained_collection(
555557
collection_type=collection_type, # type: ignore[type-var]
556558
factory=cls,

0 commit comments

Comments
 (0)