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

Commit 0cb5c2e

Browse files
committed
Merge pull request #127 from Nurdok/package_error
D104: Missing docstring in public package
2 parents 1cba4cd + 64a276f commit 0cb5c2e

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

docs/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# If extensions (or modules to document with autodoc) are in another directory,
1919
# add these directories to sys.path here. If the directory is relative to the
2020
# documentation root, use os.path.abspath to make it absolute, like shown here.
21-
sys.path.insert(0, os.path.join(os.path.abspath('.'), '..'))
21+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
2222

2323
# -- General configuration ------------------------------------------------
2424

@@ -266,8 +266,9 @@
266266
issuetracker = 'github'
267267
issuetracker_project = 'GreenSteam/pep257'
268268

269+
269270
def generate_error_code_table():
270-
from ..pep257 import ErrorRegistry
271+
from pep257 import ErrorRegistry
271272
with open(os.path.join('snippets', 'error_code_table.rst'), 'wt') as outf:
272273
outf.write(ErrorRegistry.to_rst())
273274

docs/release_notes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ Release Notes
55
Current Development Version
66
---------------------------
77

8-
Nothing here yet!
8+
New Features
9+
10+
* Added the D104 error code - "Missing docstring in public package". This new
11+
error is turned on by default. Missing docstring in `__init__.py` files which
12+
previously resulted in D100 errors ("Missing docstring in public module")
13+
will now result in D104 (#105, #127).
914

1015

1116
0.6.0 - July 20th, 2015

pep257.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ def __str__(self):
141141
return 'at module level'
142142

143143

144+
class Package(Module):
145+
146+
"""A package is a __init__.py module."""
147+
148+
144149
class Function(Definition):
145150

146151
_nest = staticmethod(lambda s: {'def': NestedFunction,
@@ -398,8 +403,11 @@ def parse_module(self):
398403
children = list(self.parse_definitions(Module, all=True))
399404
assert self.current is None, self.current
400405
end = self.line
401-
module = Module(self.filename, self.source, start, end,
402-
[], docstring, children, None, self.all)
406+
cls = Module
407+
if self.filename.endswith('__init__.py'):
408+
cls = Package
409+
module = cls(self.filename, self.source, start, end,
410+
[], docstring, children, None, self.all)
403411
for child in module.children:
404412
child.parent = module
405413
log.debug("finished parsing module.")
@@ -580,6 +588,7 @@ def to_rst(cls):
580588
D101 = D1xx.create_error('D101', 'Missing docstring in public class')
581589
D102 = D1xx.create_error('D102', 'Missing docstring in public method')
582590
D103 = D1xx.create_error('D103', 'Missing docstring in public function')
591+
D104 = D1xx.create_error('D104', 'Missing docstring in public package')
583592

584593
D2xx = ErrorRegistry.create_group('D2', 'Whitespace Issues')
585594
D200 = D2xx.create_error('D200', 'One-line docstring should fit on one line '
@@ -926,7 +935,8 @@ def check_docstring_missing(self, definition, docstring):
926935
if (not docstring and definition.is_public or
927936
docstring and is_blank(eval(docstring))):
928937
codes = {Module: D100, Class: D101, NestedClass: D101,
929-
Method: D102, Function: D103, NestedFunction: D103}
938+
Method: D102, Function: D103, NestedFunction: D103,
939+
Package: D104}
930940
return codes[type(definition)]()
931941

932942
@check_for(Definition)

test_pep257.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,13 @@ def foo():
279279
assert code == 0
280280
assert 'D301' not in err
281281
assert 'D302' not in err
282+
283+
284+
def test_missing_docstring_in_package():
285+
with Pep257Env() as env:
286+
with env.open('__init__.py', 'wt') as init:
287+
pass # an empty package file
288+
out, err, code = env.invoke_pep257()
289+
assert code == 1
290+
assert 'D100' not in err # shouldn't be treated as a module
291+
assert 'D104' in err # missing docstring in package

0 commit comments

Comments
 (0)