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
)
attrs_extractor.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录