Constructor documentation assigned to class or __init__?

L

Leif K-Brooks

Should a class's constructor be documented in the class's docstring or
__init__'s docstring? For instance:

class Foo(object):
"""This class represents mating lizards. Constructor requires one
argument, the lizard this lizard is mating with."""
def __init__(self, other):
pass

# or

class Bar(object):
""This class represents mating lizards."""
def __init__(self, other):
"""Initiate the object. Requires one argument, "other", which is the
lizard this lizard is mating with."""
pass
 
Y

Yermat

Leif said:
Should a class's constructor be documented in the class's docstring or
__init__'s docstring? For instance:

class Foo(object):
"""This class represents mating lizards. Constructor requires one
argument, the lizard this lizard is mating with."""
def __init__(self, other):
pass

# or

class Bar(object):
""This class represents mating lizards."""
def __init__(self, other):
"""Initiate the object. Requires one argument, "other", which is
the lizard this lizard is mating with."""
pass

Think as a user of your library: Where will you look at if you do not
know how to use a class ?
 
?

=?ISO-8859-1?Q?Holger_T=FCrk?=

Leif said:
Should a class's constructor be documented in the class's docstring or
__init__'s docstring? For instance:

class Foo(object):
"""This class represents mating lizards. Constructor requires one
argument, the lizard this lizard is mating with."""
def __init__(self, other):
pass

# or

class Bar(object):
""This class represents mating lizards."""
def __init__(self, other):
"""Initiate the object. Requires one argument, "other", which is
the lizard this lizard is mating with."""
pass

It's probably a matter of taste, but
I'd prefer the style like in class Bar, because
information about the constructor is technically
nearer to the constructor.
Please don't write "Initiate the object." That's
what a constructor is (almost) always supposed to do.

Regards,

Holger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,051
Members
47,656
Latest member
rickwatson

Latest Threads

Top