Skip to content

Docparams does not recognize class docstring when placed in __init__ #6692

@tcamise-gpsw

Description

@tcamise-gpsw

Bug description

The documentation states that "Constructor parameters can be documented in either the class docstring or the init docstring, but not both.

However, I see that the docstring is only recognized when in the class docstring.

Consider this simple main.py:

"""MyModule"""

class MyClass:
    def __init__(self, variable: int) -> None:
        """_summary_

        Args:
            variable (int): _description_
        """
        self.my_variable = variable

    def method1(self) -> bool:
        """_summary_"""
        return bool(self.my_variable)

    def method2(self) -> int:
        """_summary_"""
        return 2 if self.my_variable else 1

This will raise a missing-class-docstring error.
If I move the docstring from __init to the Class, it passes.
Also of note, if I put the docstring in both places, I do not get multiple-constructor-doc error.

Configuration

[MAIN]
load-plugins=pylint.extensions.docparams

Command used

pylint main.py

Pylint output

************* Module main
main.py:3:0: C0115: Missing class docstring (missing-class-docstring)

------------------------------------------------------------------
Your code has been rated at 8.57/10 (previous run: 8.57/10, +0.00)

Expected behavior

I expect to not receive this error when the docstring is in __init__
Also, I expect to receive multiple-constructor-doc if I put the docstring in both places.

Pylint version

Python 3.9.10
I tested both pylint 2.14.0b and 2.13.9

OS / Environment

Windows Git Bash

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentGood first issueFriendly and approachable by new contributorsHacktoberfestHelp wanted 🙏Outside help would be appreciated, good for new contributorsMinor 💅Polishing pylint is always niceNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions