[Python-Dev] PEP 318 -- a couple use cases

Guido van Rossum guido at python.org
Thu Apr 1 14:16:33 EST 2004

> I saw both of the following use cases mentioned on the list, and they 
> seemed interesting, so I went ahead and wrote up implementations:
> def property_getter(func):
> def generic(*type_signature):
> Full code is at <http://www.cis.upenn.edu/~edloper/pydecorators.html>.
> But I still don't feel like I have a good handle on what "acceptable" 
> uses of decorators are..  So, for each of these 2 use cases, is it...
>      - an excellent example that should be included in the stdlib
>      - perfectly acceptable, and belongs in the python cookbook
>      - somewhat hackish, but ok under the right circumstances
>      - an abhorition of nature

I'm wavering between 2 (perfectly acceptable) and 3 (somewhat
hackish), only because I consider anything that uses sys._getframe()
to be a danger to society unless proven innocent.

I would probably prefer to do both of these using explicit, different
names.  In particular for properties, I *like* the fact that I can
also explicitly call the getter or setter functions, so I'd probably
continue to write those like this:

  class C(object):

     def getX(self): return self.__x
     def setX(self, x): self.__x = x
     x = property(getX, setX)

I'm not sufficiently comfortable with generic functions to quite know
what feels best there.  But I like the notation you proposed (I would
like it better with the decorators up front though).

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

More information about the Python-Dev mailing list