[PEP 224] Attribute Docstrings

Lawrence Kesteloot lk at veriomail.com
Sat Aug 26 01:02:42 EDT 2000


>     Here is an example:
>
>         class C:
>             "class C doc-string"
>
>             a = 1
>             "attribute C.a doc-string (1)"
>
>             b = 2
>             "attribute C.b doc-string (2)"


Correct me if I'm wrong about this, but initialization of things
like lists can't be done in a class definition.  For example:

    class C:
        x = []

wouldn't work because the list itself would be shared among
the instances (assuming you don't want that).  This kind of
initialization must be done in the constructor in order to
create a new list for each instance.  If that's the case,
then this PEP is only useful for non-mutable attributes
such as floats, strings, and integers.

Is this correct?  Or would you just do:

    class C:
        x = []
        "attribute C.x does whatever"

        def __init__(self):
            self.x = list(self.x)

which seems bad.

Either way this PEP seems like it has limited value.

Personally, I would love to declare all class attributes like you
do instead of in the constructor.  But Python doesn't seem to
work that way as far as I know.

Lawrence






More information about the Python-list mailing list