• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyta-uoft / pyta / 15338828631

30 May 2025 03:54AM UTC coverage: 92.94% (-0.5%) from 93.487%
15338828631

Pull #1177

github

web-flow
Merge c8611d90f into fc1c64f4d
Pull Request #1177: Refactor reporter loading and imports

28 of 49 new or added lines in 14 files covered. (57.14%)

3436 of 3697 relevant lines covered (92.94%)

17.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/python_ta/checkers/unmentioned_parameter_checker.py
1
"""Checker to check that every function parameter is mentioned by name in the docstring text."""
2

3
from __future__ import annotations
20✔
4

5
import doctest
20✔
6
import string
20✔
7
from typing import TYPE_CHECKING
20✔
8

9
from pylint.checkers import BaseChecker
20✔
10
from pylint.checkers.utils import only_required_for_messages
20✔
11

12
if TYPE_CHECKING:
20✔
NEW
13
    from astroid import nodes
×
NEW
14
    from pylint.lint import PyLinter
×
15

16

17
class UnmentionedParameterChecker(BaseChecker):
20✔
18
    """A class to check if every function parameter is mentioned by name within the function's the docstring."""
19

20
    name = "unmentioned-parameter"
20✔
21
    msgs = {
20✔
22
        "C9960": (
23
            "The parameter '%s' is not mentioned in the docstring",
24
            "unmentioned-parameter",
25
            "Used when a function parameter is not mentioned in the docstring",
26
        )
27
    }
28

29
    @only_required_for_messages("unmentioned-parameter")
20✔
30
    def visit_functiondef(self, node: nodes.FunctionDef) -> None:
20✔
31
        """Visit a function definition"""
32
        docstring = node.doc_node.value if node.doc_node and node.doc_node.value else ""
20✔
33
        remove_punctuation = str.maketrans(
20✔
34
            {char: " " for char in string.punctuation if char != "_"}
35
        )
36
        docstring = self._strip_docstring_of_doctest(docstring).translate(remove_punctuation)
20✔
37
        docstring_words = {word for line in docstring.split("\n") for word in line.split()}
20✔
38
        for parameter in node.args.args:
20✔
39
            self._check_parameter(docstring_words, parameter.name, parameter)
20✔
40

41
    def _check_parameter(
20✔
42
        self, docstring_words: set[str], parameter: str, node: nodes.NodeNG
43
    ) -> None:
44
        """Return whether parameter is mentioned in the docstring_words"""
45
        if parameter not in docstring_words:
20✔
46
            self.add_message("unmentioned-parameter", node=node, args=parameter, line=node.lineno)
20✔
47

48
    def _strip_docstring_of_doctest(self, docstring: str) -> str:
20✔
49
        """Return the docstring without the doctest"""
50
        parsed = doctest.DocTestParser().parse(docstring)
20✔
51
        return "".join(part for part in parsed if not isinstance(part, doctest.Example))
20✔
52

53

54
def register(linter: PyLinter) -> None:
20✔
55
    """Required method to auto register this checker on the linter"""
56
    linter.register_checker(UnmentionedParameterChecker(linter))
20✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc