pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

False negative: missing numpy param doc when "default ..." in same line of "param : type" #6211

Open vepain opened 2 years ago

vepain commented 2 years ago

Bug description

False negative : Warning "missing param doc" should'nt be raised when these type of docstring format:

def func(x: int = 0):
  """This is func.

  Parameter
  ---------
  x : int, default 0  # this raises the warning
    The x parameter
  """
  # ...

Configuration

[MASTER]
load-plugins =
    pylint.extensions.docstyle,
    pylint.extensions.docparams

[MESSAGES CONTROL]
enable = W

[BASIC]
accept-no-param-doc = no

Command used

pylint --rcfile=tox.ini a.py

Pylint output

"orientation" missing in parameter documentation

Expected behavior

No warning

In fact, numpy style doc says:

These are all equivalent:

copy : bool, default True
copy : bool, default=True
copy : bool, default: True

Pylint version

pylint 2.13.5
astroid 2.11.2
Python 3.9.12 (main, Mar 24 2022, 16:20:11) 
[GCC 9.4.0]

OS / Environment

Ubuntu 20.04

Additional dependencies

No response

lkev commented 2 years ago

+1 having the same issue.

Just to add - the following does not raise any error, so maybe just allow items in parenthesis and/or the "default" word after the comma?

def func(x: int = 0):
  """This is func.

  Parameter
  ---------
  x : int, optional
    The x parameter, by default 0
  """
  # ...
DanielNoord commented 2 years ago

See https://numpydoc.readthedocs.io/en/latest/format.html#parameters and the failures in https://github.com/PyCQA/pylint/pull/7149.

adam-grant-hendry commented 2 years ago

I am seeing this as well with

python 3.8.10
pylint 2.14.5

using

pylint.extensions.docparams

@DanielNoord Has this not been fixed yet?

DanielNoord commented 2 years ago

No, I don't think so. The linked PR fixed something different.

adam-grant-hendry commented 2 years ago

@DanielNoord Can you point me to the section of code to review? I can submit a PR if you like.

adam-grant-hendry commented 2 years ago

@DanielNoord Can you point me to the section of code to review? I can submit a PR if you like.

Actually, I'm assuming this is pylint/extensions/docparams.py. I'll submit a PR.

Pierre-Sassoulas commented 2 years ago

That's right @adam-grant-hendry, most tests for this checker are in https://github.com/PyCQA/pylint/tree/main/tests/functional/ext/docparams

adam-grant-hendry commented 2 years ago

@lkev @vepain One note: you are using Parameter instead of Parameters (plural). Change this to Parameters. pylint checks for this docstring section using the plural form of the word, so if you don't write it like that, the docparams extension won't see any of your parameters:

re_param_section = re.compile(
        _re_section_template.format(r"(?:Args|Arguments|Parameters)"),
        re.X | re.S | re.M,
    )

and this is how it is written in the numpydoc Style Guide.

Note, this doesn't fix the bug, but wanted to point it out because you will silently think everything is fine when it is not.