Commit c9149b18 authored by YOU's avatar YOU Committed by Dylan Trotter

Raise error on wildcard import (#119)

parent bd4077a4
...@@ -364,6 +364,12 @@ class StatementVisitor(ast.NodeVisitor): ...@@ -364,6 +364,12 @@ class StatementVisitor(ast.NodeVisitor):
self.block.bind_var(self.writer, asname, mod.expr) self.block.bind_var(self.writer, asname, mod.expr)
def visit_ImportFrom(self, node): def visit_ImportFrom(self, node):
# Wildcard imports are not yet supported.
for alias in node.names:
if alias.name == '*':
msg = 'wildcard member import is not implemented: from %s import %s' % (
node.module, alias.name)
raise util.ParseError(node, msg)
self._write_py_context(node.lineno) self._write_py_context(node.lineno)
if node.module.startswith(_NATIVE_MODULE_PREFIX): if node.module.startswith(_NATIVE_MODULE_PREFIX):
values = [alias.name for alias in node.names] values = [alias.name for alias in node.names]
......
...@@ -332,6 +332,14 @@ class StatementVisitorTest(unittest.TestCase): ...@@ -332,6 +332,14 @@ class StatementVisitorTest(unittest.TestCase):
self.assertRaisesRegexp(util.ParseError, want_regexp, self.assertRaisesRegexp(util.ParseError, want_regexp,
stmt.import_from_future, node) stmt.import_from_future, node)
def testImportWildcardMemberRaises(self):
regexp = r'wildcard member import is not implemented: from foo import *'
self.assertRaisesRegexp(util.ParseError, regexp, _ParseAndVisit,
'from foo import *')
regexp = r'wildcard member import is not implemented: from __go__.foo import *'
self.assertRaisesRegexp(util.ParseError, regexp, _ParseAndVisit,
'from __go__.foo import *')
def testVisitFuture(self): def testVisitFuture(self):
testcases = [ testcases = [
('from __future__ import print_function', ('from __future__ import print_function',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment