Fix #9781: autodoc_preserve_defaults does not support hexadecimal

This commit is contained in:
Takeshi KOMIYA
2021-10-31 00:26:03 +09:00
parent 2b5c55e45a
commit b8844eb339
4 changed files with 47 additions and 9 deletions

View File

@@ -7,7 +7,8 @@ SENTINEL = object()
def foo(name: str = CONSTANT,
sentinel: Any = SENTINEL,
now: datetime = datetime.now()) -> None:
now: datetime = datetime.now(),
color: int = 0xFFFFFF) -> None:
"""docstring"""
@@ -15,5 +16,5 @@ class Class:
"""docstring"""
def meth(self, name: str = CONSTANT, sentinel: Any = SENTINEL,
now: datetime = datetime.now()) -> None:
now: datetime = datetime.now(), color: int = 0xFFFFFF) -> None:
"""docstring"""

View File

@@ -8,6 +8,8 @@
:license: BSD, see LICENSE for details.
"""
import sys
import pytest
from .test_ext_autodoc import do_autodoc
@@ -16,6 +18,11 @@ from .test_ext_autodoc import do_autodoc
@pytest.mark.sphinx('html', testroot='ext-autodoc',
confoverrides={'autodoc_preserve_defaults': True})
def test_preserve_defaults(app):
if sys.version_info < (3, 8):
color = "16777215"
else:
color = "0xFFFFFF"
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.preserve_defaults', options)
assert list(actual) == [
@@ -30,14 +37,14 @@ def test_preserve_defaults(app):
'',
'',
' .. py:method:: Class.meth(name: str = CONSTANT, sentinel: Any = SENTINEL, '
'now: datetime.datetime = datetime.now()) -> None',
'now: datetime.datetime = datetime.now(), color: int = %s) -> None' % color,
' :module: target.preserve_defaults',
'',
' docstring',
'',
'',
'.. py:function:: foo(name: str = CONSTANT, sentinel: Any = SENTINEL, now: '
'datetime.datetime = datetime.now()) -> None',
'datetime.datetime = datetime.now(), color: int = %s) -> None' % color,
' :module: target.preserve_defaults',
'',
' docstring',