def autoprops_override_decorate(func: Callable, attribute:str = None, is_getter:bool = True) -> Callable:
"""
Used to decorate a function as an overridden getter or setter, without using the @getter_override or
@setter_override annotations. If the overridden setter has no @contract, the contract will still be
dynamically added. Note: this should be executed BEFORE @autoprops or autoprops_decorate().
:param func: the function on which to execute. Note that it won't be wrapped but simply annotated.
:param attribute: the attribute name. If None, the function name will be used
:param is_getter: True for a getter override, False for a setter override.
:return:
"""
# Simply annotate the fact that this is a function
attr_name = attribute or func.__name__
if is_getter:
if hasattr(func, __GETTER_OVERRIDE_ANNOTATION):
raise DuplicateOverrideError('Getter is overridden twice for attribute name : ' + attr_name)
else:
func.__getter_override__ = attr_name
else:
if hasattr(func, __SETTER_OVERRIDE_ANNOTATION):
raise DuplicateOverrideError('Setter is overridden twice for attribute name : ' + attr_name)
else:
func.__setter_override__ = attr_name
return func
评论列表
文章目录