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

Commit

Permalink
Add D419: Add and switch to "Docstring is empty" error code (#559)
Browse files Browse the repository at this point in the history
Co-authored-by: Sambhav Kothari <sambhavs.email@gmail.com>
  • Loading branch information
thejcannon and samj1912 committed Dec 30, 2021
1 parent 07fa835 commit 8dee619
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/release_notes.rst
Expand Up @@ -12,6 +12,7 @@ New Features

* Add support for `property_decorators` config to ignore D401.
* Add support for Python 3.10 (#554).
* Replace D10X errors with D419 if docstring exists but is empty (#559).

6.1.1 - May 17th, 2021
---------------------------
Expand Down
19 changes: 13 additions & 6 deletions src/pydocstyle/checker.py
Expand Up @@ -196,12 +196,7 @@ def check_docstring_missing(self, definition, docstring):
with a single underscore.
"""
if (
not docstring
and definition.is_public
or docstring
and is_blank(ast.literal_eval(docstring))
):
if not docstring and definition.is_public:
codes = {
Module: violations.D100,
Class: violations.D101,
Expand All @@ -227,6 +222,18 @@ def check_docstring_missing(self, definition, docstring):
}
return codes[type(definition)]()

@check_for(Definition, terminal=True)
def check_docstring_empty(self, definition, docstring):
"""D419: Docstring is empty.
If the user provided a docstring but it was empty, it is like they never provided one.
NOTE: This used to report as D10X errors.
"""
if docstring and is_blank(ast.literal_eval(docstring)):
return violations.D419()

@check_for(Definition)
def check_one_liners(self, definition, docstring):
"""D200: One-liner docstrings should fit on one line with quotes.
Expand Down
4 changes: 4 additions & 0 deletions src/pydocstyle/violations.py
Expand Up @@ -415,6 +415,10 @@ def to_rst(cls) -> str:
'D418',
'Function/ Method decorated with @overload shouldn\'t contain a docstring',
)
D419 = D4xx.create_error(
'D419',
'Docstring is empty',
)


class AttrDict(dict):
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_cases/capitalization.py
Expand Up @@ -13,7 +13,7 @@ def not_capitalized():


# Make sure empty docstrings don't generate capitalization errors.
@expect("D103: Missing docstring in public function")
@expect("D419: Docstring is empty")
def empty_docstring():
""""""

Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_cases/test.py
Expand Up @@ -13,7 +13,7 @@

class class_:

expect('meta', 'D106: Missing docstring in public nested class')
expect('meta', 'D419: Docstring is empty')

class meta:
""""""
Expand Down Expand Up @@ -64,13 +64,13 @@ def __call__(self=None, x=None, y=None, z=None):
pass


@expect('D103: Missing docstring in public function')
@expect('D419: Docstring is empty')
def function():
""" """
def ok_since_nested():
pass

@expect('D103: Missing docstring in public function')
@expect('D419: Docstring is empty')
def nested():
''

Expand Down

0 comments on commit 8dee619

Please sign in to comment.