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

Commit 9589896

Browse files
committed
Merge pull request #77 from Nurdok/issue-76
Handle one-liner defintions
2 parents 10b3bba + 42a6188 commit 9589896

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

pep257.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def __call__(self, filelike, filename):
186186
def consume(self, kind):
187187
assert self.stream.move().kind == kind
188188

189-
def leapfrog(self, kind):
189+
def leapfrog(self, kind, value=None):
190190
for token in self.stream:
191-
if token.kind == kind:
191+
if token.kind == kind and (value is None or token.value == value):
192192
self.consume(kind)
193193
return
194194

@@ -264,12 +264,19 @@ def parse_definition(self, class_):
264264
start = self.line
265265
self.consume(tk.NAME)
266266
name = self.current.value
267-
self.leapfrog(tk.INDENT)
268-
assert self.current.kind != tk.INDENT
269-
docstring = self.parse_docstring()
270-
children = list(self.parse_definitions(class_))
271-
assert self.current.kind == tk.DEDENT
272-
end = self.line - 1
267+
self.leapfrog(tk.OP, value=":")
268+
if self.current.kind in (tk.NEWLINE, tk.COMMENT):
269+
self.leapfrog(tk.INDENT)
270+
assert self.current.kind != tk.INDENT
271+
docstring = self.parse_docstring()
272+
children = list(self.parse_definitions(class_))
273+
assert self.current.kind == tk.DEDENT
274+
end = self.line - 1
275+
else: # one-liner definition
276+
docstring = self.parse_docstring()
277+
children = []
278+
end = self.line
279+
self.leapfrog(tk.NEWLINE)
273280
definition = class_(name, self.source, start, end,
274281
docstring, children, None)
275282
for child in definition.children:

test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,20 @@ def old_209():
216216
217217
"""
218218

219+
220+
@expect("D103: Docstring missing")
221+
def oneliner_d102(): return
222+
223+
224+
@expect("D400: First line should end with '.', not 'r'")
225+
def oneliner_withdoc(): """One liner"""
226+
227+
228+
@expect("D208: Docstring is over-indented")
229+
def docstring_start_in_same_line(): """First Line.
230+
231+
Second Line
232+
"""
233+
234+
219235
expect('test.py', 'D100: Docstring missing')

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ commands = py.test --pep8
1111
deps = pytest
1212
pytest-pep8
1313
mock
14+
15+
[pytest]
16+
pep8ignore =
17+
test.py E701

0 commit comments

Comments
 (0)