terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

False positive DAR301 for optional keyword parameter when using Numpy-style docstrings #168

Closed amv213 closed 3 years ago

amv213 commented 3 years ago
def foo(x: str = 'bar') -> None:
    """[summary]

    Parameters
    ----------
    x : str, optional
        [description], by default 'bar'
    """

    print(x)

raises

DAR103 Parameter type mismatch: ~x: expected str but was str, optional

when <type>, optional is the numpydoc way of indicating that the given parameter is optional and has a default value. Darglint might be interpreting it as corresponding to a typing.Optional type definition - which in this case is not actually appropriate.

terrencepreilly commented 3 years ago

This has been brought up before, many times. See issues #123, #114, #112, and #95.