Skip to content

Commit

Permalink
Merge pull request #10285 from jmp1985/master
Browse files Browse the repository at this point in the history
Fixed singledispatch documentation
  • Loading branch information
tk0miya committed Apr 4, 2022
2 parents bf01079 + 3d2c54e commit f5b3804
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 29 deletions.
8 changes: 4 additions & 4 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -1403,8 +1403,8 @@ def dummy():
except (AttributeError, TypeError):
# failed to update signature (ex. built-in or extension types)
return None
else:
return None

return func


class DecoratorDocumenter(FunctionDocumenter):
Expand Down Expand Up @@ -2299,8 +2299,8 @@ def dummy():
except (AttributeError, TypeError):
# failed to update signature (ex. built-in or extension types)
return None
else:
return None

return func

def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
if self._new_docstrings is not None:
Expand Down
8 changes: 8 additions & 0 deletions tests/roots/test-ext-autodoc/target/singledispatch.py
Expand Up @@ -26,3 +26,11 @@ def _func_int(arg, kwarg=None):
def _func_str(arg, kwarg=None):
"""A function for str."""
pass


@func.register
def _func_dict(arg: dict, kwarg=None):
"""A function for dict."""
# This function tests for specifying type through annotations
pass

6 changes: 6 additions & 0 deletions tests/roots/test-ext-autodoc/target/singledispatchmethod.py
Expand Up @@ -19,3 +19,9 @@ def _meth_int(self, arg, kwarg=None):
def _meth_str(self, arg, kwarg=None):
"""A method for str."""
pass

@meth.register
def _meth_dict(self, arg: dict, kwarg=None):
"""A method for dict."""
# This function tests for specifying type through annotations
pass
47 changes: 33 additions & 14 deletions tests/test_ext_autodoc.py
Expand Up @@ -2064,20 +2064,37 @@ def test_autodoc_for_egged_code(app):
def test_singledispatch(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.singledispatch', options)
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)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
if sys.version_info < (3, 7):
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)',
' :module: target.singledispatch',
'',
' 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),
Expand All @@ -2101,6 +2118,7 @@ def test_singledispatchmethod(app):
' Foo.meth(arg: float, kwarg=None)',
' Foo.meth(arg: int, kwarg=None)',
' Foo.meth(arg: str, kwarg=None)',
' Foo.meth(arg: dict, kwarg=None)',
' :module: target.singledispatchmethod',
'',
' A method for general use.',
Expand All @@ -2120,6 +2138,7 @@ def test_singledispatchmethod_automethod(app):
' Foo.meth(arg: float, kwarg=None)',
' Foo.meth(arg: int, kwarg=None)',
' Foo.meth(arg: str, kwarg=None)',
' Foo.meth(arg: dict, kwarg=None)',
' :module: target.singledispatchmethod',
'',
' A method for general use.',
Expand Down
38 changes: 27 additions & 11 deletions tests/test_ext_autodoc_autofunction.py
Expand Up @@ -4,6 +4,8 @@
source file translated by test_build.
"""

import sys

import pytest

from .test_ext_autodoc import do_autodoc
Expand Down Expand Up @@ -111,17 +113,31 @@ def test_decorated(app):
def test_singledispatch(app):
options = {}
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: float, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
if sys.version_info < (3, 7):
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: float, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' 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')
Expand Down

0 comments on commit f5b3804

Please sign in to comment.