[Python-Dev] Simpler finalization semantics (was Re: PEP 343 - Abstract Block Redux)

Michael Chermside mcherm at mcherm.com
Thu May 19 01:39:18 CEST 2005


Guido writes:

  [a rather silly objection to Phillip's proposal that 'with x:' is
   a no-op when x lacks __enter__ and __exit__]

> I know this is not a very strong argument, but my gut tells me this
> generalization of the with-statement is wrong, so I'll stick to it
> regardless of the strength of the argument. The real reason will come
> to me.

Perhaps the real reason is that it allows errors to pass silently.

If I write

    with foo:
       BLOCK

where I should have written

    with locked(foo):
       BLOCK

...it silently "succeeds" by doing nothing. I CLEARLY intended to
do the appropriate cleanup (or locking, or whatever), but it doesn't
happen.

-- Michael Chermside



More information about the Python-Dev mailing list