osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Call for prudence about PEP-572


On Mon, Jul 9, 2018 at 3:55 AM, Eric V. Smith <eric at trueblade.com> wrote:
> I agree with Chris in this case. That said, there is at least one place
> where the grammar does forbid you from doing something that would otherwise
> make be allowable: decorators.
>
>>>> @lookup[0]
>   File "<stdin>", line 1
>     @lookup[0]
>            ^
> SyntaxError: invalid syntax
>
> But this works:
>
>>>> new_decorator = lookup[0]
>>>> @new_decorator
> ... def f(): pass
>
> Thus, the idea of restricting the type of expression that can be used in
> particular circumstances is not without precedent, and should not be
> dismissed at face value. That is, unless we want to remove the restriction
> on decorators, which I'm okay with, too. I have occasionally wanted to do
> something more complicated with a decorator, and used the workaround above.
>

This is true. I wasn't around when decorator syntax was discussed;
what were the reasons for this being the way it is? It isn't simply
"'@' test".

ChrisA