omit_if_default ignores attrs' converters
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with cattrs.Converter configured with omit_if_default=True and its unstructure path, using the attrs.define examples and attrs.field converters as the reproducer. Determine whether default comparison should use the converted value, then add or update coverage for both default="0", converter=int and default=0; done means the output consistently omits or retains b according to the agreed behavior.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/cattrs
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-attrs/cattrs#761 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
python-attrs/cattrs#513 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
python-attrs/cattrs#779 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 85/100
python-attrs/cattrs#774 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
python-attrs/cattrs#746 · 2 comments ·
All issues in python-attrs/cattrs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100