Skip to content

Document abstract methods #222

@shanemcq18

Description

@shanemcq18

Abstract methods – which have a signature but not a body – are currently not documented. It would be nice to be able to document them though, since they exist to define an interface for users to extend ("if you inherit from this class, you must write a function that...<precise explanation that should live in a docstring>").

The trouble is that these methods are special cases lexically because they aren't bookended by function and end. Here's an example.

classdef My_Class < handle
    % Docstring for the class.

    methods (Abstract)

        % How can we document this method?
        val = abstractmethod1(arg)
            % Perhaps a docstring here?

        % This is also not documented.
        [val1, val2] = abstractmethod2(arg1, arg2)

    end

    methods

        function [out] = publicmethod(arg)
            % This is documented.
            out = 2 * arg;
        end

    end
end

Now with this RST block somewhere,

.. autoclass:: My_Class
   :show-inheritance:
   :members:
   :undoc-members:

we get documentation for publicmethod() but not abstractmethod1() or abstractmethod2().

Screenshot 2023-11-15 at 4 04 06 PM

This was discussed a little way back in #28. Is this something that can be added without too much trouble? Adding function and end is not allowed for abstract methods, so it would have to be handled as a special case. It seems pretty natural to allow docstrings with this style:

[val1, val2] = abstractmethod2(arg1, arg2)
% This is the docstring.
%
% It may or may not continues for multiple lines.
% But watch out! It won't be followed by an ``end`` statement!

Thanks for writing this extension, it's a huge help for our project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions