Skip to content

Add support for factories to Optional #28

Description

@todofixthis

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'>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions