-
-
Notifications
You must be signed in to change notification settings - Fork 337
-
I wonder if it is possible to read a generic dictionary from a config file (i.e. yaml), and then add new items to the existing dictionary.
For example, I have the following yaml file:
conf: a: 1 b: 2
In the container:
@dataclass class MyClass conf: dict[str, any] class Container(containers.DeclarativeContainer): config = providers.Configuration() my_class_factory = providers.Factory(MyClass, config.conf) container = Container() container.config.from_yaml("config.yaml") obj = container.my_class_factory()
This work, creating an object with the conf dictionary defined in the yaml file.
However, I want to add other items to the conf dictionary not defined in the file.
I only manage to do in this way:
@dataclass class MyClass conf: dict[str, any] class Container(containers.DeclarativeContainer): config = providers.Configuration() my_class_factory = providers.Factory(MyClass) container = Container() container.config.from_yaml("config.yaml") obj = container.my_class_factory(conf={**container.config["conf"], "c": 67})
Is there a better way of doing it?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment