validators.py 文件源码

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

项目:caniuseweekly 作者: tjwudi 项目源码 文件源码
def __call__(self, inst, attr, value):
        if not isinstance(value, dict) and \
                not isinstance(value, MappingProxyType):
            raise TypeError(
                """'{name}' must be a dict object or
                instance of MappingProxyType.""".format(
                    name=attr.name,
                ),
            )

        if not self.required_keypaths:
            return

        for keypath in self.required_keypaths:
            current = value
            components = keypath.split('.')
            for component in components[:-1]:
                current = current.get(component, {})
            if components[-1] not in current:
                raise DictValidatorKeypathDoesNotExistError(
                    "'{keypath}' not found".format(
                        keypath=keypath,
                    )
                )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号