Skip to content

Commit 4af4e97

Browse files
committed
Merge pull request #86 from twisted/no-inner-doc-requirement
Allow classes defined within functions to be undocumented.
2 parents 30f4a37 + 6295202 commit 4af4e97

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
2+
# -*- test-case-name: twistedchecker -*-
33
# Copyright (c) Twisted Matrix Laboratories.
44
# See LICENSE for details.
55

twistedchecker/checkers/docstring.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# -*- test-case-name: twistedchecker.test.test_functionaltests -*-
2+
# Copyright (c) Twisted Matrix Laboratories.
3+
# See LICENSE for details.
4+
5+
"""
6+
Checks for docstrings.
7+
"""
8+
19
import re
210

311
from logilab.astng import node_classes
@@ -8,6 +16,24 @@
816
from pylint.checkers.base import NO_REQUIRED_DOC_RGX
917

1018

19+
def _isInner(node):
20+
"""
21+
Determine whether the given node is, at any point in its syntactic
22+
parentage, defined within a function.
23+
24+
@param node: The node to inspect.
25+
@type node: L{logilab.astng.bases.NodeNG}
26+
27+
@return: a boolean indicating if the given node is defined as an inner
28+
class or inner function.
29+
"""
30+
while node:
31+
node = node.parent
32+
if isinstance(node, scoped_nodes.Function):
33+
return True
34+
return False
35+
36+
1137

1238
class DocstringChecker(PylintDocStringChecker):
1339
"""
@@ -89,7 +115,7 @@ def _check_docstring(self, node_type, node):
89115
if docstring is None:
90116
# The node does not have a docstring.
91117
# But do not check things inside a function or method.
92-
if type(node.parent) != scoped_nodes.Function:
118+
if not _isInner(node):
93119
self.add_message('W9208', node=node)
94120
return
95121
elif not docstring.strip():

twistedchecker/functionaltests/docstring_pass.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# enable: W9201,W9202,W9203,W9204,W9205,W9206,W9207
1+
# enable: W9201,W9202,W9203,W9204,W9205,W9206,W9207,W9208,W9209
2+
# -*- test-case-name: twistedchecker.test.test_functionaltests.FunctionalTests.test_twistedchecker_functionaltests_docstring_pass -*-
23
"""
34
A docstring with a wrong indentation.
45
Docstring should have consistent indentations.
@@ -65,7 +66,7 @@ def f(self):
6566

6667

6768

68-
class Bar(self):
69+
class Bar(object):
6970
"""
7071
A cvar is recognized as being the start of epytext markup.
7172
@@ -89,10 +90,22 @@ def b(self):
8990
@raise BarException: Another exception.
9091
@returns: C{int}
9192
"""
93+
def callback(result):
94+
pass
95+
96+
97+
9298

99+
def topLevel():
100+
"""
101+
A top-level function.
102+
"""
103+
class Inner(object):
104+
def innerInner(self):
105+
pass
93106

94107

95-
class Baz(self):
108+
class Baz(object):
96109
"""
97110
An ivar is recognized as being the start of epytext markup.
98111

0 commit comments

Comments
 (0)