|
1 | 1 | import __future__ |
2 | 2 |
|
3 | 3 | import ast |
| 4 | +import collections |
4 | 5 | import copy |
5 | 6 | import inspect |
6 | 7 | import sys |
|
13 | 14 | from .options import Options |
14 | 15 |
|
15 | 16 |
|
16 | | -class SettingsDict(dict): |
| 17 | +class SettingsDict(collections.UserDict): |
17 | 18 | def __init__(self, *, options, bases): |
18 | | - super().__init__(__options__=options) |
| 19 | + super().__init__() |
| 20 | + self.options = options |
19 | 21 | if options.inject_settings: |
20 | 22 | to_inject = {} |
21 | 23 | for base in reversed(bases): |
@@ -75,13 +77,10 @@ def __prepare__(name, bases): |
75 | 77 | return SettingsDict(options=Options(meta), bases=bases) |
76 | 78 |
|
77 | 79 | def __new__(meta, name, bases, namespace): |
78 | | - options = namespace.pop("__options__", None) |
79 | | - if not isinstance(options, Options): |
80 | | - raise AttributeError("__options__ cannot be overwritten") |
81 | 80 | if "Meta" in namespace and not isinstance(namespace["Meta"], type): |
82 | 81 | raise TypeError("{}.Meta has to be a class".format(name)) |
83 | | - namespace["_options"] = options |
84 | | - return super().__new__(meta, name, bases, namespace) |
| 82 | + namespace["_options"] = namespace.options |
| 83 | + return super().__new__(meta, name, bases, namespace.data) |
85 | 84 |
|
86 | 85 | def __dir__(cls): |
87 | 86 | default_settings = cls._options.default_settings |
|
0 commit comments