Skip to content

Commit f73ea8a

Browse files
authored
Fix "can't link function short name if it matches module name"
* Fix "can't link function short name if it matches module name" #243. * Fix issue with autolinking of functions or classes with same name as module.
1 parent fc28175 commit f73ea8a

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

sphinxcontrib/mat_documenters.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ def auto_link_see_also(self, docstrings):
235235
o = None
236236
if o:
237237
if isinstance(o, dict):
238-
o = o["class"]
238+
if "class" in o:
239+
o = o["class"]
240+
elif "func" in o:
241+
o = o["func"]
239242
role = o.ref_role()
240243
if role in ["class", "func"]:
241244
entries[k] = f":{role}:`{entries[k]}`"
@@ -318,7 +321,10 @@ def auto_link_all(self, docstrings):
318321
# auto-link known classes and functions everywhere
319322
for n, o in entities_table.items():
320323
if isinstance(o, dict):
321-
o = o["class"]
324+
if "class" in o:
325+
o = o["class"]
326+
elif "func" in o:
327+
o = o["func"]
322328
role = o.ref_role()
323329
if role in ["class", "func"]:
324330
nn = n.replace("+", "") # remove + from name

sphinxcontrib/mat_types.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,13 @@ def isClassFolderModule(name, entity):
296296
long_names = entities_table.keys()
297297
for name, entity in entities_table.items():
298298
short_name = shortest_name(name)
299-
if short_name != name and not (short_name in long_names and name in long_names):
299+
if (
300+
short_name != name
301+
and not (short_name in long_names and name in long_names)
302+
or short_name in long_names
303+
and (entity.ref_role() == "func" or entity.ref_role() == "class")
304+
and entities_table[short_name].ref_role() == "mod"
305+
):
300306
# Only handle the below special case when overwriting entries in entities_table will not
301307
# introduce conflicts
302308
if short_name in entities_table:

sphinxcontrib/matlab.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def get_index_text(self, modname, name):
258258
def add_target_and_index(self, name_cls, sig, signode):
259259
modname = self.options.get("module", self.env.temp_data.get("mat:module"))
260260

261-
if self.env.config.matlab_short_links:
261+
if self.env.config.matlab_short_links and not name_cls[0] == modname:
262262
# modname is only used for package names
263263
# - "target.+package" => "package"
264264
# - "target" => ""

0 commit comments

Comments
 (0)