Automatically replace "-" in TOML keys with "_"?
Currently, TS automatically replaces -
in TOML keys with _
. This allows you to have a bit nicer looking config files:
>>> from pathlib import Path
>>> import typed_settings as ts
>>>
>>> @ts.settings
... class Settings:
... line_length: int = 88
...
>>> sf = Path("settings.toml")
>>> sf.write_text("""
... [orange]
... line-length = 79
... """)
27
>>> ts.load_settings(Settings, "orange", [sf])
Settings(line_length=79)
However, this behavior leads to serious problems when you have a dict option and the dict keys contain dashes (e.g., because they are UUIDs):
>>> @ts.settings
... class Settings:
... a_dict: dict
...
>>> sf.write_text("""
... [bug]
... [bug.a-dict]
... a39d-d93f-80ae = "spam"
... f02c-01e4-ff30 = "eggs"
... """)
68
>>> ts.load_settings(Settings, "bug", [sf])
Settings(a_dict={'a39d_d93f_80ae': 'spam', 'f02c_01e4_ff30': 'eggs'})
This use-case seems rather obscure, but it already happend at least once and its result was not desirable.
We have these options now:
-
meh
🙄 - Remove this functionality
- Make it optional with default
toml_dashed_keys=False
- Make it optional with default
toml_dashed_keys=True