Skip to content

Commit 4fafdf7

Browse files
authored
Merge pull request #4678 from jposada202020/defining_parameters
Defining parameters
2 parents e6dc3e4 + 5fa7186 commit 4fafdf7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/design_guide.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,58 @@ Renders as:
292292
:param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to.
293293
:param int address: The I2C address of the device. Defaults to :const:`0x40`
294294

295+
296+
Documenting Parameters
297+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
298+
Although there are different ways to document class and functions definitions in Python,
299+
the following is the prevalent method of documenting parameters
300+
for CircuitPython libraries. When documenting class parameters you should use the
301+
following structure:
302+
303+
.. code-block:: sh
304+
305+
:param param_type param_name: Parameter_description
306+
307+
308+
param_type
309+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310+
The type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc.
311+
To document an object in the CircuitPython domain, you need to include a ``~`` before the
312+
definition as shown in the following example:
313+
314+
.. code-block:: sh
315+
316+
:param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to.
317+
318+
319+
To include references to CircuitPython modules, cookiecutter creates an entry in the
320+
intersphinx_mapping section in the ``conf.py`` file located within the ``docs`` directory.
321+
To add different types outside CircuitPython you need to include them in the intersphinx_mapping::
322+
323+
324+
intersphinx_mapping = {
325+
"python": ("https://docs.python.org/3.4", None),
326+
"BusDevice":("https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", None,),
327+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
328+
}
329+
330+
The intersphinx_mapping above includes references to Python, BusDevice and CircuitPython
331+
Documentation
332+
333+
334+
param_name
335+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336+
Parameter name used in the class or method definition
337+
338+
339+
Parameter_description
340+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341+
Parameter description. When the parameter defaults to a particular value, it is good
342+
practice to include the default::
343+
344+
:param int pitch: Pitch value for the servo. Defaults to :const:`4500`
345+
346+
295347
Attributes
296348
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
297349

0 commit comments

Comments
 (0)