Skip to content

Commit

Permalink
Close sphinx-doc#9664: autodoc: autodoc-process-bases supports reST s…
Browse files Browse the repository at this point in the history
…nippet

This allows to inject a reST snippet through autodoc-process-bases
event.  It helps to modify the base classes of any class to the expected
mark-up'ed text by custom extension.
  • Loading branch information
tk0miya committed Sep 23, 2021
1 parent f1a4eef commit 01b6db7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -14,6 +14,8 @@ Features added
--------------

* #9639: autodoc: Support asynchronous generator functions
* #9664: autodoc: ``autodoc-process-bases`` supports to inject reST snippet as a
base class

Bugs fixed
----------
Expand Down
8 changes: 6 additions & 2 deletions doc/usage/extensions/autodoc.rst
Expand Up @@ -768,8 +768,6 @@ needed docstring processing in event :event:`autodoc-process-docstring`:

.. event:: autodoc-process-bases (app, name, obj, options, bases)

.. versionadded:: 4.1

Emitted when autodoc has read and processed a class to determine the
base-classes. *bases* is a list of classes that the event handler can
modify **in place** to change what Sphinx puts into the output. It's
Expand All @@ -781,6 +779,12 @@ needed docstring processing in event :event:`autodoc-process-docstring`:
:param options: the options given to the class directive
:param bases: the list of base classes signature. see above.

.. versionadded:: 4.1
.. versionchanged:: 4.3

``bases`` can contain a string as a base class name. It will be processed
as reST mark-up'ed text.


Skipping members
----------------
Expand Down
2 changes: 2 additions & 0 deletions sphinx/util/typing.py
Expand Up @@ -113,6 +113,8 @@ def restify(cls: Optional[Type]) -> str:
return ':py:obj:`None`'
elif cls is Ellipsis:
return '...'
elif isinstance(cls, str):
return cls
elif cls in INVALID_BUILTIN_CLASSES:
return ':py:class:`%s`' % INVALID_BUILTIN_CLASSES[cls]
elif inspect.isNewType(cls):
Expand Down
1 change: 1 addition & 0 deletions tests/test_util_typing.py
Expand Up @@ -48,6 +48,7 @@ def test_restify():
assert restify(Struct) == ":py:class:`struct.Struct`"
assert restify(TracebackType) == ":py:class:`types.TracebackType`"
assert restify(Any) == ":py:obj:`~typing.Any`"
assert restify('str') == "str"


def test_restify_type_hints_containers():
Expand Down

0 comments on commit 01b6db7

Please sign in to comment.