Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Skip function arguments prefixed with _ in D417 check
Browse files Browse the repository at this point in the history
These arguments have been marked private. As such,
it should be okay for the checker to not validate their
existence in the docstring,
  • Loading branch information
samj1912 committed Jan 10, 2020
1 parent 55fde24 commit c454be8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -4,6 +4,14 @@ Release Notes
**pydocstyle** version numbers follow the
`Semantic Versioning <http://semver.org/>`_ specification.

Current Development Version
---------------------------

New Features

* Skip function arguments prefixed with `_` in D417 check (#440).


5.0.2 - January 8th, 2020
---------------------------

Expand Down
10 changes: 10 additions & 0 deletions src/pydocstyle/checker.py
Expand Up @@ -764,6 +764,13 @@ def _check_missing_args(docstring_args, definition):
# positional argument as it is `cls` or `self`
if definition.kind == 'method' and not definition.is_static:
function_args = function_args[1:]
# Filtering out any arguments prefixed with `_` marking them
# as private.
function_args = [
arg_name
for arg_name in function_args
if not is_def_arg_private(arg_name)
]
missing_args = set(function_args) - docstring_args
if missing_args:
yield violations.D417(", ".join(sorted(missing_args)),
Expand Down Expand Up @@ -996,6 +1003,9 @@ def get_leading_words(line):
if result is not None:
return result.group()

def is_def_arg_private(arg_name):
"""Returns a boolean indicating if the argument name is private."""
return arg_name.startswith("_")

def get_function_args(function_string):
"""Return the function arguments given the source-code string."""
Expand Down
24 changes: 12 additions & 12 deletions src/tests/test_cases/sections.py
Expand Up @@ -278,7 +278,7 @@ def missing_colon_google_style_section(): # noqa: D406, D407
@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) y are missing descriptions in "
"'test_missing_google_args' docstring)")
def test_missing_google_args(x=1, y=2): # noqa: D406, D407
def test_missing_google_args(x=1, y=2, _private=3): # noqa: D406, D407
"""Toggle the gizmo.
Args:
Expand All @@ -290,7 +290,7 @@ def test_missing_google_args(x=1, y=2): # noqa: D406, D407
class TestGoogle: # noqa: D203
"""Test class."""

def test_method(self, test, another_test): # noqa: D213, D407
def test_method(self, test, another_test, _): # noqa: D213, D407
"""Test a valid args section.
Args:
Expand All @@ -301,8 +301,8 @@ def test_method(self, test, another_test): # noqa: D213, D407

@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) test, y, z are missing descriptions in "
"'test_missing_args' docstring)", arg_count=4)
def test_missing_args(self, test, x, y, z=3): # noqa: D213, D407
"'test_missing_args' docstring)", arg_count=5)
def test_missing_args(self, test, x, y, z=3, _private_arg=3): # noqa: D213, D407
"""Test a valid args section.
Args:
Expand All @@ -313,8 +313,8 @@ def test_missing_args(self, test, x, y, z=3): # noqa: D213, D407
@classmethod
@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) test, y, z are missing descriptions in "
"'test_missing_args_class_method' docstring)", arg_count=4)
def test_missing_args_class_method(cls, test, x, y, z=3): # noqa: D213, D407
"'test_missing_args_class_method' docstring)", arg_count=5)
def test_missing_args_class_method(cls, test, x, y, _, z=3): # noqa: D213, D407
"""Test a valid args section.
Args:
Expand All @@ -326,8 +326,8 @@ def test_missing_args_class_method(cls, test, x, y, z=3): # noqa: D213, D407
@staticmethod
@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) a, y, z are missing descriptions in "
"'test_missing_args_static_method' docstring)", arg_count=3)
def test_missing_args_static_method(a, x, y, z=3): # noqa: D213, D407
"'test_missing_args_static_method' docstring)", arg_count=4)
def test_missing_args_static_method(a, x, y, _test, z=3): # noqa: D213, D407
"""Test a valid args section.
Args:
Expand All @@ -340,7 +340,7 @@ def test_missing_args_static_method(a, x, y, z=3): # noqa: D213, D407
@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) y are missing descriptions in "
"'test_missing_numpy_args' docstring)")
def test_missing_numpy_args(x=1, y=2): # noqa: D406, D407
def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
"""Toggle the gizmo.
Parameters
Expand All @@ -354,7 +354,7 @@ def test_missing_numpy_args(x=1, y=2): # noqa: D406, D407
class TestNumpy: # noqa: D203
"""Test class."""

def test_method(self, test, another_test, x=1, y=2): # noqa: D213, D407
def test_method(self, test, another_test, _, x=1, y=2, _private_arg=1): # noqa: D213, D407
"""Test a valid args section.
Parameters
Expand All @@ -368,8 +368,8 @@ def test_method(self, test, another_test, x=1, y=2): # noqa: D213, D407

@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) test, y, z are missing descriptions in "
"'test_missing_args' docstring)", arg_count=4)
def test_missing_args(self, test, x, y, z=3, t=1): # noqa: D213, D407
"'test_missing_args' docstring)", arg_count=5)
def test_missing_args(self, test, x, y, z=3, t=1, _private=0): # noqa: D213, D407
"""Test a valid args section.
Parameters
Expand Down

0 comments on commit c454be8

Please sign in to comment.