Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "zenlib"
version = "3.1.1"
version = "3.1.2"
authors = [
{ name="Desultory", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion src/zenlib/namespace/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def new_id_map(id_type, pid, id, nsid, count=1, *args, failures=0):
raise ValueError("id_type must be 'uid' or 'gid")
cmd_args = [f"new{id_type}map", str(pid), str(id), str(nsid), str(count), *map(str, args)]
try:
return run(cmd_args, check=True)
return run(cmd_args, check=True, capture_output=True)
except CalledProcessError as e:
if failures > 5:
raise e
Expand Down
11 changes: 9 additions & 2 deletions src/zenlib/types/validated_dataclass.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from dataclasses import dataclass
from typing import get_type_hints


def validatedDataclass(cls):
from zenlib.logging import loggify
from zenlib.util import merge_class


cls = loggify(dataclass(cls))
base_annotations = {}
for base in cls.__mro__:
base_annotations.update(getattr(base, "__annotations__", {}))

cls.__annotations__.update(base_annotations)

class ValidatedDataclass(cls):
def __setattr__(self, attribute, value):
Expand All @@ -20,7 +25,9 @@ def _validate_attribute(self, attribute, value):
if value is None:
return

expected_type = get_type_hints(self.__class__)[attribute]
expected_type = self.__class__.__annotations__.get(attribute)
if not expected_type:
return value # No type hint, so we can't validate it
if not isinstance(value, expected_type):
try:
value = expected_type(value)
Expand Down
Loading