__init__.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:python-application 作者: AGProjects 项目源码 文件源码
def __new__(mcls, name, bases, dictionary):
        settings = {}
        # copy all settings defined by parents unless also defined in the class being constructed
        for name, setting in chain(*(cls.__settings__.iteritems() for cls in bases if isinstance(cls, ConfigSectionType))):
            if name not in dictionary and name not in settings:
                settings[name] = ConfigSetting(type=setting.type, value=setting.value)
        for attr, value in dictionary.iteritems():
            if isinstance(value, ConfigSetting):
                settings[attr] = value
            elif attr.startswith('__') or isdescriptor(value) or type(value) is BuiltinFunctionType:
                continue
            else:
                if type(value) is bool:
                    data_type = datatypes.Boolean
                else:
                    data_type = type(value)
                settings[attr] = ConfigSetting(type=data_type, value=value)
        dictionary.update(settings)

        cls = super(ConfigSectionType, mcls).__new__(mcls, name, bases, dictionary)
        cls.__settings__ = settings
        cls.__defaults__ = SaveState(cls)

        return cls
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号