Skip to content

Ability to add a doc string to attr.ib #8

@econchick

Description

@econchick

Current behavior:

In [17]: @attr.s()
   ....: class Bar(object):
   ....:     x = attr.ib()
   ....:

In [18]: b = Bar(x="foo")

In [19]: b.x
Out[19]: 'foo'

In [20]: help(b.x)
no Python documentation found for 'foo'

Desired behavior:

In [17]: @attr.s()
   ....: class Bar(object):
   ....:     x = attr.ib(help="The x of bar")  # or doc="The x of bar" or whatever
   ....:

In [18]: b = Bar(x="foo")

In [19]: b.x
Out[19]: 'foo'

In [20]: help(b.x)
Help on attribute:

    The x of bar

(or something like that)

Similar to doing:

n [21]: class Foo(object):
   ....:     def __init__(self):
   ....:         self._x = None
   ....:     @property
   ....:     def x(self):
   ....:         """The x of Foo"""
   ....:         return self._x
   ....:

In [22]: f = Foo

In [23]: f.x
Out[23]: <property at 0x10a097940>

In [24]: help(f.x)
Help on property:

    The x of Foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions