Skip to content

Commit d02904b

Browse files
committed
wip Akuli#14 stuff
1 parent ce8fa36 commit d02904b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

basics/docstrings.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,34 @@ It's recommended to always use `"""strings like this"""` for docstrings,
121121
even if the docstring is only one line long. This way it's easy to add
122122
more stuff to it later.
123123

124-
## Popular Docstrings Format
124+
## Popular Docstring Formats
125125

126-
There might be different documentation strings available. You need not need to worry about the fact that you have to reinvent the wheel to study all. The formats of all the Documentation strings are nearly similar. The patterns are similar, but there are only nitty-gritty changes in each format.
126+
There are different styles for writing docstrings. If you are contributing to
127+
another Python project, make sure to use the same style as rest of that project
128+
is using.
127129

128-
##### 1) Sphinx Style :
130+
If you are starting a new project, then you can use whichever style you
131+
want, but don't "reinventing the wheel"; use an existing style instead instead of
132+
making up your own. Here are some examples of popular docstring styles to choose
133+
from:
129134

130-
Sphinx is the easy and traditional style, verbose and was initially created specifically for the Python Documentation. Sphinx uses a reStructuredText which is similar in usage to Markdown.
135+
### Sphinx Style
136+
137+
[Sphinx](https://www.sphinx-doc.org/en/master/) is the Python documentation tool
138+
that [the official Python documentation](https://docs.python.org/3/) uses.
139+
By default, sphinx expects you to write docstrings like this:
131140

132141
```python
133142
class Vehicle(object):
134143
'''
135-
The Vehicle object contains lots of vehicles
144+
The Vehicle object contains lots of vehicles.
136145
:param arg: The arg is used for ...
137146
:type arg: str
138-
:param `*args`: The variable arguments are used for ...
139-
:param `**kwargs`: The keyword arguments are used for ...
140147
:ivar arg: This is where we store arg
141148
:vartype arg: str
142149
'''
143150

144-
145-
def __init__(self, arg, *args, **kwargs):
151+
def __init__(self, arg):
146152
self.arg = arg
147153

148154
def cars(self, distance, destination):
@@ -156,12 +162,14 @@ class Vehicle(object):
156162
:returns: A Car mileage
157163
:rtype: Cars
158164
'''
159-
pass
160-
165+
...
161166
```
162167

163-
##### 2) Google Style :
164-
Google Style is easier and more intuitive to use. It can be used for the shorter form of documentation. A configuration of python file needs to be done to get started, so you need to add either sphinx.ext.napoleon or sphinxcontrib.napoleon to the extensions list in conf.py.
168+
### Google Style
169+
170+
Google Style is meant to be easier to read and use without a tool like sphinx.
171+
Sphinx can be configured to use that with
172+
[sphinx.ext.napoleon](https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html).
165173

166174
```python
167175
class Vehicles(object):
@@ -170,17 +178,15 @@ class Vehicles(object):
170178
171179
Args:
172180
arg (str): The arg is used for...
173-
*args: The variable arguments are used for...
174-
**kwargs: The keyword arguments are used for...
175181
176182
Attributes:
177183
arg (str): This is where we store arg,
178184
'''
179185

180-
def __init__(self, arg, *args, **kwargs):
186+
def __init__(self, arg):
181187
self.arg = arg
182188

183-
def cars(self, distance,destination):
189+
def cars(self, distance, destination):
184190
'''We can't travel distance in vehicles without fuels, so here is the fuels
185191
186192
Args:
@@ -193,13 +199,16 @@ class Vehicles(object):
193199
Returns:
194200
cars: A car mileage
195201
'''
196-
pass
202+
...
197203

198204
```
199205

200-
##### 3) Numpy Style :
206+
### Numpy Style
201207

202-
Numpy style has a lot of details in the documentation. It is more verbose than other documentation, but it is an excellent choice if you want to do detailed documentation, i.e., extensive documentation of all the functions and parameters.
208+
[Numpy](https://numpy.org/) is a large and popular Python library,
209+
and numpy developers have their own docstring style.
210+
It is an excellent choice if you want to do detailed documentation,
211+
i.e., extensive documentation of all the functions and parameters.
203212

204213
```python
205214
class Vehicles(object):
@@ -221,7 +230,7 @@ class Vehicles(object):
221230
This is where we store arg,
222231
'''
223232

224-
def __init__(self, arg, *args, **kwargs):
233+
def __init__(self, arg):
225234
self.arg = arg
226235

227236
def cars(self, distance, destination):

0 commit comments

Comments
 (0)