polyfactory
polyfactory copied to clipboard
Bug: typing.NotRequired is ignored in TypedDict coverage
Description
When a field is annotated with typing.NotRequired, expectation is that TypedDictFactory.coverage would generate examples where that field is not set.
URL to code causing the issue
No response
MCVE
from typing import NotRequired, TypedDict
from polyfactory.factories import TypedDictFactory
class Example(TypedDict):
value: NotRequired[int]
print(list(TypedDictFactory.create_factory(Example).coverage()))
# Prints: [{'value': 7853}]
# Expected: [{'value': 7853}, {}]
Steps to reproduce
- Run with uv:
echo "\
from typing import NotRequired, TypedDict
from polyfactory.factories import TypedDictFactory
class Example(TypedDict):
value: NotRequired[int]
print(list(TypedDictFactory.create_factory(Example).coverage()))
" | uv run --with polyfactory --python 3.13 -
- See that it provides only one example: with
valuefield set.
Screenshots
"In the format of: "
Logs
Release Version
2.19.0
Platform
- [ ] Linux
- [x] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)