mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #7156: autodoc: separator for keyword only arguments is not shown
This commit is contained in:
parent
67abd960ed
commit
cd8f3a78d9
1
CHANGES
1
CHANGES
@ -18,6 +18,7 @@ Bugs fixed
|
|||||||
|
|
||||||
* #7138: autodoc: ``autodoc.typehints`` crashed when variable has unbound object
|
* #7138: autodoc: ``autodoc.typehints`` crashed when variable has unbound object
|
||||||
as a value
|
as a value
|
||||||
|
* #7156: autodoc: separator for keyword only arguments is not shown
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -387,9 +387,9 @@ def stringify_signature(sig: inspect.Signature, show_annotation: bool = True,
|
|||||||
if param.kind != param.POSITIONAL_ONLY and last_kind == param.POSITIONAL_ONLY:
|
if param.kind != param.POSITIONAL_ONLY and last_kind == param.POSITIONAL_ONLY:
|
||||||
# PEP-570: Separator for Positional Only Parameter: /
|
# PEP-570: Separator for Positional Only Parameter: /
|
||||||
args.append('/')
|
args.append('/')
|
||||||
elif param.kind == param.KEYWORD_ONLY and last_kind in (param.POSITIONAL_OR_KEYWORD,
|
if param.kind == param.KEYWORD_ONLY and last_kind in (param.POSITIONAL_OR_KEYWORD,
|
||||||
param.POSITIONAL_ONLY,
|
param.POSITIONAL_ONLY,
|
||||||
None):
|
None):
|
||||||
# PEP-3102: Separator for Keyword Only Parameter: *
|
# PEP-3102: Separator for Keyword Only Parameter: *
|
||||||
args.append('*')
|
args.append('*')
|
||||||
|
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
def foo(a, b, /, c, d):
|
def foo(*, a, b):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def bar(a, b, /):
|
def bar(a, b, /, c, d):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def baz(a, /, *, b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def qux(a, b, /):
|
||||||
pass
|
pass
|
||||||
|
@ -298,14 +298,21 @@ def test_signature_annotations():
|
|||||||
@pytest.mark.skipif(sys.version_info < (3, 8), reason='python 3.8+ is required.')
|
@pytest.mark.skipif(sys.version_info < (3, 8), reason='python 3.8+ is required.')
|
||||||
@pytest.mark.sphinx(testroot='ext-autodoc')
|
@pytest.mark.sphinx(testroot='ext-autodoc')
|
||||||
def test_signature_annotations_py38(app):
|
def test_signature_annotations_py38(app):
|
||||||
from target.pep570 import foo, bar
|
from target.pep570 import foo, bar, baz, qux
|
||||||
|
|
||||||
|
# case: separator at head
|
||||||
|
sig = inspect.signature(foo)
|
||||||
|
assert stringify_signature(sig) == '(*, a, b)'
|
||||||
|
|
||||||
# case: separator in the middle
|
# case: separator in the middle
|
||||||
sig = inspect.signature(foo)
|
sig = inspect.signature(bar)
|
||||||
assert stringify_signature(sig) == '(a, b, /, c, d)'
|
assert stringify_signature(sig) == '(a, b, /, c, d)'
|
||||||
|
|
||||||
|
sig = inspect.signature(baz)
|
||||||
|
assert stringify_signature(sig) == '(a, /, *, b)'
|
||||||
|
|
||||||
# case: separator at tail
|
# case: separator at tail
|
||||||
sig = inspect.signature(bar)
|
sig = inspect.signature(qux)
|
||||||
assert stringify_signature(sig) == '(a, b, /)'
|
assert stringify_signature(sig) == '(a, b, /)'
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user