-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Description of your problem
The output of the get() method is a different type depending on whether or not it returns the fallback option, meaning that it cannot be reliably assumed to be an object of type Option as expected.
import configupdater
conf = configupdater.ConfigUpdater()
conf.read("config.ini")
example1 = conf.get("section", "existingKey", "fallback").value
print(example1)
conf["section"].setdefault("nonexistantKey", "some value")
example2 = conf.get("section", "nonexistantKey", "fallback").value
print(example2)
example3 = conf.get("section", "nonexistantKey2", "fallback").value
print(example3)Output:
value of key "existingKey"
some value
Traceback (most recent call last):
File "example.py", line 9, in <module>
example3 = conf.get("section", "nonexistantKey2", "fallback").value
AttributeError: 'str' object has no attribute 'value'Please provide any additional information below.
According to this documentation, the get method should return an object of type Option. However, if a fallback value is provided, the literal value of this fallback is returned. I would expect the behaviour of examples 2 and 3 to be the same, where if I provide a fallback value then it will be treated as an option in the respective section and returned as such. The ability to provide a fallback is pointless since I still have to check the output and do something different depending on whether or not the key was found in that section
Versions and main components
- ConfigUpdater Version: 3.1.1
- Python Version: 3.10.12
- Operating system: Ubuntu 22.04
- How did you install ConfigUpdater: pip