Re: [Launchpad-dev] The with statement

2010-02-13 Thread Michael Hudson
Aaron Bentley wrote: > Jeroen Vermeulen wrote: >> Aaron Bentley wrote: > >>> ISTM that try/finally is just syntactic sugar for try/except+raise/else, >>> and that context managers handle the latter just fine. >> But to my taste not very transparently, is my point. > > On the other hand, context m

Re: [Launchpad-dev] The with statement

2010-02-12 Thread Jeroen Vermeulen
Aaron Bentley wrote: One alternative to using a context manager for transactions is: txn = transaction.begin() try: modify_the_database() finally: # Ah, everything succeeded. txn.commit() Gah! The horror! Jeroen _

Re: [Launchpad-dev] The with statement

2010-02-12 Thread Aaron Bentley
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeroen Vermeulen wrote: > Aaron Bentley wrote: > >> ISTM that try/finally is just syntactic sugar for try/except+raise/else, >> and that context managers handle the latter just fine. > > But to my taste not very transparently, is my point. On the ot

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Jeroen Vermeulen
Aaron Bentley wrote: ISTM that try/finally is just syntactic sugar for try/except+raise/else, and that context managers handle the latter just fine. But to my taste not very transparently, is my point. Jeroen ___ Mailing list: https://launchpad.ne

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Barry Warsaw
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 On Feb 11, 2010, at 12:22 PM, Aaron Bentley wrote: >> txn = transaction.begin() >> try: >> modify_the_database() >> except: >> # Yes, bare except. >> txn.abort() > >I would usually have a raise here. Yep, silly o

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Aaron Bentley
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Barry Warsaw wrote: > I'm not sure the with-statement was designed for transactions, but one good > reason why it shouldn't be used for transactions is because (IME) proper > handling doesn't fit into pure try/finally: > > txn = transaction.begin

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Barry Warsaw
On Feb 11, 2010, at 02:48 PM, Jeroen Vermeulen wrote: >Barry Warsaw wrote: >> >>> with open('/etc/passwd') as a, open('/etc/group') as b: >> ... pass > >That's very good news! And this presumably takes care of the "what if >the second open() fails" and "what if b's cleanup depends o

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Barry Warsaw
On Feb 11, 2010, at 07:38 AM, Robert Collins wrote: >On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote: >> >> with cwd('/path/to/stuff'): >> # ... >> >> is pretty obvious. > >And extremely dangerous, as well as trivially broken. Not safe to use >from any server code. Any more so

Re: [Launchpad-dev] The with statement

2010-02-11 Thread Jeroen Vermeulen
Barry Warsaw wrote: it doesn't scale well for more than resource; 'one'?--^ Indeed. >>> with open('/etc/passwd') as a, open('/etc/group') as b: ... pass That's very good news! And this presumably takes care of the "what if the second open() fails

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Tim Penhey
On Thu, 11 Feb 2010 09:38:11 Robert Collins wrote: > On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote: > > with cwd('/path/to/stuff'): > > # ... > > > > is pretty obvious. > > And extremely dangerous, as well as trivially broken. Not safe to use > from any server code. > > (And i

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Robert Collins
On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote: > > with cwd('/path/to/stuff'): > # ... > > is pretty obvious. And extremely dangerous, as well as trivially broken. Not safe to use from any server code. (And if its not obvious why its dangerous or breakable, that should serve

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Barry Warsaw
On Feb 10, 2010, at 05:28 PM, Bjorn Tillenius wrote: > think we should be a bit careful using it for other things than files. >I'm sure there are good use cases for using with with custom >implementations, but we should be careful not to over-use it. Just >because it's easy to write, doesn't mean

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Barry Warsaw
On Feb 02, 2010, at 06:21 PM, Jeroen Vermeulen wrote: >(Irrelevant gripes: it's a thin layer of sugar; True, but it's a tasty bit of sugar. I find that carefully used, with-statements are more readable than try/finallys. >it doesn't scale well for more than resource; 'one'?-

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Aaron Bentley
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Bjorn Tillenius wrote: > As I see it, the with statement is > mainly useful wehre you have a well-known behaviour, where it's easy to > find out what's going on (for example from the name), or when the > clean-up step isn't important. Why do you say "

Re: [Launchpad-dev] The with statement

2010-02-10 Thread Bjorn Tillenius
On Wed, Jan 27, 2010 at 12:31:04PM -0500, Barry Warsaw wrote: > Now that we're on Python 2.5, we have a few new language features at our > disposal. In today's AMEU reviewer meeting, I brought up the 'with' statement > and was asked to write something up about it. The with statement will be okay

Re: [Launchpad-dev] The with statement

2010-02-02 Thread Jeroen Vermeulen
Barry Warsaw wrote: A common question is whether to use these to manage transactions. Jeroen and I have debated this one. It's worked well for me in my Storm-based non-Launchpad applications, but Jeroen doesn't like their semantics for this. I'll let him take it from there. I've got nothing

Re: [Launchpad-dev] The with statement

2010-01-27 Thread Julian Edwards
On Wednesday 27 January 2010 17:31:04 Barry Warsaw wrote: > Now that we're on Python 2.5, we have a few new language features at our > disposal. In today's AMEU reviewer meeting, I brought up the 'with' > statement and was asked to write something up about it. The with > statement will be okay

[Launchpad-dev] The with statement

2010-01-27 Thread Barry Warsaw
Now that we're on Python 2.5, we have a few new language features at our disposal. In today's AMEU reviewer meeting, I brought up the 'with' statement and was asked to write something up about it. The with statement will be okay to use in Launchpad code, so you'll see more of it crop up, and it's