| 80 | |
| 81 | |
| 82 | class Settings: |
| 83 | def __init__(self, defaults=None): |
| 84 | self.default_config = defaults or {} |
| 85 | self.user_config = {} |
| 86 | |
| 87 | def __getattr__(self, attr): |
| 88 | if attr in self.user_config: |
| 89 | return self.user_config[attr] |
| 90 | if attr in self.default_config: |
| 91 | return self.default_config[attr] |
| 92 | raise AttributeError( |
| 93 | f"'{self.__class__.__name__}' object has no attribute '{attr}'" |
| 94 | ) |
| 95 | |
| 96 | def __setattr__(self, key, value): |
| 97 | if key in ["default_config", "user_config"]: |
| 98 | super().__setattr__(key, value) |
| 99 | else: |
| 100 | self.user_config[key] = value |
| 101 | |
| 102 | def items(self): |
| 103 | return {**self.default_config, **self.user_config}.items() |
| 104 | |
| 105 | |
| 106 | settings = Settings(DEFAULT_CONFIG) |