Skip to content

Allow specifying a default value for a field #43

Description

@NiklasRosenstein

You can already specify a default value by assigning to a dataclass field as you would expect; but there are cases where you may want to specify a different default value for deserialization (or not have a default value in code at all).

from databind.core.settings import Default

@dataclass
class MyClass:
  a: Annotated[str, Default("foo")]

This setting would ensure that a has default value foo when deserialized, but not when the dataclass is constructed in Python code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions