Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case insensitive loading/lookup as opt-in #10

Open
RonnyPfannschmidt opened this issue Jul 6, 2022 · 0 comments
Open

case insensitive loading/lookup as opt-in #10

RonnyPfannschmidt opened this issue Jul 6, 2022 · 0 comments

Comments

@RonnyPfannschmidt
Copy link

when migrating from other configuration systems, those sometimes are very lenient on how they deal with uppercase/lowercase/mixed case keys

it would be nice to be able to

  1. normalize the case of keys on loading + warning when normalization was necessary
  2. normalize the case of lookup when using config objects in old code

example:

# settings.yaml
MAIN:
  hostname: deathstar.example.com
# load_config.py

config = Config.from_path("settings.yaml")
fixed_config = Config()
fixed_config.merge(config, context=CaseNormalizer(normalize=str.lower, warn=True)
# warns here about MAIN needing to be renamed to main

safely_usable_config = CaseSensitiveLookup(fixed_config)
def get_host(settings):
   # legacy code, gets warning about MAIN and HOST
   return settings.MAIN.HOST
  
get_host(safely_usable_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant