Skip to content

case insensitive loading/lookup as opt-in #10

@RonnyPfannschmidt

Description

@RonnyPfannschmidt

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions