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

Commit 8248cfb

Browse files
committed
Merge pull request #143 from Nurdok/all-token-error
Fixed the creation of an AllError when there is an unexpected token
2 parents d7d21b1 + ec0639a commit 8248cfb

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docs/release_notes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ Release Notes
22
=============
33

44

5+
Current Development Version
6+
---------------------------
7+
8+
Bug Fixes
9+
10+
* Fixed an issue where a `NameError` was raised when parsing complex defintions
11+
of `__all__` (#142, #143).
12+
13+
514
0.7.0 - October 9th, 2015
615
-------------------------
716

src/pep257.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ def parse_all(self):
389389
self.current.value == ','):
390390
all_content += self.current.value
391391
else:
392-
kind = token.tok_name[self.current.kind]
393-
raise AllError('Unexpected token kind in __all__: %s' % kind)
392+
raise AllError('Unexpected token kind in __all__: %r. ' %
393+
self.current.kind)
394394
self.stream.move()
395395
self.consume(tk.OP)
396396
all_content += ")"

src/tests/test_definitions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2+
import pytest
23
from ..pep257 import (StringIO, TokenStream, Parser, Error, check,
34
Module, Class, Method, Function, NestedFunction,
4-
ErrorRegistry)
5+
ErrorRegistry, AllError)
56

67

78
_ = type('', (), dict(__repr__=lambda *a: '_', __eq__=lambda *a: True))()
@@ -44,6 +45,13 @@ def nested_3(self):
4445
from __future__ import (nested_scopes as ns,
4546
unicode_literals)
4647
'''
48+
source_complex_all = '''
49+
import foo
50+
import bar
51+
52+
__all__ = (foo.__all__ +
53+
bar.__all)
54+
'''
4755

4856

4957
def test_parser():
@@ -98,6 +106,8 @@ def test_parser():
98106
_, {'unicode_literals': True, 'nested_scopes': True}) \
99107
== module
100108
assert module.future_imports['unicode_literals']
109+
with pytest.raises(AllError):
110+
parse(StringIO(source_complex_all), 'file_complex_all.py')
101111

102112

103113
def _test_module():

0 commit comments

Comments
 (0)