Description
Observe the below example. The comments explain the issue.
Example:
from dataclasses import dataclass
from typing import Annotated
from annotated_types import Gt, Lt
from polyfactory.factories import DataclassFactory
@dataclass
class MyClass:
values: Annotated[int, Gt(0), Lt(5)] | None # <------- the int type should be >0, <5
class Factory(DataclassFactory[MyClass]): ...
from_coverage = list(Factory.coverage())
print(from_coverage)
# >>> [MyClass(values=2863), MyClass(values=None)] # above constraints are not respected.
from_batch = Factory.batch(2)
print(from_batch)
# >>> [MyClass(values=None), MyClass(values=2)] # above constraints are respected.
My guess is the issue lies here (no solution yet):
|
if is_union(field_meta.annotation): |
Release Version
3.3.0
Platform
Description
Observe the below example. The comments explain the issue.
Example:
My guess is the issue lies here (no solution yet):
polyfactory/polyfactory/factories/base.py
Line 895 in c79cebe
Release Version
3.3.0
Platform