Added backwards compatible feature that excludes entries with None

This commit is contained in:
florian committed 2026-11-10 15:56:14 +01:00
1 parent 6e2442b41e
commit 1e36de5a9a
2 files changed
+4 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "lib-shared-models" name = "lib-shared-models"
version = "0.1.0" version = "0.1.1"
description = "Shared model(s) to validate against" description = "Shared model(s) to validate against"
requires-python = ">=3.9" requires-python = ">=3.9"
dependencies = [] dependencies = []
+3 -1
View File
@@ -112,7 +112,9 @@ class Message:
raise MessageValidationError(issues) raise MessageValidationError(issues)
return cls(title, body, link, category, timestamp) return cls(title, body, link, category, timestamp)
def to_dict(self) -> dict[str, Any]: def to_dict(self, *, exclude_none: bool = False) -> dict[str, Any]:
d = asdict(self) d = asdict(self)
d["category"] = self.category.value d["category"] = self.category.value
if exclude_none:
d = {k: v for k, v in d.items() if v is not None}
return d return d