[Python-Dev] @decorators, the PEP and the "options" out there?

Tim Peters tim.peters at gmail.com
Sat Aug 7 08:54:35 CEST 2004


[ixokai at gmail.com]
>  Doesn't the fact that the @stuff is at the same level and has no
> connection to the def besides 'above' bother you in our universe of
> indentation-love?

No, it doesn't.  I routinely put comment blocks before my functions,
"at the same level", and they're strongly connected to the function in
reality if not by syntax rule.  I *like* them at that level too,
because they're usually about the external behavior of the function,
not about its internals.  Decorators are also more about externals
than internals, so it feels right to me to see them at the same level
as the function's comment block.  Guido agrees, although he doesn't
yet realize it <wink>, as evidenced by his earlier comment that
docstrings probably would have been better placed before defs too. 
Comment blocks, docstrings, and decorators are all about what the
function is like "from the outside".  If Python supported design by
contract natively, I'd also like to see method pre- and
post-conditions at this level.

>  And the fact that the pie *is* "at", and why that it just doesn't
> "read"? '"define methy1 at staticmethod" is wrong, but "at
> staticmethod define methy2" is right.

When I read

# Here's a comment.

I don't verbalize it as "splat here's a comment".  I don't feel a need
to verbalize "@" either.

> I like Python to be able to be read very easily.

I care about readability, but little about pronouncability.

> If we have to have it at the same level as def and above, we soo need a
> keyword..pweeze?

Pick the keyword you'd like.  Then whenever you see "@", pronounce
that word instead <wink>.

> class MyLittleToy:
>   def methy1(self):
>       print 'whee'
>   @staticmethod
>   def methy2():
>        print 'woo'
>   @staticmethod
>   def methy3(arg):
>        for i in arg:
>           print 'woohoo'
> 
> ? That bothers me a looot... and is the primary reason I hate the pie.
> That and I really don't want anymore punctuation.

That bothers me a lot too, but because the world really isn't running
out of vertical whitespace:

class MyLittleToy:

    def methy1(self):
        print 'whee'

    @staticmethod
    def methy2():
        print 'woo'

    @staticmethod
    def methy3(arg):
        for i in arg:
            print 'woohoo'
 
doesn't bother me.


More information about the Python-Dev mailing list