This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cool-RR
Recipients cool-RR
Date 2014-10-17.13:15:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1413551704.24.0.449864930924.issue22656@psf.upfronthosting.co.za>
In-reply-to
Content
The builtin `property` lets you specify a `doc` argument for your properties, which is great because then it shows up in `help`. So I figured that when I'm writing my own descriptor, I could set `__doc__` on it and have `help` use it. Not so, `help` ignores it. 

See this example:

    class Property(object):
        "Emulate PyProperty_Type() in Objects/descrobject.c"
    
        def __init__(self, fget=None, fset=None, fdel=None, doc=None):
            self.fget = fget
            self.fset = fset
            self.fdel = fdel
            if doc is None and fget is not None:
                doc = fget.__doc__
            self.__doc__ = doc
    
        def __get__(self, obj, objtype=None):
            if obj is None:
                return self
            if self.fget is None:
                raise AttributeError("unreadable attribute")
            return self.fget(obj)
    
        def __set__(self, obj, value):
            if self.fset is None:
                raise AttributeError("can't set attribute")
            self.fset(obj, value)
    
        def __delete__(self, obj):
            if self.fdel is None:
                raise AttributeError("can't delete attribute")
            self.fdel(obj)
    
        def getter(self, fget):
            return type(self)(fget, self.fset, self.fdel, self.__doc__)
    
        def setter(self, fset):
            return type(self)(self.fget, fset, self.fdel, self.__doc__)
    
        def deleter(self, fdel):
            return type(self)(self.fget, self.fset, fdel, self.__doc__)
    
    
    class A:
        x = property(lambda self: 3,
                     doc='Helpful text')
        
        y = Property(lambda self: 7,
                     doc='More Helpful text')
        
    
    help(A.x) # Shows 'Helpful text'
    help(A.y) # Does not show 'More Helpful text'
    

It seems that `property` is special-cased or something. I want to be able to set a docstring on my own descriptors.
History
Date User Action Args
2014-10-17 13:15:04cool-RRsetrecipients: + cool-RR
2014-10-17 13:15:04cool-RRsetmessageid: <1413551704.24.0.449864930924.issue22656@psf.upfronthosting.co.za>
2014-10-17 13:15:04cool-RRlinkissue22656 messages
2014-10-17 13:15:03cool-RRcreate