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

:attr: and :meth: links require class name #184

Open
rdzman opened this issue May 5, 2023 · 6 comments
Open

:attr: and :meth: links require class name #184

rdzman opened this issue May 5, 2023 · 6 comments

Comments

@rdzman
Copy link
Contributor

rdzman commented May 5, 2023

Given a class MyClass with a method my_method(), it does not seem possible to create a link to the method with just the method name (e.g. using :meth:`my_method` ). Rather it requires including the class name as well to get the link (e.g. :meth:`MyClass.my_method` ), but then the class name is also displayed as the link text. Likewise for properties when using :attr:.

This does not appear to be the case with Python autodoc, based on on-line examples of what I assume is documentation generated using Sphinx autodoc. An example would be the data_version link in the 3rd paragraph of the Sphinx Domain API. The source says :attr:`data_version` , but the link points to sphinx.domains.Domain.data_version as one would expect.

It would be nice if it worked this way for matlabdomain as well.

Not sure if this is a bug report or a feature request ... but hopefully it's not too hard to fix.

@joeced
Copy link
Collaborator

joeced commented May 6, 2023

I wasn't aware of this feature of the Python domain! That would make things so much easier for making auto-links in docstrings akin to how MATLAB does it.

Given

classdef myClass
    % myClass   Summary of myClass
    % This is the first line of the description of myClass.
    % Descriptions can include multiple lines of text.
    %
    % myClass Properties:
    %    a - Description of a
    %    b - Description of b
    %
    % myClass Methods:
    %    doThis - Description of doThis
    %    doThat - Description of doThat

    properties
        a
        b
    end
    
    methods
        function obj = myClass
        end
        function doThis(obj)
        end
        function doThat(obj)
        end
    end
    
end

We could then just replace the property and method names with

classdef myClass
    % myClass   Summary of myClass
    % This is the first line of the description of myClass.
    % Descriptions can include multiple lines of text.
    %
    % myClass Properties:
    %    :attr:`a` - Description of a
    %    :attr:`b` - Description of b
    %
    % myClass Methods:
    %    :meth:`doThis` - Description of doThis
    %    :meth:`doThat` - Description of doThat

...
    
end

@rdzman
Copy link
Contributor Author

rdzman commented May 12, 2023

Exactly!

@joeced
Copy link
Collaborator

joeced commented May 13, 2023

Definitely on the things to work on next.

@rdzman
Copy link
Contributor Author

rdzman commented Jul 18, 2023

Ran into this one again.

With auto-linking turned on I have a workaround for methods, as mymethod() gets automatically converted into :meth:`mymethod() <myclass.mymethod>` .

But for properties, I still don't have a workaround. I could use code similar to the auto-linking code to modify the docstring directly to replace :attr:`myproperty` with :attr:`myproperty <myclass.myproperty>` , but that feels like a hack.

@joeced, have you made any progress on this? Or do you have any thoughts?

@joeced
Copy link
Collaborator

joeced commented Jul 19, 2023

No progress yet. I'll try to work on it in the coming week.

@rdzman
Copy link
Contributor Author

rdzman commented Feb 21, 2024

Just wanted to add a quick note here while I'm thinking about it, since I ran into this issue again.

It should be possible to link to the proper method or attribute from any docstring in the class. That is, from a method docstring or property/attribute docstring, not just the class docstring itself. This should be included in the tests for this functionality when implemented.

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