We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
attr_getters
__post_init__
I'm trying to pass in a config object that can be used to set defaults for attributes dynamically:
config
from dataclasses import dataclass import jsons @dataclass class Car(jsons.JsonSerializable): engine: str = None def __post_init__(self): if self.engine is None self.engine = self.config["engine_default"] car = Car.loads("{}", attr_getters={"config": lambda: {"engine_default": "mid"}})
fails with,
jsons.exceptions.DeserializationError: Could not deserialize value "{}" into "__main__.Car". 'Car' object has no attribute 'config'
(If there's no __post_init__, car.config works just fine here, but later in the cycle.)
car.config
If there's a better way of achieving this I'd be happy to hear it--I'd likely use the same idea to inject a logger dependency too.
logger
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I'm trying to pass in a
config
object that can be used to set defaults for attributes dynamically:fails with,
(If there's no
__post_init__
,car.config
works just fine here, but later in the cycle.)If there's a better way of achieving this I'd be happy to hear it--I'd likely use the same idea to inject a
logger
dependency too.The text was updated successfully, but these errors were encountered: