[Python-ideas] Decorators for variables
Stephen J. Turnbull
stephen at xemacs.org
Sun Apr 3 05:24:22 EDT 2016
Steven D'Aprano writes:
> > 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.
>
> I'm afraid I don't understand what you mean by this. What does
> "while on a variable" mean here?
Missing punctuation (see substring in square brackets):
and this way we can read the decorator next to the function
signature[. W]hile on a variable, this just add another way to
call a function on a variable.
So, it appears that he's proposing pure syntactic sugar with no
semantic change at all. The syntactic effects are that decorator
syntax separates function calls from the values they act on (-1 on
that), and makes it appear that in Python a function can change the
value of its formal argument (-1 on that, too).
The latter characteristic may need some expansion. Of course Python
has mutable objects which can be changed "inside" a function and that
effect propagates to "outside" the function. But in the containing
scope, while the object has mutated, the variable (more precisely, the
name-object binding) has not.
It seems to me that everything he's asked for can be accomplished by
defining a descriptor class and assigning an instance of that class.
I don't yet understand why that isn't good enough, unless it's just a
matter of taste about the sweetness of syntax.
More information about the Python-ideas
mailing list