add Guido's comment about nested decorator problems

This commit is contained in:
Skip Montanaro 2004-08-06 18:34:15 +00:00
parent 980dc9c859
commit 2ad669666f
1 changed files with 21 additions and 1 deletions

View File

@ -229,6 +229,24 @@ suggests nesting of namespaces that doesn't exist. The name ``foo``
would actually exist at the same scope as the using: block. Finally,
it would require the introduction of a new keyword.
The obvious alternative that nests the function within the block
::
using:
dec1
dec2
...
def foo(arg1, arg2, ...):
pass
has its own set of drawbacks. Having the minimal indent level be
three deep for methods is painful for those using limited-width
windows. The inconsistent indentation between methods of the same
class with and without decorators would be a readability problem.
Finally, adding or removing decorators would require reindenting the
entire function/method body.
Guido proposed and implementated a patch to support interpretation of
a `list of decorators`_ as a prefix to function definitions ::
@ -285,7 +303,9 @@ There is some history in Java using @ initially as a marker in
`Javadoc comments`_ and later in ... mumble mumble ... The fact that
@ was previously unused as a token in Python also means it's clear
there is no possibility of such code being parsed by an earlier
version of Python, leading to possibly subtle semantic bugs.
version of Python, leading to possibly subtle semantic bugs. That
said, @ is still a fairly arbitrary choice. Some have suggested using
| instead.
For syntax options which use a list-like syntax (no matter where it
appears) to specify the decorators a few alternatives were proposed: