Q: Can Configuration values be made required?
See original GitHub issueCouldn’t find an example of this in the docs but I am trying to ensure that the system fails fast if the container hasn’t been properly configured when the necessary provider is called. For example:
class MyContainer(DeclarativeContainer):
config = Configuration()
some_client = Singleton(SomeClient, config.something_important)
Right now, if I forget to set mycontainer.config.something_important
before calling mycontainer.some_client()
, then SomeClient
will be given None
as its parameter which is actually worse than forgetting to pass the argument at all because Python will allow it even if it’s not an optional parameter. I don’t want to sprinkle my classes with something_important is None
checks.
What I really want is to be able to specify the exact keys I would expect in a Configuration provider and have the Container initialization fail if those values are not provided. Do you have any suggestions?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
I have released version
4.10.0
with strict mode and required modifier features for theConfiguration
provider. Here is a doc: https://python-dependency-injector.ets-labs.org/providers/configuration.html#strict-mode-and-required-optionsGlad to hear that! Thank you again