mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Updated Docstring Guidelines (markdown)
@ -261,3 +261,62 @@ The following resources provide additional information and examples on how to wr
|
||||
* [Autodoc](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html): A Sphinx extension that automatically extracts documentation from your Python modules.
|
||||
* [Google Style Python Docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html): Examples and guidelines for writing Python docstrings in Google style.
|
||||
* [reStructuredText Primer](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html): A guide to the markup syntax used by Sphinx and autosummary.
|
||||
|
||||
## reSTructuredText vs Markdown
|
||||
|
||||
You can write your documentation files in .rst or MyST Markdown.
|
||||
See [MyST Markdown documentation](https://myst-parser.readthedocs.io/en/v0.15.1/sphinx/use.html) for detailed instructions.
|
||||
|
||||
Below is a quick reference of how to use MyST Markdown.
|
||||
|
||||
### Python References
|
||||
|
||||
| reSTructuredText| Purpose | MyST Markdown |
|
||||
|-----------|---------|---------|
|
||||
| `:py:class:` | Reference a class | `{py:class}`MyClass`` |
|
||||
| `:py:func:` | Reference a function | `{py:func}`my_module.my_function`` |
|
||||
| `:py:meth:` | Reference a method | `{py:meth}`MyClass.my_method`` |
|
||||
| `:py:mod:` | Reference a module | `{py:mod}`my_module`` |
|
||||
| `:py:attr:` | Reference an attribute | `{py:attr}`MyClass.my_attribute`` |
|
||||
| `:py:data:` | Reference a data attribute or value | `{py:data}`MY_CONSTANT`` |
|
||||
| `:py:exc:` | Reference an exception | `{py:exc}`MyException`` |
|
||||
| `:py:obj:` | Reference any Python object | `{py:obj}`my_module.MyClass.my_function`` |
|
||||
|
||||
### Auto-Documentation Directives
|
||||
|
||||
Autodoc and autosummary directives should be wrapped in the `{eval-rst}` directive.
|
||||
For example, this in .rst:
|
||||
|
||||

|
||||
|
||||
would become this in MyST Markdown:
|
||||
|
||||

|
||||
|
||||
This applies to all following directives:
|
||||
|
||||
* `.. autoclass::`
|
||||
* `.. autofunction::`
|
||||
* `.. automethod::`
|
||||
* `.. autoattribute::`
|
||||
* `.. autodata::`
|
||||
* `.. autoexception::`
|
||||
* `.. autoproperty::`
|
||||
* `.. autosummary::`
|
||||
|
||||
### Document References
|
||||
|
||||
| reSTructuredText| Purpose | MyST Markdown |
|
||||
|-----------|---------|---------|
|
||||
| `:doc:` | Reference another document | `{doc}`path/to/document`` |
|
||||
| `:ref:` | Reference a labeled section or target | `{ref}`section-label`` |
|
||||
| `:title:` | Reference a document's title | `{title}`Page Title`` |
|
||||
| `:numref:` | Reference numbered items (e.g., figures) | `{numref}`figure-label`` |
|
||||
|
||||
### C++ References
|
||||
|
||||
| reSTructuredText| Purpose | MyST Markdown |
|
||||
|-----------|---------|---------|
|
||||
| `:cpp:class:` | Reference a C++ class | `{cpp:class}`MyCppClass`` |
|
||||
| `:cpp:func:` | Reference a C++ function | `{cpp:func}`my_function`` |
|
||||
|
||||
|
Reference in New Issue
Block a user