[pypy-commit] pypy py3k: Fix compiler: the exception handler target is now a NAME
amauryfa
noreply at buildbot.pypy.org
Sat Dec 17 23:01:10 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r50642:3f837e62c8c0
Date: 2011-12-17 22:04 +0100
http://bitbucket.org/pypy/pypy/changeset/3f837e62c8c0/
Log: Fix compiler: the exception handler target is now a NAME (and not
any assignment target as before). Still missing: the deletion of the
target after the "except:" block.
diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -2229,8 +2229,6 @@
def mutate_over(self, visitor):
if self.type:
self.type = self.type.mutate_over(visitor)
- if self.name:
- self.name = self.name.mutate_over(visitor)
if self.body:
visitor._mutate_sequence(self.body)
return visitor.visit_ExceptHandler(self)
@@ -2245,8 +2243,6 @@
self.name = None
if self.type:
self.type.sync_app_attrs(space)
- if self.name:
- self.name.sync_app_attrs(space)
w_list = self.w_body
if w_list is not None:
list_w = space.listview(w_list)
@@ -2699,8 +2695,6 @@
def visit_ExceptHandler(self, node):
if node.type:
node.type.walkabout(self)
- if node.name:
- node.name.walkabout(self)
self.visit_sequence(node.body)
def visit_arguments(self, node):
@@ -6718,9 +6712,10 @@
def ExceptHandler_set_name(space, w_self, w_new_value):
try:
- w_self.name = space.interp_w(expr, w_new_value, True)
- if type(w_self.name) is expr:
- raise OperationError(space.w_TypeError, space.w_None)
+ if space.is_w(w_new_value, space.w_None):
+ w_self.name = None
+ else:
+ w_self.name = space.str_w(w_new_value)
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -364,16 +364,16 @@
def handle_except_clause(self, exc, body):
test = None
- target = None
+ name = None
suite = self.handle_suite(body)
child_count = len(exc.children)
if child_count >= 2:
test = self.handle_expr(exc.children[1])
if child_count == 4:
- target_child = exc.children[3]
- target = self.handle_expr(target_child)
- self.set_context(target, ast.Store)
- return ast.ExceptHandler(test, target, suite, exc.lineno, exc.column)
+ name_node = exc.children[3]
+ name = name_node.value
+ self.check_forbidden_name(name, name_node)
+ return ast.ExceptHandler(test, name, suite, exc.lineno, exc.column)
def handle_try_stmt(self, try_node):
body = self.handle_suite(try_node.children[2])
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -524,7 +524,7 @@
self.emit_jump(ops.POP_JUMP_IF_FALSE, next_except, True)
self.emit_op(ops.POP_TOP)
if handler.name:
- handler.name.walkabout(self)
+ self.name_op(handler.name, ast.Store);
else:
self.emit_op(ops.POP_TOP)
self.emit_op(ops.POP_TOP)
diff --git a/pypy/interpreter/astcompiler/tools/Python.asdl b/pypy/interpreter/astcompiler/tools/Python.asdl
--- a/pypy/interpreter/astcompiler/tools/Python.asdl
+++ b/pypy/interpreter/astcompiler/tools/Python.asdl
@@ -101,7 +101,7 @@
comprehension = (expr target, expr iter, expr* ifs)
-- not sure what to call the first argument for raise and except
- excepthandler = ExceptHandler(expr? type, expr? name, stmt* body)
+ excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
attributes(int lineno, int col_offset)
arguments = (expr* args, identifier? vararg,
diff --git a/pypy/interpreter/pyparser/pytoken.py b/pypy/interpreter/pyparser/pytoken.py
--- a/pypy/interpreter/pyparser/pytoken.py
+++ b/pypy/interpreter/pyparser/pytoken.py
@@ -35,6 +35,7 @@
_add_tok('EQUAL', "=" )
_add_tok('DOT', "." )
_add_tok('PERCENT', "%" )
+_add_tok('BACKQUOTE', "`" )
_add_tok('LBRACE', "{" )
_add_tok('RBRACE', "}" )
_add_tok('EQEQUAL', "==" )
diff --git a/pypy/module/atexit/app_atexit.py b/pypy/module/atexit/app_atexit.py
--- a/pypy/module/atexit/app_atexit.py
+++ b/pypy/module/atexit/app_atexit.py
@@ -25,7 +25,7 @@
continue
try:
func(*args, **kwargs)
- except BaseException, e:
+ except BaseException as e:
if not isinstance(e, SystemExit):
import traceback
last_type, last_exc, last_tb = sys.exc_info()
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -71,7 +71,7 @@
return
try:
fcntl.fcntl(fd, fcntl.F_GETFD)
- except IOError, e:
+ except IOError as e:
raise OSError(e.errno, e.strerror, e.filename)
else:
def _validate_fd(fd):
More information about the pypy-commit
mailing list