-
-
Notifications
You must be signed in to change notification settings - Fork 96
feat: NeverNone to always generate an optional field, and AlwaysNone #677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a86e363
to
4d86cc1
Compare
@adhtruong fixed up tests for this! Take a look when you can. |
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/677 |
"""A factory field that marks as always generated, even if it's an optional.""" | ||
|
||
|
||
class AlwaysNone: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? Does
from dataclasses import dataclass
from polyfactory.factories.dataclass_factory import DataclassFactory
@dataclass
class A:
a: int | None
class Factory(DataclassFactory[A]):
a = None
print(Factory.batch(size=10))
work for this use case? Could this be documented
# within get_field_value. | ||
excluded_field_value = has_field_value and isinstance(field_value, (NeverNone, AlwaysNone)) | ||
|
||
# TODO why do we need the BaseFactory check here, only dunder methods which are ignored would trigger this? # noqa: FIX002 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# TODO why do we need the BaseFactory check here, only dunder methods which are ignored would trigger this? # noqa: FIX002 | |
# Avoid considering fields on base field in case of clash |
or if fine to remove check then can do that
@@ -334,6 +334,7 @@ def _handle_factory_field( # noqa: PLR0911 | |||
if isinstance(field_value, Fixture): | |||
return field_value.to_value() | |||
|
|||
# if a raw lambda is passed, invoke it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this applies to all callables rather than just lambdas. Can this be updated?
Just a friendly reminder about this pull request! Please let me know if there's anything else needed here. |
This would also be useful to me! |
Description
Right now, there is not an ergonomic way to mark a single field as "required" in the sense
that polyfactory should always generate a value for it, even if it's marked as optional.
Curious what you think about the approach, I still need to:
Closes
#655