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

Commit 832fd11

Browse files
authored
Skip function arguments prefixed with _ in D417 check (#440)
These arguments have been marked private. As such, it should be okay for the checker to not validate their existence in the docstring,
1 parent 55fde24 commit 832fd11

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

docs/release_notes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Release Notes
44
**pydocstyle** version numbers follow the
55
`Semantic Versioning <http://semver.org/>`_ specification.
66

7+
Current Development Version
8+
---------------------------
9+
10+
New Features
11+
12+
* Skip function arguments prefixed with `_` in D417 check (#440).
13+
14+
715
5.0.2 - January 8th, 2020
816
---------------------------
917

src/pydocstyle/checker.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,13 @@ def _check_missing_args(docstring_args, definition):
764764
# positional argument as it is `cls` or `self`
765765
if definition.kind == 'method' and not definition.is_static:
766766
function_args = function_args[1:]
767+
# Filtering out any arguments prefixed with `_` marking them
768+
# as private.
769+
function_args = [
770+
arg_name
771+
for arg_name in function_args
772+
if not is_def_arg_private(arg_name)
773+
]
767774
missing_args = set(function_args) - docstring_args
768775
if missing_args:
769776
yield violations.D417(", ".join(sorted(missing_args)),
@@ -996,6 +1003,9 @@ def get_leading_words(line):
9961003
if result is not None:
9971004
return result.group()
9981005

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

10001010
def get_function_args(function_string):
10011011
"""Return the function arguments given the source-code string."""

src/tests/test_cases/sections.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def missing_colon_google_style_section(): # noqa: D406, D407
278278
@expect("D417: Missing argument descriptions in the docstring "
279279
"(argument(s) y are missing descriptions in "
280280
"'test_missing_google_args' docstring)")
281-
def test_missing_google_args(x=1, y=2): # noqa: D406, D407
281+
def test_missing_google_args(x=1, y=2, _private=3): # noqa: D406, D407
282282
"""Toggle the gizmo.
283283
284284
Args:
@@ -290,7 +290,7 @@ def test_missing_google_args(x=1, y=2): # noqa: D406, D407
290290
class TestGoogle: # noqa: D203
291291
"""Test class."""
292292

293-
def test_method(self, test, another_test): # noqa: D213, D407
293+
def test_method(self, test, another_test, _): # noqa: D213, D407
294294
"""Test a valid args section.
295295
296296
Args:
@@ -301,8 +301,8 @@ def test_method(self, test, another_test): # noqa: D213, D407
301301

302302
@expect("D417: Missing argument descriptions in the docstring "
303303
"(argument(s) test, y, z are missing descriptions in "
304-
"'test_missing_args' docstring)", arg_count=4)
305-
def test_missing_args(self, test, x, y, z=3): # noqa: D213, D407
304+
"'test_missing_args' docstring)", arg_count=5)
305+
def test_missing_args(self, test, x, y, z=3, _private_arg=3): # noqa: D213, D407
306306
"""Test a valid args section.
307307
308308
Args:
@@ -313,8 +313,8 @@ def test_missing_args(self, test, x, y, z=3): # noqa: D213, D407
313313
@classmethod
314314
@expect("D417: Missing argument descriptions in the docstring "
315315
"(argument(s) test, y, z are missing descriptions in "
316-
"'test_missing_args_class_method' docstring)", arg_count=4)
317-
def test_missing_args_class_method(cls, test, x, y, z=3): # noqa: D213, D407
316+
"'test_missing_args_class_method' docstring)", arg_count=5)
317+
def test_missing_args_class_method(cls, test, x, y, _, z=3): # noqa: D213, D407
318318
"""Test a valid args section.
319319
320320
Args:
@@ -326,8 +326,8 @@ def test_missing_args_class_method(cls, test, x, y, z=3): # noqa: D213, D407
326326
@staticmethod
327327
@expect("D417: Missing argument descriptions in the docstring "
328328
"(argument(s) a, y, z are missing descriptions in "
329-
"'test_missing_args_static_method' docstring)", arg_count=3)
330-
def test_missing_args_static_method(a, x, y, z=3): # noqa: D213, D407
329+
"'test_missing_args_static_method' docstring)", arg_count=4)
330+
def test_missing_args_static_method(a, x, y, _test, z=3): # noqa: D213, D407
331331
"""Test a valid args section.
332332
333333
Args:
@@ -340,7 +340,7 @@ def test_missing_args_static_method(a, x, y, z=3): # noqa: D213, D407
340340
@expect("D417: Missing argument descriptions in the docstring "
341341
"(argument(s) y are missing descriptions in "
342342
"'test_missing_numpy_args' docstring)")
343-
def test_missing_numpy_args(x=1, y=2): # noqa: D406, D407
343+
def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
344344
"""Toggle the gizmo.
345345
346346
Parameters
@@ -354,7 +354,7 @@ def test_missing_numpy_args(x=1, y=2): # noqa: D406, D407
354354
class TestNumpy: # noqa: D203
355355
"""Test class."""
356356

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

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

0 commit comments

Comments
 (0)