pylint-dev/pylint

Docparams does not recognize class docstring when placed in __init__

Open

#6692 aperta il 24 mag 2022

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)Python (1059 fork)batch import
Enhancement ✨Good first issueHacktoberfestHelp wanted 🙏Minor 💅Needs PR

Metriche repository

Star
 (4978 star)
Metriche merge PR
 (Merge medio 58g 21h) (63 PR mergiate in 30 g)

Descrizione

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

Guida contributor