python-configuration
python-configuration copied to clipboard
Cast a config value to a python type
It would be nice if there was a interface to cast config values to specific types when they get loaded.
I'm using this library to configure file paths alot and I'm finding I have to nest the config values a lot since they currently only return str, int and float:
from module import config # previously loaded ConfigurationSet
from pathlib import Path
my_func(Path(config.paths.train_features))
If the ConfigurationSet class is immutable, that casting would have to happen when it's created. I tried to interate through the values and cast them myself, but I couldn't figure it out.
I'm having the same trouble with an env value that is a int, but when it's loaded into the config, it's a string. So I think there's a potential need being met by adding a cast to variables loaded in the config.
Do you have an example of this? There are no specific casts forced by the library ; the data type is taken by the first element the ConfigurationSet sees. Is this a particular case of https://github.com/tr11/python-configuration?tab=readme-ov-file#caveats-1?