mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #10285 from jmp1985/master
Fixed singledispatch documentation
This commit is contained in:
commit
f5b3804060
@ -1403,8 +1403,8 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
|
|||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
# failed to update signature (ex. built-in or extension types)
|
# failed to update signature (ex. built-in or extension types)
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
return None
|
return func
|
||||||
|
|
||||||
|
|
||||||
class DecoratorDocumenter(FunctionDocumenter):
|
class DecoratorDocumenter(FunctionDocumenter):
|
||||||
@ -2299,8 +2299,8 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type:
|
|||||||
except (AttributeError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
# failed to update signature (ex. built-in or extension types)
|
# failed to update signature (ex. built-in or extension types)
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
return None
|
return func
|
||||||
|
|
||||||
def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
|
def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
|
||||||
if self._new_docstrings is not None:
|
if self._new_docstrings is not None:
|
||||||
|
@ -26,3 +26,11 @@ def _func_int(arg, kwarg=None):
|
|||||||
def _func_str(arg, kwarg=None):
|
def _func_str(arg, kwarg=None):
|
||||||
"""A function for str."""
|
"""A function for str."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@func.register
|
||||||
|
def _func_dict(arg: dict, kwarg=None):
|
||||||
|
"""A function for dict."""
|
||||||
|
# This function tests for specifying type through annotations
|
||||||
|
pass
|
||||||
|
|
||||||
|
@ -19,3 +19,9 @@ class Foo:
|
|||||||
def _meth_str(self, arg, kwarg=None):
|
def _meth_str(self, arg, kwarg=None):
|
||||||
"""A method for str."""
|
"""A method for str."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@meth.register
|
||||||
|
def _meth_dict(self, arg: dict, kwarg=None):
|
||||||
|
"""A method for dict."""
|
||||||
|
# This function tests for specifying type through annotations
|
||||||
|
pass
|
||||||
|
@ -2064,20 +2064,37 @@ def test_autodoc_for_egged_code(app):
|
|||||||
def test_singledispatch(app):
|
def test_singledispatch(app):
|
||||||
options = {"members": None}
|
options = {"members": None}
|
||||||
actual = do_autodoc(app, 'module', 'target.singledispatch', options)
|
actual = do_autodoc(app, 'module', 'target.singledispatch', options)
|
||||||
assert list(actual) == [
|
if sys.version_info < (3, 7):
|
||||||
'',
|
assert list(actual) == [
|
||||||
'.. py:module:: target.singledispatch',
|
'',
|
||||||
'',
|
'.. py:module:: target.singledispatch',
|
||||||
'',
|
'',
|
||||||
'.. py:function:: func(arg, kwarg=None)',
|
'',
|
||||||
' func(arg: float, kwarg=None)',
|
'.. py:function:: func(arg, kwarg=None)',
|
||||||
' func(arg: int, kwarg=None)',
|
' func(arg: float, kwarg=None)',
|
||||||
' func(arg: str, kwarg=None)',
|
' func(arg: int, kwarg=None)',
|
||||||
' :module: target.singledispatch',
|
' func(arg: str, kwarg=None)',
|
||||||
'',
|
' :module: target.singledispatch',
|
||||||
' A function for general use.',
|
'',
|
||||||
'',
|
' A function for general use.',
|
||||||
]
|
'',
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
assert list(actual) == [
|
||||||
|
'',
|
||||||
|
'.. py:module:: target.singledispatch',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'.. py:function:: func(arg, kwarg=None)',
|
||||||
|
' func(arg: float, kwarg=None)',
|
||||||
|
' func(arg: int, kwarg=None)',
|
||||||
|
' func(arg: str, kwarg=None)',
|
||||||
|
' func(arg: dict, kwarg=None)',
|
||||||
|
' :module: target.singledispatch',
|
||||||
|
'',
|
||||||
|
' A function for general use.',
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 8),
|
@pytest.mark.skipif(sys.version_info < (3, 8),
|
||||||
@ -2101,6 +2118,7 @@ def test_singledispatchmethod(app):
|
|||||||
' Foo.meth(arg: float, kwarg=None)',
|
' Foo.meth(arg: float, kwarg=None)',
|
||||||
' Foo.meth(arg: int, kwarg=None)',
|
' Foo.meth(arg: int, kwarg=None)',
|
||||||
' Foo.meth(arg: str, kwarg=None)',
|
' Foo.meth(arg: str, kwarg=None)',
|
||||||
|
' Foo.meth(arg: dict, kwarg=None)',
|
||||||
' :module: target.singledispatchmethod',
|
' :module: target.singledispatchmethod',
|
||||||
'',
|
'',
|
||||||
' A method for general use.',
|
' A method for general use.',
|
||||||
@ -2120,6 +2138,7 @@ def test_singledispatchmethod_automethod(app):
|
|||||||
' Foo.meth(arg: float, kwarg=None)',
|
' Foo.meth(arg: float, kwarg=None)',
|
||||||
' Foo.meth(arg: int, kwarg=None)',
|
' Foo.meth(arg: int, kwarg=None)',
|
||||||
' Foo.meth(arg: str, kwarg=None)',
|
' Foo.meth(arg: str, kwarg=None)',
|
||||||
|
' Foo.meth(arg: dict, kwarg=None)',
|
||||||
' :module: target.singledispatchmethod',
|
' :module: target.singledispatchmethod',
|
||||||
'',
|
'',
|
||||||
' A method for general use.',
|
' A method for general use.',
|
||||||
|
@ -4,6 +4,8 @@ This tests mainly the Documenters; the auto directives are tested in a test
|
|||||||
source file translated by test_build.
|
source file translated by test_build.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .test_ext_autodoc import do_autodoc
|
from .test_ext_autodoc import do_autodoc
|
||||||
@ -111,17 +113,31 @@ def test_decorated(app):
|
|||||||
def test_singledispatch(app):
|
def test_singledispatch(app):
|
||||||
options = {}
|
options = {}
|
||||||
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
|
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
|
||||||
assert list(actual) == [
|
if sys.version_info < (3, 7):
|
||||||
'',
|
assert list(actual) == [
|
||||||
'.. py:function:: func(arg, kwarg=None)',
|
'',
|
||||||
' func(arg: float, kwarg=None)',
|
'.. py:function:: func(arg, kwarg=None)',
|
||||||
' func(arg: int, kwarg=None)',
|
' func(arg: float, kwarg=None)',
|
||||||
' func(arg: str, kwarg=None)',
|
' func(arg: int, kwarg=None)',
|
||||||
' :module: target.singledispatch',
|
' func(arg: str, kwarg=None)',
|
||||||
'',
|
' :module: target.singledispatch',
|
||||||
' A function for general use.',
|
'',
|
||||||
'',
|
' A function for general use.',
|
||||||
]
|
'',
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
assert list(actual) == [
|
||||||
|
'',
|
||||||
|
'.. py:function:: func(arg, kwarg=None)',
|
||||||
|
' func(arg: float, kwarg=None)',
|
||||||
|
' func(arg: int, kwarg=None)',
|
||||||
|
' func(arg: str, kwarg=None)',
|
||||||
|
' func(arg: dict, kwarg=None)',
|
||||||
|
' :module: target.singledispatch',
|
||||||
|
'',
|
||||||
|
' A function for general use.',
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
|
Loading…
Reference in New Issue
Block a user