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

Commit 8dee619

Browse files
thejcannonsambhav
andauthored
Add D419: Add and switch to "Docstring is empty" error code (#559)
Co-authored-by: Sambhav Kothari <[email protected]>
1 parent 07fa835 commit 8dee619

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

docs/release_notes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ New Features
1212

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

1617
6.1.1 - May 17th, 2021
1718
---------------------------

src/pydocstyle/checker.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,7 @@ def check_docstring_missing(self, definition, docstring):
196196
with a single underscore.
197197
198198
"""
199-
if (
200-
not docstring
201-
and definition.is_public
202-
or docstring
203-
and is_blank(ast.literal_eval(docstring))
204-
):
199+
if not docstring and definition.is_public:
205200
codes = {
206201
Module: violations.D100,
207202
Class: violations.D101,
@@ -227,6 +222,18 @@ def check_docstring_missing(self, definition, docstring):
227222
}
228223
return codes[type(definition)]()
229224

225+
@check_for(Definition, terminal=True)
226+
def check_docstring_empty(self, definition, docstring):
227+
"""D419: Docstring is empty.
228+
229+
If the user provided a docstring but it was empty, it is like they never provided one.
230+
231+
NOTE: This used to report as D10X errors.
232+
233+
"""
234+
if docstring and is_blank(ast.literal_eval(docstring)):
235+
return violations.D419()
236+
230237
@check_for(Definition)
231238
def check_one_liners(self, definition, docstring):
232239
"""D200: One-liner docstrings should fit on one line with quotes.

src/pydocstyle/violations.py

+4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ def to_rst(cls) -> str:
415415
'D418',
416416
'Function/ Method decorated with @overload shouldn\'t contain a docstring',
417417
)
418+
D419 = D4xx.create_error(
419+
'D419',
420+
'Docstring is empty',
421+
)
418422

419423

420424
class AttrDict(dict):

src/tests/test_cases/capitalization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def not_capitalized():
1313

1414

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

src/tests/test_cases/test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class class_:
1515

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

1818
class meta:
1919
""""""
@@ -64,13 +64,13 @@ def __call__(self=None, x=None, y=None, z=None):
6464
pass
6565

6666

67-
@expect('D103: Missing docstring in public function')
67+
@expect('D419: Docstring is empty')
6868
def function():
6969
""" """
7070
def ok_since_nested():
7171
pass
7272

73-
@expect('D103: Missing docstring in public function')
73+
@expect('D419: Docstring is empty')
7474
def nested():
7575
''
7676

0 commit comments

Comments
 (0)