Re: Enhanced property decorator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benjamin

    Re: Enhanced property decorator

    On Aug 25, 8:45 pm, Daniel <miller...@gmai l.comwrote:
    I've often been frustrated by the inability of the built-in property
    descriptor to handle anything other than a read-only property when
    used as a decorator. Furthermore, read/write/delete properties take
    their doc-string and property definition at a non-intuitive and
    awkward place (after the getter/setter/delter functions). The
    following are three possible solutions to this problem (inspired by
    messagehttp://groups.google.c om/group/comp.lang.pytho n/msg/9a56da7ca8ceb7c 7).
    I don't like the solution in that thread because it uses apply() which
    will go away in Python 3.
    I didn't read the rest of the thread, but I think Python 2.6 may have
    want you want:

    class A(object):

    @property
    def my_prop(): return self._prop

    @my_prop.setter
    def my_prop(prop): self._prop = prop

    @my_prop.delete r
    def my_prop(): del self._prop
  • Daniel

    #2
    Re: Enhanced property decorator

    On 25 Aug, 21:52, Benjamin <musiccomposit. ..@gmail.comwro te:
    ... I think Python 2.6 may have
    want you want:
    >
    class A(object):
    >
        @property
        def my_prop(): return self._prop
    >
        @my_prop.setter
        def my_prop(prop): self._prop = prop
    >
        @my_prop.delete r
        def my_prop(): del self._prop
    Hmm, interesting. I wonder if it suppports setting the doc-string in a
    similar way? I'll have to look into that. Thanks for pointing this
    out.

    ~ Daniel

    Comment

    • Benjamin

      #3
      Re: Enhanced property decorator

      On Aug 25, 9:00 pm, Daniel <miller...@gmai l.comwrote:
      On 25 Aug, 21:52, Benjamin <musiccomposit. ..@gmail.comwro te:
      >
      ... I think Python 2.6 may have
      want you want:
      >
      class A(object):
      >
          @property
          def my_prop(): return self._prop
      >
          @my_prop.setter
          def my_prop(prop): self._prop = prop
      >
          @my_prop.delete r
          def my_prop(): del self._prop
      >
      Hmm, interesting. I wonder if it suppports setting the doc-string in a
      similar way? I'll have to look into that. Thanks for pointing this
      out.
      It takes the getter's docstring as usual.
      >
      ~ Daniel

      Comment

      Working...