From 700be75a73b17bf07fd32c295fdd127e3bd2275c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 23 Mar 2019 22:32:37 +0900 Subject: [PATCH] Fix #6196: py domain: unexpected prefix is generated --- CHANGES | 2 ++ sphinx/domains/python.py | 3 ++- tests/test_domain_py.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 717517e70..a7f2db423 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #6196: py domain: unexpected prefix is generated + Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 6c4030a6c..73d6d2c11 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -262,7 +262,8 @@ class PyObject(ObjectDescription): classname = self.env.ref_context.get('py:class') if classname: add_module = False - if name_prefix and name_prefix.startswith(classname): + if name_prefix and (name_prefix == classname or + name_prefix.startswith(classname + ".")): fullname = name_prefix + name # class name is given again in the signature name_prefix = name_prefix[len(classname):].lstrip('.') diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 87c310982..fb6e70914 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -273,3 +273,20 @@ def test_pydata_signature(app): desc_content)])) assert_node(doctree[1], addnodes.desc, desctype="data", domain="py", objtype="data", noindex=False) + + +def test_pyobject_prefix(app): + text = (".. py:class:: Foo\n" + "\n" + " .. py:method:: Foo.say\n" + " .. py:method:: FooBar.say") + doctree = restructuredtext.parse(app, text) + assert_node(doctree, (addnodes.index, + [desc, ([desc_signature, ([desc_annotation, "class "], + [desc_name, "Foo"])], + [desc_content, (addnodes.index, + desc, + addnodes.index, + desc)])])) + assert doctree[1][1][1].astext().strip() == 'say' # prefix is stripped + assert doctree[1][1][3].astext().strip() == 'FooBar.say' # not stripped