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

_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to