[Python-Dev] Decorators: vertical bar syntax (original) (raw)

Guido van Rossum guido at python.org
Sat Aug 7 18:17:42 CEST 2004


The new "vertical bar" syntax was proposed recently, and has gotten almost unanimously positive feedback. In particular, of 17 responses to the syntax, only one has been negative (see table, below).

I want to mention one argument for '@' that doesn't apply to '|': it will be familiar to Java programmers.

I'm including both of the following variants:

|classmethod |accepts(int, int) |returns(float) def foo(arg1, arg2): ... def foo(arg1, arg2): |classmethod |accepts(int, int) |returns(float) ... (I prefer the second, but would be happy with either.)

In the discussion on decorators months ago, solutions involving special syntax inside the block were ruled out early on. Basically, you shouldn't have to peek inside the block to find out important external properties of the function. (Yes, I know that docstrings violate this principle. For the record, it would be better if they were prefix too; and a prefix decorator syntax will let us fix this in the future but introducing a "doc" decorator.)

Please add this to the Wiki for me.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list