[New-bugs-announce] [issue12635] use "as" for block scope support

HaiYun Yan report at bugs.python.org
Mon Jul 25 09:36:47 CEST 2011

New submission from HaiYun Yan <lyricconch at gmail.com>:

use "as" for block scope support
just like mozilla javascript "let" extension


as_clause(as_declare): "as" NAME
as_stmt: NAME "as" test
as_expr: "(" expr "as" NAME ")" expr

var declare by as_clause is alive in <suite> only
<NAME "f" binding saved>with open(...) as f<NAME "f" bind to HEAPObj>:
<NAME "f" binding restored>

the same rule to "except E as e: "

from socket import AF_INET as IPv4
<IPv4 bind to socket.AF_INET slot>
IPv4 = None
assert socket.AF_INET == None

var in as_stmt is alive in current indentation
for i in range(10):
   <NAME "t" binding saved>
   t as f()+1 <NAME "t" bind to f()+1>
   <NAME "t" binding restored>

var in as_expr is alive in sub expr only
t = None
x = (2+3 as t) t**2
assert t == None ane  x == 25

new opcode
ENTER_BLOCK #depth #varslots

components: Interpreter Core
messages: 141076
nosy: lyricconch
priority: normal
severity: normal
status: open
title: use "as" for block scope support
type: feature request

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list