[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
https://developer.mozilla.org/en/new_in_javascript_1.7#Block_scope_with_let_%28Merge_into_let_Statement%29
usage:
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
eg:
<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: "
spec:
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
eg:
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
eg:
t = None
x = (2+3 as t) t**2
assert t == None ane x == 25
Suggestion:
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>
<http://bugs.python.org/issue12635>
_______________________________________
More information about the Python-bugs-list
mailing list