attrs_extractor.py 文件源码

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

项目:jsonschema-extractor 作者: toumorokoshi 项目源码 文件源码
def _extract_attribute(cls, extractor, attribute):
        is_required = attribute.default is attr.NOTHING

        schema = None
        if "jsonschema" in attribute.metadata:
            schema = attribute.metadata["jsonschema"]
        elif attribute.type is not None:
            schema = extractor.extract(attribute.type)
        else:
            for validator in _iterate_validator(attribute.validator):
                if isinstance(validator, _InstanceOfValidator):
                    schema = extractor.extract(validator.type)

        if schema is None:
            raise UnextractableSchema(
                "all attributes must have an 'InstanceOfValidator'. attribute {0} does not.".format(attribute)
            )
        return AttributeDetails(
            attribute.name, schema, is_required
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号