pylint-dev/pylint

Docparams does not recognize class docstring when placed in __init__

Open

#6 692 ouverte le 24 mai 2022

Voir sur GitHub
 (4 commentaires) (0 réactions) (0 assignés)Python (1 059 forks)batch import
Enhancement ✨Good first issueHacktoberfestHelp wanted 🙏Minor 💅Needs PR

Métriques du dépôt

Stars
 (4 978 stars)
Métriques de merge PR
 (Merge moyen 58j 21h) (63 PRs mergées en 30 j)

Description

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

Guide contributeur