On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano <st...@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)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/L3SCMWIIRDW2P4IPQBEII72MDWR4AGVB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to