[Python-Dev] PEP 343 and with (original) (raw)
Guido van Rossum guido at python.org
Tue Oct 4 16:54:15 CEST 2005
- Previous message: [Python-Dev] PEP 343 and __with__
- Next message: [Python-Dev] PEP 343 and __with__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/4/05, Jason Orendorff <jason.orendorff at gmail.com> wrote:
This:
with EXPR as VAR: BLOCK expands to this under PEP 342: cm = contextmanager(EXPR) VAR = cm.next() try: BLOCK except: try: cm.throw(*sys.excinfo()) except: pass raise finally: try: cm.next() except StopIteration: pass except: raise else: raise RuntimeError
Where in the world do you get this idea? The translation is as follows, according to PEP 343:
abc = EXPR
exc = (None, None, None)
VAR = abc.__enter__()
try:
try:
BLOCK
except:
exc = sys.exc_info()
raise
finally:
abc.__exit__(*exc)
PEP 342 doesn't touch on the expansion of with-statements at all.
I think I know where you're coming from, but please do us a favor and don't misrepresent the PEPs. If anything, your proposal is more complicated; it requires four new APIs instead of two, and requires an extra call to set up (with() followed by start()).
Proposals like yours (and every other permutation) were brought up during the initial discussion. We picked one. Don't create more churn by arguing for a different variant. Spend your efforts on implementing it so you can actually use it and see how bad it is (I predict it won't be bad at all).
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 343 and __with__
- Next message: [Python-Dev] PEP 343 and __with__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]