Commit 666315e1 authored by Fred Drake's avatar Fred Drake

Do not allow import-as to rebind "under names".

parent 9579eb05
...@@ -15,7 +15,7 @@ RestrictionMutator modifies a tree produced by ...@@ -15,7 +15,7 @@ RestrictionMutator modifies a tree produced by
compiler.transformer.Transformer, restricting and enhancing the compiler.transformer.Transformer, restricting and enhancing the
code in various ways before sending it to pycodegen. code in various ways before sending it to pycodegen.
''' '''
__version__='$Revision: 1.10 $'[11:-2] __version__='$Revision: 1.11 $'[11:-2]
from SelectCompiler import ast, parse, OP_ASSIGN, OP_DELETE, OP_APPLY from SelectCompiler import ast, parse, OP_ASSIGN, OP_DELETE, OP_APPLY
...@@ -271,3 +271,10 @@ class RestrictionMutator: ...@@ -271,3 +271,10 @@ class RestrictionMutator:
def visitAugAssign(self, node, walker): def visitAugAssign(self, node, walker):
node.node.in_aug_assign = 1 node.node.in_aug_assign = 1
return walker.defaultVisitNode(node) return walker.defaultVisitNode(node)
def visitImport(self, node, walker):
for name, asname in node.names:
self.checkName(node, name)
if asname:
self.checkName(node, asname)
return node
...@@ -30,3 +30,13 @@ def bad_attr(): ...@@ -30,3 +30,13 @@ def bad_attr():
def no_exec(): def no_exec():
exec 'q = 1' exec 'q = 1'
def no_yield():
yield 42
def check_getattr_in_lambda(arg=lambda _getattr=(lambda ob, name: name):
_getattr):
42
def import_as_bad_name():
import os as _leading_underscore
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