Skip to content

Commit 1fb9963

Browse files
committed
Fix PyCQA#182
1 parent 4975051 commit 1fb9963

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

src/pydocstyle.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ def parse_definition(self, class_):
486486
self.current.value)
487487
return definition
488488

489+
def check_current(self, kind=None, value=None):
490+
msg = """Error at line {self.line}:
491+
492+
In file: {self.filename}
493+
494+
Got kind {self.current.kind!r}
495+
Got value {self.current.value}
496+
""".format(self=self)
497+
kind_valid = self.current.kind == kind if kind else True
498+
value_valid = self.current.value == value if value else True
499+
assert kind_valid and value_valid, msg
500+
489501
def parse_from_import_statement(self):
490502
"""Parse a 'from x import y' statement.
491503
@@ -495,9 +507,12 @@ def parse_from_import_statement(self):
495507
log.debug('parsing from/import statement.')
496508
assert self.current.value == 'from', self.current.value
497509
self.stream.move()
498-
if self.current.value != '__future__':
499-
return
510+
is_future_import = self.current.value == '__future__'
500511
self.stream.move()
512+
while (self.current.kind in (tk.DOT, tk.NAME, tk.OP) and
513+
self.current.value != 'import'):
514+
self.stream.move()
515+
self.check_current(value='import')
501516
assert self.current.value == 'import', self.current.value
502517
self.stream.move()
503518
if self.current.value == '(':
@@ -512,8 +527,9 @@ def parse_from_import_statement(self):
512527
continue
513528
log.debug("parsing import, token is %r (%s)",
514529
self.current.kind, self.current.value)
515-
log.debug('found future import: %s', self.current.value)
516-
self.future_imports[self.current.value] = True
530+
if is_future_import:
531+
log.debug('found future import: %s', self.current.value)
532+
self.future_imports[self.current.value] = True
517533
self.consume(tk.NAME)
518534
log.debug("parsing import, token is %r (%s)",
519535
self.current.kind, self.current.value)

src/tests/test_cases/all_import.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""A valid module docstring."""
2+
3+
from .all_import_aux import __all__ as not_dunder_all
4+
from .expected import Expectation
5+
6+
expectation = Expectation()
7+
expect = expectation.expect
8+
9+
__all__ = ('public_func', )
10+
11+
12+
@expect("D103: Missing docstring in public function")
13+
def public_func():
14+
pass
15+
16+
17+
def private_func():
18+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__all__ = ('this', 'is', 'a', 'helper', 'file')

src/tests/test_definitions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def test_token_stream():
260260
'capitalization',
261261
'comment_after_def_bug',
262262
'multi_line_summary_start',
263+
'all_import',
263264
])
264265
def test_pep257(test_case):
265266
"""Run domain-specific tests from test.py file."""

0 commit comments

Comments
 (0)