You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
Is there a way to get data validation on attribute setting?
Can it be achieved with your package e.g. by subclassing and overwriting __setattribute__?
Or if this not in scope, is there some other package you can recommend?
@Bultako and I are looking for a solution to have hierarchical config objects that offer dot access and do type validation (or more, a la JSON schema) as users interact with the object. Basically the structure of the config should be frozen, types should be fixed, only values should be allowed to change.
from dataclasses import dataclass
from dataclasses_jsonschema import JsonSchemaMixin
@dataclass
class Point(JsonSchemaMixin):
"A 2D point"
x: float
y: float
p = Point(3, 4)
I'd like this to raise an error:
p.x = "not a number, please no"
The text was updated successfully, but these errors were encountered:
Our use case is for configuration, where users sometimes write it in YAML, and sometimes they then interactively change config items at runtime, e.g.:
config.analysis.debug = True
and we want this to fail immediately
config.analysis.debug = "yes, please"
For our use case performance isn't a concern at all, always re-validating the whole object would be fine. But I guess it's not possible or easy if the schema is for config and then it should run when config.analysis.debug.__setattr__ runs.
Is there a way to get data validation on attribute setting?
Can it be achieved with your package e.g. by subclassing and overwriting
__setattribute__
?Or if this not in scope, is there some other package you can recommend?
@Bultako and I are looking for a solution to have hierarchical config objects that offer dot access and do type validation (or more, a la JSON schema) as users interact with the object. Basically the structure of the config should be frozen, types should be fixed, only values should be allowed to change.
I'd like this to raise an error:
The text was updated successfully, but these errors were encountered: