Decorators, with optional arguments

Stephen Hansen me+list/python at ixokai.io
Sat Jul 3 01:37:00 EDT 2010


On 7/2/10 11:58 AM, Alf P. Steinbach /Usenet wrote:

> <code>
> #Py3

I'm stuck on Python 2.x, as I mentioned (albeit only in a comment). That
said this code does not seem to be including any Py3isms that aren't
compatible.

> class Thing(object):
>     @expose()
>     def test1(self, arg1):
>         return arg1
> 
>     @expose( "testing" )
>     def test2(self, arg2):
>         return arg2

Its the @expose() which bugs me. I have some decorators (made by me and
others) which have no args, that look like @hello. Then some which
always have args, that look like @hello("whatsup dude"). To then have a
decorator which has no args as @hello(), I can't abide. For internal
consistancy purposes, I want "no arguments" to always look like @hello,
and "arguments" to look like @hello(something). I don't want to have to
think, "Hey, does this no-arg version require parens or no?"

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100702/15897fcd/attachment-0001.sig>


More information about the Python-list mailing list