[Python-3000] Betas today - I hope
Georg Brandl
g.brandl at gmx.net
Fri Jun 13 00:13:45 CEST 2008
Nick Coghlan schrieb:
> 2. Method lookup MAY bypass __getattribute__, shadowing the attribute in
> the instance dictionary MAY have ill effects. (slots such as __enter__
> and __exit__ that are looked up via normal attribute lookup in CPython
> will fit into this category)
I would argue that the __enter__ and __exit__ behavior should be changed too.
The reason for the current behavior is this:
2 0 LOAD_GLOBAL 0 (a)
3 DUP_TOP
4 LOAD_ATTR 1 (__exit__)
7 STORE_FAST 0 (_[1])
10 LOAD_ATTR 2 (__enter__)
13 CALL_FUNCTION 0
16 STORE_FAST 1 (_[2])
19 SETUP_FINALLY 18 (to 40)
IOW, when "with" is compiled, the attributes are retrieved using bytecode.
It wouldn't be hard to have a WITH_SETUP opcode (along with the already
existing WITH_CLEANUP) that would make the bytecode read like:
2 0 LOAD_GLOBAL 0 (a)
3 WITH_SETUP 0 (_[1])
6 STORE_FAST 1 (_[2])
9 SETUP_FINALLY 18 (to 40)
Georg
More information about the Python-3000
mailing list