Bug: polyfactoryutils.helpers.flatten_annotation does not handle Optional properly
sam-or opened this issue · 1 comments
sam-or commented
Description
calling the flatten_annotation
function with an optional annotation int | None
/Optional[int]
does not properly flatten the annotation, instead the result is [NoneType,[int]]
(expected: [NoneType, int]
)
MCVE
# Your MCVE code here
@dataclass
class OptionalInt:
i: Optional[int]
class OptionalIntFactory(DataclassFactory[OptionalInt]):
__model__ = OptionalInt
results = list(OptionalIntFactory.coverage())
Steps to reproduce
Run the `<factory>.coverage()` function with any factory for a model that has an optional field
Logs
TypeError: unhashable type: 'list'
Release Version
2.12.0
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
- If you would like to see an issue prioritized, make a pledge towards it!
- We receive the pledge once the issue is completed & verified
- This, along with engagement in the community, helps us know which features are a priority to our users.
sam-or commented
I'll create a PR for this