Skip to content

Commit

Permalink
Merge pull request #6198 from tk0miya/6196_unexpected_prefix
Browse files Browse the repository at this point in the history
Fix #6196: py domain: unexpected prefix is generated
  • Loading branch information
tk0miya committed Mar 23, 2019
2 parents 8980f63 + 700be75 commit e1185ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -16,6 +16,8 @@ Features added
Bugs fixed
----------

* #6196: py domain: unexpected prefix is generated

Testing
--------

Expand Down
3 changes: 2 additions & 1 deletion sphinx/domains/python.py
Expand Up @@ -262,7 +262,8 @@ def handle_signature(self, sig, signode):
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('.')
Expand Down
17 changes: 17 additions & 0 deletions tests/test_domain_py.py
Expand Up @@ -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

0 comments on commit e1185ff

Please sign in to comment.