Skip to content

Commit fc31613

Browse files
authored
Merge pull request #12 from desultory/dev
Capture namespace output, improve validation for validatedDataclass
2 parents 43fddae + f00dc71 commit fc31613

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zenlib"
7-
version = "3.1.1"
7+
version = "3.1.2"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

src/zenlib/namespace/namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def new_id_map(id_type, pid, id, nsid, count=1, *args, failures=0):
2424
raise ValueError("id_type must be 'uid' or 'gid")
2525
cmd_args = [f"new{id_type}map", str(pid), str(id), str(nsid), str(count), *map(str, args)]
2626
try:
27-
return run(cmd_args, check=True)
27+
return run(cmd_args, check=True, capture_output=True)
2828
except CalledProcessError as e:
2929
if failures > 5:
3030
raise e

src/zenlib/types/validated_dataclass.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from dataclasses import dataclass
2-
from typing import get_type_hints
32

43

54
def validatedDataclass(cls):
65
from zenlib.logging import loggify
76
from zenlib.util import merge_class
87

8+
99
cls = loggify(dataclass(cls))
10+
base_annotations = {}
11+
for base in cls.__mro__:
12+
base_annotations.update(getattr(base, "__annotations__", {}))
13+
14+
cls.__annotations__.update(base_annotations)
1015

1116
class ValidatedDataclass(cls):
1217
def __setattr__(self, attribute, value):
@@ -20,7 +25,9 @@ def _validate_attribute(self, attribute, value):
2025
if value is None:
2126
return
2227

23-
expected_type = get_type_hints(self.__class__)[attribute]
28+
expected_type = self.__class__.__annotations__.get(attribute)
29+
if not expected_type:
30+
return value # No type hint, so we can't validate it
2431
if not isinstance(value, expected_type):
2532
try:
2633
value = expected_type(value)

0 commit comments

Comments
 (0)