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

Commit

Permalink
Allow for greater flexibility in parsing __all__.
Browse files Browse the repository at this point in the history
This patch allows for newlines and comments to be inserted between the opening
parenthesis or bracket for the __all__ list and the first string value.
Additionally, a test has been added for this case.

Proposed fix for Issue #66.
  • Loading branch information
jkrukoff committed Mar 31, 2014
1 parent a12f427 commit 35b1129
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pep257.py
Expand Up @@ -235,6 +235,8 @@ def parse_all(self):
sys.stderr.write(msg)
self.consume(tk.OP)
s = '('
while self.current.kind in (tk.NL, tk.COMMENT):
self.stream.move()
if self.current.kind != tk.STRING:
raise AllError('Could not evaluate contents of __all__. ')
while self.current.value not in ')]':
Expand Down
11 changes: 11 additions & 0 deletions test_definitions.py
Expand Up @@ -29,6 +29,12 @@ def nested_3(self):
__all__ = ['a', 'b'
'c',]
'''
source_alt_nl_at_bracket = '''
__all__ = [
# Inconvenient comment.
'a', 'b' 'c',]
'''


def test_parser():
Expand Down Expand Up @@ -63,6 +69,11 @@ def test_parser():
assert Module('file_alt.py', _, 1, len(source_alt.split('\n')),
None, _, _, all) == module

module = parse(StringIO(source_alt_nl_at_bracket), 'file_alt_nl.py')
assert Module('file_alt_nl.py', _, 1,
len(source_alt_nl_at_bracket.split('\n')), None, _, _,
all) == module


def _test_module():

Expand Down

0 comments on commit 35b1129

Please sign in to comment.