|
4 | 4 | source file translated by test_build. |
5 | 5 | """ |
6 | 6 |
|
| 7 | +import inspect |
7 | 8 | import sys |
| 9 | +import typing |
8 | 10 |
|
9 | 11 | import pytest |
10 | 12 |
|
@@ -185,8 +187,22 @@ def test_automodule_inherited_members(app): |
185 | 187 | 'sphinx.missing_module4']}) |
186 | 188 | @pytest.mark.usefixtures("rollback_sysmodules") |
187 | 189 | def test_subclass_of_mocked_object(app): |
| 190 | + from sphinx.ext.autodoc.mock import _MockObject |
188 | 191 | sys.modules.pop('target', None) # unload target module to clear the module cache |
189 | 192 |
|
| 193 | + options = {'members': None} |
| 194 | + actual = do_autodoc(app, 'module', 'target.need_mocks', options) |
| 195 | + # ``typing.Any`` is not available at runtime on ``_MockObject.__new__`` |
| 196 | + assert '.. py:class:: Inherited(*args: Any, **kwargs: Any)' in actual |
| 197 | + |
| 198 | + # make ``typing.Any`` available at runtime on ``_MockObject.__new__`` |
| 199 | + sig = inspect.signature(_MockObject.__new__) |
| 200 | + parameters = sig.parameters.copy() |
| 201 | + for name in ('args', 'kwargs'): |
| 202 | + parameters[name] = parameters[name].replace(annotation=typing.Any) |
| 203 | + sig = sig.replace(parameters=tuple(parameters.values())) |
| 204 | + _MockObject.__new__.__signature__ = sig # type: ignore[attr-defined] |
| 205 | + |
190 | 206 | options = {'members': None} |
191 | 207 | actual = do_autodoc(app, 'module', 'target.need_mocks', options) |
192 | 208 | assert '.. py:class:: Inherited(*args: ~typing.Any, **kwargs: ~typing.Any)' in actual |
0 commit comments