From 6aeee375067483337b5cfda98233d4fb1a1addb1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 27 Jan 2022 18:06:36 +0000 Subject: [PATCH] Handle iterables of iterables as default values Signed-off-by: Stephen Finucane Closes: #91 --- sphinx_click/ext.py | 2 +- tests/test_formatter.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sphinx_click/ext.py b/sphinx_click/ext.py index b49b839..be645ab 100644 --- a/sphinx_click/ext.py +++ b/sphinx_click/ext.py @@ -83,7 +83,7 @@ def _write_opts(opts): extras.append( ':default: %s' % ( - ', '.join('%s' % d for d in opt.default) + ', '.join(str(d) for d in opt.default) if isinstance(opt.default, (list, tuple)) else opt.default, ) diff --git a/tests/test_formatter.py b/tests/test_formatter.py index c5937da..3a959d9 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -169,6 +169,14 @@ def test_defaults(self): default=lambda: None, show_default='Something computed at runtime', ) + @click.option( + '--group', + default=[('foo', 'bar')], + nargs=2, + type=click.Tuple([str, str]), + multiple=True, + show_default=True, + ) def foobar(bar): """A sample command.""" pass @@ -195,6 +203,10 @@ def foobar(bar): .. option:: --param :default: Something computed at runtime + + .. option:: --group + + :default: ('foo', 'bar') """ ).lstrip(), '\n'.join(output),