autoDocstring icon indicating copy to clipboard operation
autoDocstring copied to clipboard

Class Docstring

Open jrwrigh opened this issue 7 years ago • 12 comments

Feature Request:

Is it possible to make the docstring show something different for a Class? For example, I use numpy docstring system and they have a slightly different format for class docstrings, the addition of an attributes section being the most notable.

For numpy, only public attributes should be listed, so maybe it could go through all the attributes and parse for ones without a leading _?

jrwrigh avatar Feb 15 '18 14:02 jrwrigh

It's in the works :)

NilsJPWerner avatar Feb 16 '18 05:02 NilsJPWerner

The docstring as inserted for the class is inconsistent at least. If the class has superclass:

class Pipeline(PackageAwareObjectMixin):
    """[summary]

    :param PackageAwareObjectMixin: [description]
    :type PackageAwareObjectMixin: [type]
    """

If not it's fine but:

class Something:
    """[summary]
    
    :raises ValueError: [description]
    """

    def __init__(self, a, b=None):
        raise ValueError('OMG!')

zgoda-mobica avatar Mar 20 '19 13:03 zgoda-mobica

I have a fork where I had this feature working for the previous version. I was still trying to debug some unreliable function detection when indented. It involved a modest re-write of the code parsing machinery. Is there any progress on similar features for the updated version, or should I update my fork and re-implement it against the new parsing and rendering machinery?

mobiusklein avatar Apr 22 '19 22:04 mobiusklein

I really like this idea. @NilsJPWerner is this still in development? Thanks for writing a great extension!

jss367 avatar Apr 17 '20 00:04 jss367

Interested in this as well!

aaronsmith1234 avatar Jul 23 '20 20:07 aaronsmith1234

Any update on this?

remidinishanth-ntnx avatar Aug 26 '20 15:08 remidinishanth-ntnx

Hello, Nils. I actually added class docstrings and module docstrings. It seems to be working, but I haven't been able to get the original tests running. I had never used TypeScript before (or created an extension for that matter), so I'd like to get things tested. Should I just go ahead and create a PR?

tracetidwell avatar Sep 22 '20 13:09 tracetidwell

Has this been addressed? Having trouble generating docstring for classes unless it's within the constructor. Thanks

mrajancsr avatar Oct 18 '20 20:10 mrajancsr

Is this still being developed or the idea died ?

I see this format to be nice for classes

class Person:
    """
    A class to represent a person.

    ...

    Attributes
    ----------
    name : str
        first name of the person
    surname : str
        family name of the person
    age : int
        age of the person

    Methods
    -------
    info(additional=""):
        Prints the person's name and age.
    """

    def __init__(self, name, surname, age):
        """
        Constructs all the necessary attributes for the person object.

        Parameters
        ----------
            name : str
                first name of the person
            surname : str
                family name of the person
            age : int
                age of the person
        """

        self.name = name
        self.surname = surname
        self.age = age

    def info(self, additional=""):
        """
        Prints the person's name and age.

        If the argument 'additional' is passed, then it is appended after the main info.

        Parameters
        ----------
        additional : str, optional
            More info to be displayed (default is None)

        Returns
        -------
        None
        """

        print(f'My name is {self.name} {self.surname}. I am {self.age} years old.' + additional)

MohamedAliRashad avatar Jun 06 '21 23:06 MohamedAliRashad

I second this. I'm specifically looking for the feature for classes so that the docstring includes attributes as defined in init. What is the status of this?

matsuobasho avatar Aug 05 '21 18:08 matsuobasho

I submitted a PR a while back, and Nils made some comments. I need to incorporate his suggestions and then resubmit. I have been super busy lately, but I will try to get this done within the next week or two. Thanks for inquiring guys. Hopefully it will provide the motivation to wrap this thing up.

tracetidwell avatar Aug 05 '21 18:08 tracetidwell

I'm happy to go over it again @tracetidwell

NilsJPWerner avatar Aug 12 '21 19:08 NilsJPWerner