I'm creating a new-style class in Python 3.6. I've defined a property (with the @property decorator) called interaction_id. This is a string value with a maximum length of 100.Originally, I had naively written the setter like this:
@interaction_id.setterdef interaction_id(self, value: str): if len(value) > 100: raise ValueError("Value may not exceed 100 characters.") self._interaction_id = value
@interaction_id.setter@max_length(100)def interaction_id(self, value: str): self._interaction_id = value
def maxlength(length): def maxlength_decorator(func): def wrapper(*args, **kwargs): if len(args[1]) > length: raise ValueError("Value must not exceed {} characters".format(length)) return func(*args, **kwargs) return wrapper return maxlength_decorator
8/13/2018 5:46:49 PM