Skip to content

Commit

Permalink
Rename gen.make_dict_unstructure_fn.omit_if_default
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Dec 19, 2021
1 parent bb4383c commit 6260c58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History
* Add PEP 563 (string annotations) for dataclasses.
(`#195 <https://github.com/python-attrs/cattrs/issues/195>`_)
* Fix handling of dictionaries with string Enum keys for bson, orjson, and tomlkit.
* Rename the ``cattr.gen.make_dict_unstructure_fn.omit_if_default`` parameter to ``_cattrs_omit_if_default``, for consistency. The ``omit_if_default`` parameters to ``GenConverter`` and ``override`` are unchanged.

1.9.0 (2021-12-06)
------------------
Expand Down
5 changes: 4 additions & 1 deletion src/cattr/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,10 @@ def gen_unstructure_attrs_fromdict(self, cl: Type[T]) -> Dict[str, Any]:
}

h = make_dict_unstructure_fn(
cl, self, omit_if_default=self.omit_if_default, **attrib_overrides
cl,
self,
_cattrs_omit_if_default=self.omit_if_default,
**attrib_overrides,
)
return h

Expand Down
7 changes: 5 additions & 2 deletions src/cattr/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def override(omit_if_default=None, rename=None, omit: bool = False):
def make_dict_unstructure_fn(
cl,
converter,
omit_if_default: bool = False,
_cattrs_omit_if_default: bool = False,
_cattrs_use_linecache: bool = True,
**kwargs,
):
Expand Down Expand Up @@ -139,7 +139,10 @@ def make_dict_unstructure_fn(
invoke = f"instance.{attr_name}"

if d is not attr.NOTHING and (
(omit_if_default and override.omit_if_default is not False)
(
_cattrs_omit_if_default
and override.omit_if_default is not False
)
or override.omit_if_default
):
def_name = f"__cattr_def_{attr_name}"
Expand Down
5 changes: 3 additions & 2 deletions tests/test_gen_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_nodefs_generated_unstructuring_cl(cl_and_vals):
assume(False)

converter.register_unstructure_hook(
cl, make_dict_unstructure_fn(cl, converter, omit_if_default=True)
cl,
make_dict_unstructure_fn(cl, converter, _cattrs_omit_if_default=True),
)

inst = cl(*vals)
Expand Down Expand Up @@ -129,7 +130,7 @@ def test_individual_overrides(cl_and_vals):
make_dict_unstructure_fn(
cl,
converter,
omit_if_default=True,
_cattrs_omit_if_default=True,
**{attr.name: override(omit_if_default=False)}
),
)
Expand Down

0 comments on commit 6260c58

Please sign in to comment.