diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-12 20:23:23 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-12 20:23:23 (GMT) |
commit | 4e1be72e6babf857d9f263b087dae3123ac8efe1 (patch) | |
tree | 893b3b47a6a83f4beaaa1d31636ea98a0e1a6b01 | |
parent | babe326c65a3d00c0f236628a17e39df81bcf13d (diff) | |
download | cpython-4e1be72e6babf857d9f263b087dae3123ac8efe1.zip cpython-4e1be72e6babf857d9f263b087dae3123ac8efe1.tar.gz cpython-4e1be72e6babf857d9f263b087dae3123ac8efe1.tar.bz2 |
Fix SF bug #116263: support for from .. import *
transformer.py: return '*', None from com_import_as_name
pycodegen.py: special case for name == '*'
pyassem.py: fix stack counting for IMPORT_ opcodes
-rw-r--r-- | Lib/compiler/pyassem.py | 4 | ||||
-rw-r--r-- | Lib/compiler/pycodegen.py | 11 | ||||
-rw-r--r-- | Lib/compiler/transformer.py | 2 | ||||
-rw-r--r-- | Tools/compiler/compiler/pyassem.py | 4 | ||||
-rw-r--r-- | Tools/compiler/compiler/pycodegen.py | 11 | ||||
-rw-r--r-- | Tools/compiler/compiler/transformer.py | 2 |
6 files changed, 26 insertions, 8 deletions
diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py index 74ea562..3411273 100644 --- a/Lib/compiler/pyassem.py +++ b/Lib/compiler/pyassem.py @@ -515,12 +515,14 @@ class StackDepthTracker: 'BUILD_MAP': 1, 'COMPARE_OP': -1, 'STORE_FAST': -1, + 'IMPORT_STAR': -1, + 'IMPORT_NAME': 0, + 'IMPORT_FROM': 1, } # use pattern match patterns = [ ('BINARY_', -1), ('LOAD_', 1), - ('IMPORT_', 1), ] # special cases: diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index 2a1b308..2888729 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -439,9 +439,14 @@ class CodeGenerator: for name, alias in node.names: if name == '*': self.namespace = 0 - self.emit('IMPORT_FROM', name) - self._resolveDots(name) - self.storeName(alias or name) + self.emit('IMPORT_STAR') + # There can only be one name w/ from ... import * + assert len(node.names) == 1 + return + else: + self.emit('IMPORT_FROM', name) + self._resolveDots(name) + self.storeName(alias or name) self.emit('POP_TOP') def _resolveDots(self, name): diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index 91d4b5b..c8a8518 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -825,6 +825,8 @@ class Transformer: return dot, node[3][1] def com_import_as_name(self, node): + if node == '*': + return '*', None if node[0] == token.NAME: return node[1], None assert len(node) == 4 diff --git a/Tools/compiler/compiler/pyassem.py b/Tools/compiler/compiler/pyassem.py index 74ea562..3411273 100644 --- a/Tools/compiler/compiler/pyassem.py +++ b/Tools/compiler/compiler/pyassem.py @@ -515,12 +515,14 @@ class StackDepthTracker: 'BUILD_MAP': 1, 'COMPARE_OP': -1, 'STORE_FAST': -1, + 'IMPORT_STAR': -1, + 'IMPORT_NAME': 0, + 'IMPORT_FROM': 1, } # use pattern match patterns = [ ('BINARY_', -1), ('LOAD_', 1), - ('IMPORT_', 1), ] # special cases: diff --git a/Tools/compiler/compiler/pycodegen.py b/Tools/compiler/compiler/pycodegen.py index 2a1b308..2888729 100644 --- a/Tools/compiler/compiler/pycodegen.py +++ b/Tools/compiler/compiler/pycodegen.py @@ -439,9 +439,14 @@ class CodeGenerator: for name, alias in node.names: if name == '*': self.namespace = 0 - self.emit('IMPORT_FROM', name) - self._resolveDots(name) - self.storeName(alias or name) + self.emit('IMPORT_STAR') + # There can only be one name w/ from ... import * + assert len(node.names) == 1 + return + else: + self.emit('IMPORT_FROM', name) + self._resolveDots(name) + self.storeName(alias or name) self.emit('POP_TOP') def _resolveDots(self, name): diff --git a/Tools/compiler/compiler/transformer.py b/Tools/compiler/compiler/transformer.py index 91d4b5b..c8a8518 100644 --- a/Tools/compiler/compiler/transformer.py +++ b/Tools/compiler/compiler/transformer.py @@ -825,6 +825,8 @@ class Transformer: return dot, node[3][1] def com_import_as_name(self, node): + if node == '*': + return '*', None if node[0] == token.NAME: return node[1], None assert len(node) == 4 |