PEP318: property as decoration

Sean Ross frobozz_electric at hotmail.com
Thu Jun 12 09:52:59 EDT 2003


"Gerrit Holl" <gerrit at nl.linux.org> wrote in message
news:mailman.1055410883.13759.python-list at python.org...
> Such a hack isn't that hard of course.
> I solved it by adding "d=" just before my docstring:

I see ... So

> Sean Ross wrote:
> >         def foo():
                      "foo's doc string"
                       ...
> >                 fdoc = "foo"
> >                 return fget, fset, fdel, fdoc
>
Gerrit Holl wrote:
> Make that: "return fget, fset, fdel, __doc__"

was not what you really wanted. You wanted:

def foo():
        fdoc="foo's doc string"
        ...

which is what I started with?!  Heh. ;)


>__doc__
> doesn't need to stay anyway, because this outer function gets overwritten
> by the property.

Personally, I liked the idea of being able to use a proper doc string to
document my property-maker function  "foo", i.e.,

def foo():
    "proper doc string goes here"
    ...

which I can then quietly pass along to the property "foo" that will
overwrite this function. Is it necessary? Nope. I already had it working
without this. Is it neat? Yep. It grabs hold of the function *inside* of the
function. That is so cool! Should it be done? Probably not...but that wasn't
the point of the exercise. The only real reason I made it was to see if I
could.

> The only place I use frames is in by debug() function: this way, it
> prints the function and lineno of the caller, which easy's debugging.

Well, technically, "this" can be used in debugging (if made more robust with
regard to class lookup) to inspect your function by asking it things: like
this().__name__, this().__doc__.

Anyway, thanks for your earlier suggestion re: __doc__, it provided me with
a few minutes of amusement cobbling together "this()". I don't think it
should be used, but I did enjoy trying to make it work.







More information about the Python-list mailing list