On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Wed, Aug 05, 2020 at 10:40:02PM +1200, Greg Ewing wrote:

> A considerable number of moons ago, I suggested that
>     @my_property
>     fred = 42
> should expand to
>     fred = my_property("fred", 42)

That require two different rules for decorators:

@decorator over a `class name` or `def name` statement:

- execute the statement
- bind `name = decorator(name)`

But that's not what's done. (Proof: if the decorator raises, the name remains unbound.)
@decorator over a binding `target = expression`:

- bind `target = decorator("target", expression)`

So we're adding significant complexity to the concept of "decorator".

(That said, I'm not a fan of decorating assignments. The reason we invented decorators in the first place doesn't apply here.)
--Guido van Rossum (python.org/~guido)