Skip to content

omit_if_default ignores attrs' converters #695

Description

@llovanto

Hi! It seems like currently converter with omit_if_default=True does not apply attrs' converters when checking if the value is equal to the default one.

import attrs
import cattrs

c = cattrs.Converter(omit_if_default=True)


@attrs.define
class A:
    b: int = attrs.field(default="0", converter=int)


c.unstructure(A())
# {'b': 0}


@attrs.define
class A:
    b: int = attrs.field(default=0, converter=int)


c.unstructure(A())
# {}

Is this the expected behavior? If so, would you consider changing it?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions