Have you metaprogrammed today?
def _make_section(dct, section_name, section_dct):
"""Make session dispatcher."""
# __slots__
section_dct['__slots__'] = ('config',)
# __init__
def __init__(self, config):
self.config = config[section_name]
section_dct['__init__'] = __init__
section_class = type(section_name, (), section_dct)
dct[section_name] = property(lambda self: section_class(self.config))
class ConfigMeta(type):
def __new__(mcs, name, parents, dct):
sections = dct['Sections']
for section_name, section in sections.__dict__.items():
if section_name.startswith('_'):
continue
section_dct = dict()
for config_name, config_getter in section.__dict__.items():
section_dct[config_name] = property(config_getter)
_make_section(dct, section_name, section_dct)
return super().__new__(mcs, name, parents, dct)