On Wed, Dec 2, 2020 at 9:18 PM Steven D'Aprano <st...@pearwood.info> wrote: > > That's "conceptual model". How it's actually implemented is, "bu abuse > > of notation" is: > > > > def decorate(func): > > ... > > > > Works without hitch with the strict mode. > > Okay, Chris made the same point. > > Is that a language guarantee or a quirk of the implementation? > > For this to be guarenteed to work requires the implementation of > decorators to be guaranteed by the language. If it is not already a > guarantee, it will have to be made one. > > (For the record, that is not a point against your proposal, just an > observation.)
Yes, it's part of the original PEP: https://www.python.org/dev/peps/pep-0318/#current-syntax "without the intermediate assignment to the variable func" It's not often significant, but when it is, it's definitely the better way to do it. For one thing, it simplifies the understanding of idioms like this: @spam.setter def spam(self, newvalue): ... And it's not something I do often, but sometimes I've built a decorator that actually looks at the previous binding of a name. Something like this (hypothetical): @validator def frobnicate(thing): if not frobbable: raise Exception When called, the final frobnicate function would check the validator, and if it doesn't error out, would call the original function, whatever that had been. To do that, the validator() decorator function has to be able to see what was previously bound to that name. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2HK3DOPAS5FCZQ6CNXRUCUDXOHCHIGLJ/ Code of Conduct: http://python.org/psf/codeofconduct/