Re: A "scopeguard" for Python

2010-03-08 Thread sstein...@gmail.com
On Mar 8, 2010, at 7:28 AM, Steve Holden wrote: >> >> But your response, both the out of context quoting and your comment, >> seems solely designed to convey a negative impression instead of >> addressing any technical issue. >> > This isn't an isolated case, Alf. Physician, heal thyself. As fa

Re: A "scopeguard" for Python

2010-03-08 Thread Steve Holden
Alf P. Steinbach wrote: > * Gabriel Genellina: >> En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach >> escribió: >> >>> Sorry, as with the places noted above, I can't understand what you're >>> trying to say here. >> >> Regarding your posts, neither can I. All the time. Sorry, deciphering >> yo

Re: A "scopeguard" for Python

2010-03-07 Thread Alf P. Steinbach
* Gabriel Genellina: En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach escribió: Sorry, as with the places noted above, I can't understand what you're trying to say here. Regarding your posts, neither can I. All the time. Sorry, deciphering your posts would force me to spend much more t

Re: A "scopeguard" for Python

2010-03-07 Thread Gabriel Genellina
En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach escribió: Sorry, as with the places noted above, I can't understand what you're trying to say here. Regarding your posts, neither can I. All the time. Sorry, deciphering your posts would force me to spend much more time than available

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 09:39 AM, Mike Kent wrote: What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup A custo

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Steve Howell: On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even wh

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Mike Kent: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. This raises the exception insid

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-05 10:29 AM, Mike Kent wrote: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. Thi

Re: A "scopeguard" for Python

2010-03-05 Thread Steve Howell
On Mar 4, 5:04 pm, Robert Kern wrote: > On 2010-03-04 15:19 PM, Mike Kent wrote: > > > > > On Mar 3, 12:00 pm, Robert Kern  wrote: > >> On 2010-03-03 09:39 AM, Mike Kent wrote: > > >>> What's the compelling use case for this vs. a simple try/finally? > > >>>      original_dir = os.getcwd() > >>>  

Re: A "scopeguard" for Python

2010-03-05 Thread Steve Howell
On Mar 5, 8:29 am, Mike Kent wrote: > On Mar 4, 8:04 pm, Robert Kern wrote: > > > No, the try: finally: is not implicit. See the source for > > contextlib.GeneratorContextManager. When __exit__() gets an exception from > > the > > with: block, it will push it into the generator using its .throw(

Re: A "scopeguard" for Python

2010-03-05 Thread Mike Kent
On Mar 4, 8:04 pm, Robert Kern wrote: > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. > This > raises the exception inside the

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 16:27 , Alf P. Steinbach wrote: * Mike Kent: However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wan

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 17:52 , Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly fa

Re: A "scopeguard" for Python

2010-03-05 Thread Jean-Michel Pichavant
Robert Kern wrote: On 2010-03-04 15:12 , Mike Kent wrote: On Mar 4, 12:30 pm, Robert Kern wrote: He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. No, I was referring to Jean-Michel, who

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 17:52 , Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly failing operation

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 15:12 , Mike Kent wrote: On Mar 4, 12:30 pm, Robert Kern wrote: He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. No, I was referring to Jean-Michel, who was not familiar wi

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 16:27 , Alf P. Steinbach wrote: * Mike Kent: However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wanted the chdir to

Re: A "scopeguard" for Python

2010-03-04 Thread Steve Howell
On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: > For C++ Petru Marginean once invented the "scope guard" technique (elaborated > on > by Andrei Alexandrescu, they published an article about it in DDJ) where all > you > need to do to ensure some desired cleanup at the end of a scope, even when the

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Steve Holden: Alf P. Steinbach wrote: * Robert Kern: [...] No, it only argues that "with Cleanup():" is supernumerary. I don't know what "supernumerary" means, but to the degree that the argument says anything about a construct that is not 'finally', it says the same about general "with".

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 15:19 PM, Mike Kent wrote: On Mar 3, 12:00 pm, Robert Kern wrote: On 2010-03-03 09:39 AM, Mike Kent wrote: What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff f

Re: A "scopeguard" for Python

2010-03-04 Thread Steve Holden
Alf P. Steinbach wrote: > * Robert Kern: [...] >> No, it only argues that "with Cleanup():" is supernumerary. > > I don't know what "supernumerary" means, but to the degree that the > argument says anything about a construct that is not 'finally', it says > the same about general "with". > So rat

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly failing operation "A", then that systematic approach goes like t

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly failing operation "A", then that systematic approach goes like this: if A fails,

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Mike Kent: On Mar 4, 12:30 pm, Robert Kern wrote: He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. Given only your example of the with: statement, it is hard to fault him for thinking

Re: A "scopeguard" for Python

2010-03-04 Thread Mike Kent
On Mar 3, 12:00 pm, Robert Kern wrote: > On 2010-03-03 09:39 AM, Mike Kent wrote: > > > What's the compelling use case for this vs. a simple try/finally? > > >     original_dir = os.getcwd() > >     try: > >         os.chdir(somewhere) > >         # Do other stuff > >     finally: > >         os.c

Re: A "scopeguard" for Python

2010-03-04 Thread Mike Kent
On Mar 4, 12:30 pm, Robert Kern wrote: > He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. > Given only your > example of the with: statement, it is hard to fault him for thinking that try: >

Re: A "scopeguard" for Python

2010-03-04 Thread Mike Kent
On Mar 3, 10:56 am, "Alf P. Steinbach" wrote: > * Mike Kent: > > > What's the compelling use case for this vs. a simple try/finally? > > if you thought about it you would mean a simple "try/else". "finally" is > always > executed. which is incorrect for cleanup > > by the way, that's one advantag

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly failing operation "A", then that systematic approach goes like this: if A fails, then it has cleaned up its own mess, but if A su

Re: A "scopeguard" for Python

2010-03-04 Thread Jean-Michel Pichavant
Michael Rudolf wrote: Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: It looks like to me that 'with' statements are like decorators: overrated. Oh no, you just insulted my favourite two python features, followed immediately by generators, iterators and list comprehensions / generator ex

Re: A "scopeguard" for Python

2010-03-04 Thread Michael Rudolf
Am 04.03.2010 18:20, schrieb Robert Kern: What I'm trying to explain is that the with: statement has a use even if Cleanup doesn't. Arguing that Cleanup doesn't improve on try: finally: does not mean that the with: statement doesn't improve on try: finally:. Yes, the with-statement rocks :) I

Re: A "scopeguard" for Python

2010-03-04 Thread Michael Rudolf
Am 04.03.2010 17:32, schrieb Jean-Michel Pichavant: It looks like to me that 'with' statements are like decorators: overrated. Oh no, you just insulted my favourite two python features, followed immediately by generators, iterators and list comprehensions / generator expressions :p No, real

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 11:02 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: * Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exite

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: * Robert Kern: [snip] can you understand why we might think that you were saying that try: finally: was wrong and that you were proposing that your code was equivalent to some try: e

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: * Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the t

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 10:32 AM, Jean-Michel Pichavant wrote: Alf P. Steinbach wrote: * Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precis

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: * Robert Kern: [snip] can you understand why we might think that you were saying that try: finally: was wrong and that you were proposing that your code was equivalent to some try: except: else: suite? No, not really. His code d

Re: A "scopeguard" for Python

2010-03-04 Thread Jean-Michel Pichavant
Alf P. Steinbach wrote: * Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syntax is for. You'd

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-04 09:48 AM, Alf P. Steinbach wrote: * Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syn

Re: A "scopeguard" for Python

2010-03-04 Thread Alf P. Steinbach
* Jean-Michel Pichavant: Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syntax is for. You'd have to nest it. That's u

Re: A "scopeguard" for Python

2010-03-04 Thread Robert Kern
On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinba

Re: A "scopeguard" for Python

2010-03-04 Thread Jean-Michel Pichavant
Alf P. Steinbach wrote: From your post, the scope guard technique is used "to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception." This is precisely what the try: finally: syntax is for. You'd have to nest it. That's ugly. And more importantly,

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling us

Re: A "scopeguard" for Python

2010-03-03 Thread Robert Kern
On 2010-03-03 15:35 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about

Re: A "scopeguard" for Python

2010-03-03 Thread Robert Kern
On 2010-03-03 13:32 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mea

Re: A "scopeguard" for Python

2010-03-03 Thread Jerry Hill
On Wed, Mar 3, 2010 at 2:32 PM, Alf P. Steinbach wrote: > I'm not sure what that shows, except that you haven't grokked this yet. Maybe you could give us an example of how your code should be used, and how it differs from the other examples people have given? And maybe a quick example of why you

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always exec

Re: A "scopeguard" for Python

2010-03-03 Thread Robert Kern
On 2010-03-03 11:18 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is inc

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup Eh? Failed execution doesn't

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 09:39 AM, Mike Kent wrote: What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup A custo

Re: A "scopeguard" for Python

2010-03-03 Thread Robert Kern
On 2010-03-03 09:56 AM, Alf P. Steinbach wrote: * Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup Eh? Failed execution doesn't require cleanup

Re: A "scopeguard" for Python

2010-03-03 Thread Robert Kern
On 2010-03-03 09:39 AM, Mike Kent wrote: What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup A custom-written contex

Re: A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
* Mike Kent: What's the compelling use case for this vs. a simple try/finally? if you thought about it you would mean a simple "try/else". "finally" is always executed. which is incorrect for cleanup by the way, that's one advantage: a "with Cleanup" is difficult to get wrong, while a "try"

Re: A "scopeguard" for Python

2010-03-03 Thread Mike Kent
What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup -- http://mail.python.org/mailman/listinfo/python-list

A "scopeguard" for Python

2010-03-03 Thread Alf P. Steinbach
For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even when the scope is exited via an exception, is to declare a Scope