[Python-ideas] Decorators for variables

Chris Angelico rosuav at gmail.com
Fri Apr 1 13:57:22 EDT 2016

On Sat, Apr 2, 2016 at 4:53 AM, Matthias welp <boekewurm at gmail.com> wrote:
>> But, I think the benefit for @decorator on functions is mainly because a
>> function body is big, and this way we can read the decorator next to the
>> function signature while on a variable, this just add another way to
>> call a function on a variable.
> Yes, it is, but I proposed it to give a visual indicator that it does not
> change the value that is assigned to the identifier, but rather changes the
> behaviour of the identifier, just like what most function decorators do.

Wait, what?

Function decorators are simply higher-order functions: they take a
function as an argument, and return a function [1]. They can't change
the behaviour of the name, only the value it's bound to.


[1] Usually. Nothing's stopping them from returning non-callables,
except that it'd confuse the living daylights out of people.

More information about the Python-ideas mailing list