From 18fd4efca247c09e88809b20649b348c8379f78f Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 12 Feb 2018 22:44:16 +0900 Subject: [PATCH] Fix #4260: autodoc: keyword only argument separator is not disappeared --- CHANGES | 3 +++ sphinx/util/inspect.py | 3 ++- tests/conftest.py | 3 +++ tests/py3/test_util_inspect_py3.py | 26 ++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/py3/test_util_inspect_py3.py diff --git a/CHANGES b/CHANGES index d800bda4d74..eabe1f2f7c5 100644 --- a/CHANGES +++ b/CHANGES @@ -60,6 +60,9 @@ Features added Bugs fixed ---------- +* #4260: autodoc: keyword only argument separator is not disappeared if it is + appeared at top of the argument list + Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index b0c79ac37d7..07e453b632f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -390,7 +390,8 @@ def format_args(self): # insert '*' between POSITIONAL args and KEYWORD_ONLY args:: # func(a, b, *, c, d): if param.kind == param.KEYWORD_ONLY and last_kind in (param.POSITIONAL_OR_KEYWORD, - param.POSITIONAL_ONLY): + param.POSITIONAL_ONLY, + None): args.append('*') if param.kind in (param.POSITIONAL_ONLY, diff --git a/tests/conftest.py b/tests/conftest.py index 9fb06edab7a..67560d009d3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,9 @@ collect_ignore = ['roots'] # Disable Python version-specific +if sys.version_info < (3,): + collect_ignore += ['py3'] + if sys.version_info < (3, 5): collect_ignore += ['py35'] diff --git a/tests/py3/test_util_inspect_py3.py b/tests/py3/test_util_inspect_py3.py new file mode 100644 index 00000000000..6d02025f9a8 --- /dev/null +++ b/tests/py3/test_util_inspect_py3.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +""" + py3/test_util_inspect + ~~~~~~~~~~~~~~~~~~~~~ + + Tests util.inspect functions. + + :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from sphinx.util import inspect + + +def test_Signature_keyword_only_arguments(): + def func1(arg1, arg2, *, arg3=None, arg4=None): + pass + + def func2(*, arg3, arg4): + pass + + sig = inspect.Signature(func1).format_args() + assert sig == '(arg1, arg2, *, arg3=None, arg4=None)' + + sig = inspect.Signature(func2).format_args() + assert sig == '(*, arg3, arg4)'