[Python-Dev] PEP 318: Decorators last before colon (original) (raw)

Neal Norwitz neal at metaslash.com
Wed Mar 31 12:56:00 EST 2004


On Wed, Mar 31, 2004 at 12:32:35PM -0500, Phillip J. Eby wrote:

I personally would rather have the decorators required to be on the same logical line, and then use: _[classmethod] _ def foo(bar,baz): pass for visual separation. The backslash visually alerts that this is not a mere bare list.

I agree with Phillip about the backslash. But I don't like this variant because it appears to operate by side-effect. If the list had a keyword after it, that wouldn't be as bad, but the only current keywords I can think of (in, for) don't fit well and would overload their meaning. I don't really like any variants, but the original seems the least bad to me:

    def foo(bar, baz) [classmethod]:

Some of the concerns deal with the decorators getting lost after the arguments or they are too far away from the function name. It seems to me that if formatted properly, this isn't as big of a deal:

    def foo(cls, lots, of, arguments, that, will, not,
            fit, on, a, single, line) \
    [classmethod, decorate(author='Someone', version='1.2.3',
                           other='param')]:
        """The docstring goes here."""

I hope that's a pretty unrealistic case. I think all of the proposed variants are ugly with the definition above. But, this may be more reasonable:

    def foo(cls, lots, of, arguments, all, on, a line) \
           [classmethod, 
            decorate(author='Someone', version='1.2.3', other='param')]:
        """The docstring goes here."""

Writing decorators this way is the least surprising to me. Although, I wish there was a better alternative.

Neal



More information about the Python-Dev mailing list