Simple-parsing allows you to define help text for command-line arguments using three different styles. When multiple styles are used for the same attribute, the library selects the help text based on a specific priority order.
Help Text Priority Order
If an attribute has multiple documentation markers, the following order determines which one is used in the --help output:
- Docstring below: A multi-line string (
""" or ''') on the lines following the attribute. - Comment above: A single or multi-line comment (
#) on the line(s) preceding the attribute. - Inline comment: A comment on the same line as the attribute definition.
Supported Styles
- Docstring below:
attr: float = 1.0
"""Docstring below"""
- Comment above:
# Comment above
attr: float = 1.0
- Inline comment:
attr: float = 1.0 # inline comment
Note: For clarity, it is recommended to add blank lines between consecutive attribute assignments when using the 'comment above' or 'docstring below' styles, though this does not affect the --help output.
from dataclasses import dataclass
from simple_parsing import ArgumentParser
parser = ArgumentParser()
@dataclass
class DocStringsExample:
"""Class docstring appearing in the help group."""
attribute1: float = 1.0
"""docstring below, takes highest priority"""
# Comment above, takes second priority
attribute2: float = 1.0
attribute3: float = 1.0 # inline comment, takes lowest priority
parser.add_arguments(DocStringsExample, "example")
args = parser.parse_args()