def asdict(*, unset_values=None) -> dict:
if unset_values is None:
unset_values = set()
return _asdict(self, unset_values)
...
def _asdict(obj: Any, unset_values) -> Any:
if isinstance(obj, dict):
return {key: _asdict(value, unset_values=unset_values) for key, value in obj.items() if value not in unset_values}
if isinstance(obj, (list, set, tuple)):
return obj.__class__(_asdict(x, unset_values=unset_values) for x in obj if x not in unset_values)
if isinstance(obj, ItemAdapter):
return obj.asdict(unset_values=unset_values)
if ItemAdapter.is_item(obj):
return ItemAdapter(obj).asdict(unset_values=unset_values)
return
e.g.
Context: https://github.com/zytedata/zyte-common-items/pull/2#discussion_r903710963