[Python-Dev] Decorator classification: location, format, details

Terry Reedy tjreedy at udel.edu
Tue Aug 10 03:18:14 CEST 2004


I found the recent discussion of decorators rather confusing until I
noticed that objections and options to prefixed @deco fell into three
categories: location, format, and details.  Perhaps this structuring might
help the debate.

LOCATION (6 proposals/alternatives)

Multiple def prefix - dedented relative to def and covering all indented
under it.

Prefix to single def - the alpha2 innovation.

Infix in header, before or after function name.

Suffix to header, after param list, before :.

Top of body

postfiX - the 2.3 status quo

FORMAT

The format depends somewhat but not completely on location, and there have
been one to many proposed for each.  By 'format' I here mean a symbolic
template without literals (except possibly \n).  In grammar terms, a
production rhs without terminals.

For alpha2 prefix, the format is, simplified, sequence of decos, where deco
is pfix user_decorator.  One alternative prefix form is open seq of
user_decorators close.  Another is a prefixed suite.

For 2.3, the postfiX form is func_name = user_decorator(func_name).

DETAILS

These are the constant literals supplied by the designer (or grammar)
rather than the symbolic variables filled in by the user/programmer.
Grammatically, these are the terminal productions.

For alpha2, pfix is '@'.  Suggested alternatives include '=', '|', and
'deco'.


I notice in the PEP, the wiki, and here that discussions of a particular
option with all 3 aspects fixed tend to mix discussion of the pros and cons
of its location, which actually apply to all formats in that location, and
discussion the pros and cons of the format, which mostly would apply to the
format in any position.  I think greater separation would be less
confusing.  Is it possible to first pick a location, then a format, then
fill in the details?

Terry J. Reedy





More information about the Python-Dev mailing list