pylint-dev/pylint

Docparams does not recognize class docstring when placed in __init__

已關閉

#6,692 建立於 2022年5月24日

 (4 則留言) (0 個反應) (0 位負責人)Python (1,059 個分叉)batch import
Enhancement ✨Good first issueHacktoberfestHelp wanted 🙏Minor 💅Needs PR

倉庫指標

星標
 (4,978 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南