<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>> > Currently the way to create variables with custom get/set/deleters is to
<br>> > use the @property decorator or use property(get, set, del, doc?), and
<br>> > this must be repeated per variable. If I were able to decorate multiple <br>> > properties with decorators like @not_none or something similar, it <br>> > would
take away a lot of currently used confusing code.<br>> <br></div>> How does this prevent repetition?<br><br></div>If you were to define a variable you currently could use the @property for each variable, which could take up to 3 declarations of the same name per use of the pattern. Using a decorator might take that down to only 1 extra line.<br><br></div>> What about augmented assignment? Should this work?<br><br></div>The steps it would go through were these:<br><br></div>1. the value of the statement is calculated. e.g. val + 20 in the first case given.<br></div>2. the decorator is applied on that value<br></div>3. the return value from the decorator is then assigned to the variable.<br><br></div>This is, again, very similar to the way function decorators work, and a short-handed method to make property access more transparent to the programmer.<br><br>>
Also, what about attributes and items?<br><br></div>I have not yet thought about that, as they are not direct scope variables. The idea was there to decorate the attribute or variable at the moment it would get defined, not per se after definition.<br><br>> > instead of having to do that using methods<br>> <br><span class="im"></span></div><span class="im"></span>> By "methods" you mean "function composition", right? <br><br></div>Sorry for my terminology, I meant function calls, but function composition is indeed what would happen effectively.<br></div>