Skip to content

W9006: missing-raises-doc false positive when declaring multiple exceptions in SphinxDocstring #2729

Closed
@StephenBrown2

Description

@StephenBrown2

Steps to reproduce

Using load-plugins=pylint.extensions.docparams

  1. Create a function which potentially raises multiple Exceptions:
def function_name(args):
    if isinstance(args, dict):
        raise TypeError
    elif isinstance(args, str):
        raise ValueError
    else:
        raise ValidationError
  1. Document such functionality as :raises TypeError, ValueError, ValidationError
    """ A function that raises exceptions

    :param args: The arguments
    :type args: int

    :raises TypeError, ValueError, ValidationError:
    """
  1. Get [W9006(missing-raises-doc), function_name] "ValueError" not documented as being raised, et al.

Full test file:

#!/usr/bin/env python3

class ValidationError(Exception):
    pass

def function_name(args):
    """ A function that raises exceptions

    :param args: The arguments
    :type args: int

    :raises TypeError, ValueError, ValidationError:
    """
    if isinstance(args, dict):
        raise TypeError
    elif isinstance(args, str):
        raise ValueError
    else:
        raise ValidationError

Current behavior

************* Module test_raises
test_raises.py:6: [W9006(missing-raises-doc), function_name] "TypeError" not documented as being raised
test_raises.py:6: [W9006(missing-raises-doc), function_name] "ValueError" not documented as being raised
test_raises.py:6: [W9006(missing-raises-doc), function_name] "ValidationError" not documented as being raised

Expected behavior

pylint passes / Your code has been rated at 10.00/10

pylint --version output

$ pylint --version
pylint 2.2.2
astroid 2.1.0
Python 3.7.2 (default, Jan 10 2019, 23:51:51)
[GCC 8.2.1 20181127]

Notes

Sphinx properly parses the Exception types raised and links them individually, so I believe only a small change would be needed in the regex here and parsing of such here to allow for comma+whitespace (, *) separated types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions