Decorator

Steven D'Aprano steve at pearwood.info
Thu Feb 9 03:48:28 EST 2017


On Thu, 09 Feb 2017 08:03:32 +0100, ast wrote:

> Hi
> 
> In python courses I read, it is explained that
> 
> @decor 
> def f():
>     pass
> 
> is equivalent to:
> 
> def f():
>     pass
> 
> f = decor(f)
> 
> But that's not always true. See this code
[...]
> any comment ?

Congratulations, you've found a microscopic corner of the language where 
the two different ways of applying decorators are different.

Are you just sharing with us, or do you think there is a problem that 
needs to be solved?


You're absolutely correct that when using `property`, trying to apply it 
by hand instead of using the @ syntax is tricky. So don't apply it by 
hand, use the @ syntax.




-- 
Steve



More information about the Python-list mailing list