Skip to content
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

Add support for factories to Optional #28

Open
todofixthis opened this issue Jun 27, 2017 · 0 comments
Open

Add support for factories to Optional #28

todofixthis opened this issue Jun 27, 2017 · 0 comments

Comments

@todofixthis
Copy link
Contributor

todofixthis commented Jun 27, 2017

Make a few changes to the Optional filter:

  • If self.default is callable, return self.default().
  • Add an optional parameter to the initializer called is_factory that can override this behavior.

Examples:

>>> f.Optional(default=0).apply(None)
0

>>> f.Optional(default=dict).apply(None)
{}

>>> f.Optional(default=dict, is_factory=False).apply(None)
<class 'dict'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant