On Wed, Dec 2, 2020 at 9:18 PM Steven D'Aprano firstname.lastname@example.org 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:
"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.