[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r1156375 - /subversion/branches/fs-py/subversion/python/svn/fs.py

From: Greg Stein <gstein_at_gmail.com>
Date: Wed, 10 Aug 2011 19:35:31 -0400

On Wed, Aug 10, 2011 at 19:15, Branko Čibej <brane_at_xbc.nu> wrote:
>...
> Explicit management of rare resources is no bad thing. The "with"
> statement was introduced specifically to do away with the flaky, three
> times longer try-except-else that would otherwise be necessary in order
> to guarantee that file objects are closed.

With the prior constructions:

open(foo).read()
open(foo, 'w').write(bar)

If one of those .read() or .write() calls fails, *and* somebody does
not clear the traceback... then yeah. A file remains open, referenced
from the traceback. But somebody has to be explicitly *keeping* those
tracebacks. I've never seen code where people keep lists of
tracebacks. I cannot even speculate on why somebody might use svn.fs,
capture tracebacks, hold onto them, and then *continue* trying to use
svn.fs.

Switching to:

with open(foo) as f:
  f.read()

You're going from a single expression to a control flow construct,
simply to try and avoid a situation that I doubt anybody could even
begin to argue would come up.

> And yes, the CPython docs do say that file objects are closed when their
> refcount reaches zero, but also state that one shouldn't rely on that.
> Also see the second stanza in PEP 20. :)

Ha! And the third stanza says "Simple is better than complex."

> There's no call to jump all over people because you don't agree with
> their coding style.

If you call that "jump[ing] all over people", then I think you're
taking it wrong. I'm providing review feedback where I see a simple
construction being turned into something more complicated.

Cheers,
-g
Received on 2011-08-11 01:35:58 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.