Skip to content
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

non-functional :func: and :class: references with identical section name #246

Open
rdzman opened this issue Mar 19, 2024 · 4 comments
Open

Comments

@rdzman
Copy link
Contributor

rdzman commented Mar 19, 2024

I have stumbled across a very strange bug with certain :func: and :class: references not working. That is, references like ...

:func:`myfunction`
:class:`myclass`

... will display correctly, but will not render as a functioning link under certain circumstances ... which I think I have finally tracked down to something helpful. The following conditions must hold ...

  1. The name of the class or function must be a single word without underscores.
  2. It must not belong to a package (e.g. mypackage+).
  3. The module name must be . OR you must have matlab_short_links = True.
  4. You must have a section title in the .rst source with the same name as the function or class. I believe this must be in the same .rst file as the corresponding .. autofunction:: or .. autoclass::.

For me, the last two are always satisfied, since I use matlab_short_links = True and I document all of my functions/classes with an .rst stub file that looks something like ...

.. currentmodule:: mymodule

myfunction
----------

.. autofunction:: myfunction

That section title here is critical for my table of contents. It took me a long time to encounter this issue since almost all of my functions/classes are either (1) in a package, or (2) have an underscore in the name.

While I do not have a fix for this issue, I did notice that the conditional in ...

if fullname_out not in self.state.document.ids:

... evaluates to false for a name without an underscore and to true for a name with an underscore, since the corresponding section name in self.state.document.ids has dashes instead of underscores.

I have a hunch that this may be related to #243, in which case my "fix" in #245 probably isn't the right one.

@rdzman
Copy link
Contributor Author

rdzman commented Mar 19, 2024

Here's a minimal working example ...

matlabdomain-bug-246.zip

@rdzman
Copy link
Contributor Author

rdzman commented Mar 19, 2024

Upon further experimentation, it seems that completely deleting the following lines of code ...

if self.env.config.matlab_short_links:
# modname is only used for package names
# - "target.+package" => "package"
# - "target" => ""
parts = modname.split(".")
parts = [part for part in parts if part.startswith("+")]
modname = ".".join(parts)

... solves #243 and it solves this issue for the case where you have matlab_short_links = True (the case that really matters to me), but not the case where the module name is . (as in the case attached above).

I think the only effect of this change is that it will always use the fully qualified name instead of the short name for the HTML anchor tags. Is there any other effect? And if so, wouldn't this be a good idea?

@rdzman
Copy link
Contributor Author

rdzman commented May 3, 2024

For clarification, deleting the code in my previous comment is not the right solution. It causes lots of other issues. And nothing in #245 addresses it.

So this issue is still awaiting a solution.

@joeced
Copy link
Collaborator

joeced commented May 8, 2024

Thanks for the update. I'll try to get time to look at the issue more in depth. However, time is limited at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants