On Wed, Aug 05, 2020 at 06:15:22PM -0700, Guido van Rossum wrote:
> On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano <st...@pearwood.info> wrote:

> > 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.)

You are technically correct, which is the best kind of correct.

The documentation uses very close to the same wording as me

https://docs.python.org/3/reference/compound_stmts.html#function-definitions

but does make the point that "except that the original function is not 
temporarily bound to the name func". Since I wasn't writing a reference 
manual, I didn't think this level of pedantry was needed :-)

The bottom line is that the function or class statement has to be 
executed *in some sense* in order to create the function or class 
object, that object has to be passed to the decorator, and finally the 
object returned by the decorator has to be bound to the original name.


-- 
Steven
_______________________________________________
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/24RHEAJTRYMH7BPMAV5GQ66DQWAV6THG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to