mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #5431: autodoc: `autofunction
` emits a warning for callable objects
This commit is contained in:
parent
914d93a9e1
commit
5c3a0e4e40
1
CHANGES
1
CHANGES
@ -20,6 +20,7 @@ Bugs fixed
|
|||||||
* #5421: autodoc emits deprecation warning for :confval:`autodoc_default_flags`
|
* #5421: autodoc emits deprecation warning for :confval:`autodoc_default_flags`
|
||||||
* #5422: lambda object causes PicklingError on storing environment
|
* #5422: lambda object causes PicklingError on storing environment
|
||||||
* #5417: Sphinx fails to build with syntax error in Python 2.7.5
|
* #5417: Sphinx fails to build with syntax error in Python 2.7.5
|
||||||
|
* #5431: autodoc: ``autofunction`` emits a warning for callable objects
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -1055,7 +1055,13 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
|
|||||||
# cannot introspect arguments of a C function or method
|
# cannot introspect arguments of a C function or method
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
args = Signature(self.object).format_args()
|
if (not isfunction(self.object) and
|
||||||
|
not isbuiltin(self.object) and
|
||||||
|
not inspect.isclass(self.object) and
|
||||||
|
hasattr(self.object, '__call__')):
|
||||||
|
args = Signature(self.object.__call__).format_args()
|
||||||
|
else:
|
||||||
|
args = Signature(self.object).format_args()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
if (is_builtin_class_method(self.object, '__new__') and
|
if (is_builtin_class_method(self.object, '__new__') and
|
||||||
is_builtin_class_method(self.object, '__init__')):
|
is_builtin_class_method(self.object, '__init__')):
|
||||||
|
8
tests/roots/test-ext-autodoc/target/callable.py
Normal file
8
tests/roots/test-ext-autodoc/target/callable.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Callable():
|
||||||
|
"""A callable object that behaves like a function."""
|
||||||
|
|
||||||
|
def __call__(self, arg1, arg2, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
function = Callable()
|
@ -1341,6 +1341,19 @@ def test_descriptor_class(app):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
|
def test_autofunction_for_callable(app):
|
||||||
|
actual = do_autodoc(app, 'function', 'target.callable.function')
|
||||||
|
assert list(actual) == [
|
||||||
|
'',
|
||||||
|
'.. py:function:: function(arg1, arg2, **kwargs)',
|
||||||
|
' :module: target.callable',
|
||||||
|
'',
|
||||||
|
' A callable object that behaves like a function.',
|
||||||
|
' '
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='root')
|
@pytest.mark.sphinx('html', testroot='root')
|
||||||
def test_mocked_module_imports(app):
|
def test_mocked_module_imports(app):
|
||||||
options = {"members": 'TestAutodoc,decoratedFunction'}
|
options = {"members": 'TestAutodoc,decoratedFunction'}
|
||||||
|
Loading…
Reference in New Issue
Block a user