Skip to content

Commit 82b5bcd

Browse files
hoodmanestephenfin
authored andcommitted
FIX If the help of an argument is None, don't fail
This is a fix for a regression introduced in #134. It's possible that the argument has a `help` attribute, but the value of it is `None`. We then hit a type error where we pass `None` to `re.sub`.
1 parent b1a1be4 commit 82b5bcd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

sphinx_click/ext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ def _format_argument(arg: click.Argument) -> ty.Generator[str, None, None]:
218218
)
219219
)
220220
# Subclasses of click.Argument may add a `help` attribute (like typer.main.TyperArgument)
221-
if hasattr(arg, 'help'):
221+
help = getattr(arg, 'help', None)
222+
if help:
222223
yield ''
223-
help_string = ANSI_ESC_SEQ_RE.sub('', getattr(arg, 'help'))
224+
help_string = ANSI_ESC_SEQ_RE.sub('', help)
224225
for line in _format_help(help_string):
225226
yield _indent(line)
226227

tests/test_formatter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def __init__(self, *args, help=None, **kwargs):
185185
@click.command()
186186
@click.option('--option', help='A sample option')
187187
@click.argument('ARG', help='A sample argument', cls=CustomArgument)
188+
@click.argument('ARG_NO_HELP', cls=CustomArgument)
188189
def foobar(bar):
189190
"""A sample command."""
190191
pass
@@ -200,7 +201,7 @@ def foobar(bar):
200201
.. program:: foobar
201202
.. code-block:: shell
202203
203-
foobar [OPTIONS] ARG
204+
foobar [OPTIONS] ARG ARG_NO_HELP
204205
205206
.. rubric:: Options
206207
@@ -216,6 +217,10 @@ def foobar(bar):
216217
217218
A sample argument
218219
220+
221+
.. option:: ARG_NO_HELP
222+
223+
Required argument
219224
"""
220225
).lstrip(),
221226
'\n'.join(output),

0 commit comments

Comments
 (0)