<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Apr 1, 2016 at 2:09 PM Matthias welp <<a href="mailto:boekewurm@gmail.com">boekewurm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>> Function decorators<br><br></div>There are decorators that return a callable that not calls the function that was given as an argument, but also do some other things, and therefore change the behaviour of that function.<br><br></div></div></div><div dir="ltr"><div>
> So instead of<br>> <br>> a = Char(length=10, value='empty')<br>> <br>
> you want<br>
> <br>
> @Char(length=10)<br>
> a = 'empty'<br>
> <br>
> ?<br><br></div></div><div dir="ltr"><div></div>If possible, yes. So that there is a standardized way to access changing variables, or to put limits on the content of the variable, similar to the @accepts and @produces decorators that are seen here (<a href="https://wiki.python.org/moin/PythonDecoratorLibrary#Type_Enforcement_.28accepts.2Freturns.29" target="_blank">https://wiki.python.org/moin/PythonDecoratorLibrary#Type_Enforcement_.28accepts.2Freturns.29</a>)</div></blockquote><div><br></div><div>There is a standardized way. You can extend ``property`` or mimic its implementation. Then instead of </div><div><br></div><div>class Foo:</div><div> a = property(getter, no_cycles)</div><div><br></div><div>You can write</div><div><br></div><div>class Foo:</div><div> a = NoCycles()</div><div><br></div><div><br></div><div>I haven't linked to a how-to for doing this is, because I think it's unnecessary for most small projects. Every so often someone asks for a more pleasant syntax for specifying a property, getter and setter. Guido seems to consistently reply that he thinks our current situation is good enough. I'd dig up a link to the email archive for you, but Google wasn't being very kind to me.</div></div></div>