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

Commit 8cd5bde

Browse files
committed
Added test for importing __all__
1 parent d2a836e commit 8cd5bde

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/pydocstyle.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,28 @@ def parse_from_import_statement(self):
507507
508508
"""
509509
log.debug('parsing from/import statement.')
510+
is_future_import = self._parse_from_import_source()
511+
self._parse_from_import_names(is_future_import)
512+
513+
def _parse_from_import_source(self):
514+
"""Parse the 'from x import' part in a 'from x import y' statement.
515+
516+
Return true iff `x` is __future__.
517+
"""
510518
assert self.current.value == 'from', self.current.value
511519
self.stream.move()
512520
is_future_import = self.current.value == '__future__'
513521
self.stream.move()
514522
while (self.current.kind in (tk.DOT, tk.NAME, tk.OP) and
515-
self.current.value != 'import'):
523+
self.current.value != 'import'):
516524
self.stream.move()
517525
self.check_current(value='import')
518526
assert self.current.value == 'import', self.current.value
519527
self.stream.move()
528+
return is_future_import
529+
530+
def _parse_from_import_names(self, is_future_import):
531+
"""Parse the 'y' part in a 'from x import y' statement."""
520532
if self.current.value == '(':
521533
self.consume(tk.OP)
522534
expected_end_kind = tk.OP

src/tests/test_cases/all_import.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
"""A valid module docstring."""
22

3-
from .all_import_aux import __all__ as not_dunder_all
3+
from .all_import_aux import __all__
44
from .expected import Expectation
55

66
expectation = Expectation()
77
expect = expectation.expect
88

9-
__all__ = ('public_func', )
10-
119

1210
@expect("D103: Missing docstring in public function")
1311
def public_func():
1412
pass
1513

1614

17-
def private_func():
15+
@expect("D103: Missing docstring in public function")
16+
def this():
1817
pass

src/tests/test_cases/all_import_as.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

src/tests/test_definitions.py

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

0 commit comments

Comments
 (0)