From 201f61f7226c764769f1b0be4e5d1918d38ff1f2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 30 May 2021 03:16:55 +0900 Subject: [PATCH] Fix #9280: py domain: "exceptions" module is not displayed Since v0.2, python domain gives a special treatment for the exceptions module to suppress its name on documenting exception classes. It had been worthy on python2 era. But the module has been removed since python3. Therefore, the special treatment becomes harmful for user libraries. This removes it to render module names correctly. Note: Now we've only supported python3. So this is not incompatible. --- CHANGES | 1 + sphinx/domains/python.py | 9 +++------ tests/test_domain_py.py | 16 ++-------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index 886f88579..5727c7247 100644 --- a/CHANGES +++ b/CHANGES @@ -58,6 +58,7 @@ Bugs fixed * #9270: html theme : pyramid theme generates incorrect logo links * #9217: manpage: The name of manpage directory that is generated by :confval:`man_make_section_directory` is not correct +* #9280: py domain: "exceptions" module is not displayed * #9224: ``:param:`` and ``:type:`` fields does not support a type containing whitespace (ex. ``Dict[str, str]``) diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 5035ce2ab..7fb56c635 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -448,12 +448,9 @@ class PyObject(ObjectDescription[Tuple[str, str]]): if prefix: signode += addnodes.desc_addname(prefix, prefix) - elif add_module and self.env.config.add_module_names: - if modname and modname != 'exceptions': - # exceptions are a special case, since they are documented in the - # 'exceptions' module. - nodetext = modname + '.' - signode += addnodes.desc_addname(nodetext, nodetext) + elif modname and add_module and self.env.config.add_module_names: + nodetext = modname + '.' + signode += addnodes.desc_addname(nodetext, nodetext) signode += addnodes.desc_name(name, name) if arglist: diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 52ec0c2d4..e66f066d4 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -477,23 +477,11 @@ def test_optional_pyfunction_signature(app): def test_pyexception_signature(app): - text = ".. py:exception:: exceptions.IOError" - doctree = restructuredtext.parse(app, text) - assert_node(doctree, (addnodes.index, - [desc, ([desc_signature, ([desc_annotation, "exception "], - [desc_addname, "exceptions."], - [desc_name, "IOError"])], - desc_content)])) - assert_node(doctree[1], desc, desctype="exception", - domain="py", objtype="exception", noindex=False) - - -def test_exceptions_module_is_ignored(app): - text = (".. py:exception:: IOError\n" - " :module: exceptions\n") + text = ".. py:exception:: builtins.IOError" doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, [desc, ([desc_signature, ([desc_annotation, "exception "], + [desc_addname, "builtins."], [desc_name, "IOError"])], desc_content)])) assert_node(doctree[1], desc, desctype="exception",