Skip to content

Fix "can't link function short name if it matches module name" #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sphinxcontrib/mat_documenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ def auto_link_see_also(self, docstrings):
o = None
if o:
if isinstance(o, dict):
o = o["class"]
if "class" in o:
o = o["class"]
elif "func" in o:
o = o["func"]
role = o.ref_role()
if role in ["class", "func"]:
entries[k] = f":{role}:`{entries[k]}`"
Expand Down Expand Up @@ -318,7 +321,10 @@ def auto_link_all(self, docstrings):
# auto-link known classes and functions everywhere
for n, o in entities_table.items():
if isinstance(o, dict):
o = o["class"]
if "class" in o:
o = o["class"]
elif "func" in o:
o = o["func"]
role = o.ref_role()
if role in ["class", "func"]:
nn = n.replace("+", "") # remove + from name
Expand Down
8 changes: 7 additions & 1 deletion sphinxcontrib/mat_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,13 @@ def isClassFolderModule(name, entity):
long_names = entities_table.keys()
for name, entity in entities_table.items():
short_name = shortest_name(name)
if short_name != name and not (short_name in long_names and name in long_names):
if (
short_name != name
and not (short_name in long_names and name in long_names)
or short_name in long_names
and (entity.ref_role() == "func" or entity.ref_role() == "class")
and entities_table[short_name].ref_role() == "mod"
):
# Only handle the below special case when overwriting entries in entities_table will not
# introduce conflicts
if short_name in entities_table:
Expand Down
2 changes: 1 addition & 1 deletion sphinxcontrib/matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def get_index_text(self, modname, name):
def add_target_and_index(self, name_cls, sig, signode):
modname = self.options.get("module", self.env.temp_data.get("mat:module"))

if self.env.config.matlab_short_links:
if self.env.config.matlab_short_links and not name_cls[0] == modname:
# modname is only used for package names
# - "target.+package" => "package"
# - "target" => ""
Expand Down
Loading