def verify_properties(interface_cls, cls):
prop_attrs = dict(fget='getter', fset='setter', fdel='deleter')
for name, prop in inspect.getmembers(interface_cls, inspect.isdatadescriptor):
cls_prop = getattr(cls, name, None)
for attr in prop_attrs:
# instanceof doesn't work for class function comparison
if type(getattr(prop, attr, None)) != type(getattr(cls_prop, attr, None)):
raise NotImplementedError(
"'{}' must implement a {} for property '{}' defined in interface '{}'" # flake8: noqa
.format(cls.__name__, prop_attrs[attr], name, interface_cls.__name__)
)
评论列表
文章目录