Re: [Python-Dev] PEP 310 and exceptions

2005-04-24 Thread Nick Coghlan
Toby Dickenson wrote: On Sunday 24 April 2005 07:42, Nick Coghlan wrote: Shane Hathaway wrote: While we're on the subject of block handler method names, do the method names need four underscores? 'enter' and 'exit' look better than '__enter__' and '__exit__'. I quite like .acquire() and .releas

Re: [Python-Dev] PEP 310 and exceptions

2005-04-24 Thread Josiah Carlson
Toby Dickenson <[EMAIL PROTECTED]> wrote: > > On Sunday 24 April 2005 07:42, Nick Coghlan wrote: > > Shane Hathaway wrote: > > > > While we're on the subject of block handler method names, do the method > > > names need four underscores? 'enter' and 'exit' look better than > > > '__enter__' and

Re: [Python-Dev] PEP 310 and exceptions

2005-04-24 Thread Toby Dickenson
On Sunday 24 April 2005 07:42, Nick Coghlan wrote: > Shane Hathaway wrote: > > While we're on the subject of block handler method names, do the method > > names need four underscores? 'enter' and 'exit' look better than > > '__enter__' and '__exit__'. I quite like .acquire() and .release(). T

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Nick Coghlan
Shane Hathaway wrote: Nick Coghlan wrote: Which means finding a different name for '__else__'. Two possibilities that occur to me are '__ok__' or '__no_except__'. The latter makes a fair amount of sense, since I can't think of a way to refer to the thing other than as a 'no exception' handler. Wh

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Shane Hathaway
Nick Coghlan wrote: > Which means finding a different name for '__else__'. Two possibilities > that occur to me are '__ok__' or '__no_except__'. The latter makes a > fair amount of sense, since I can't think of a way to refer to the thing > other than as a 'no exception' handler. While we're on th

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Nick Coghlan
Aahz wrote: On Sat, Apr 23, 2005, Nick Coghlan wrote: In light of Alex's comments, I'd actually like to suggest the below as a potential new definition for PEP 310 (making __exit__ optional, and adding an __else__ handler): if hasattr(x, '__enter__'): x.__enter__() try: try:

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Nick Coghlan
Bernhard Herzog wrote: With the proposed implementation of PEP 310 rev. 1.5 it wouldn't work. sys.exc_info returns a tuple of Nones unless an except: clause has been entered. Either sys.exc_info() would have to be changed to always return exception information after an exception has been raised or

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Bernhard Herzog
Nick Coghlan <[EMAIL PROTECTED]> writes: > holger krekel wrote: >> Moreover, i think that there are more than the "transactional" >> use cases mentioned in the PEP. For example, a handler may want to >> log exceptions to some tracing utility or it may want to swallow >> certain exceptions when >>

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Phillip J. Eby
At 01:41 PM 4/23/05 +1000, Nick Coghlan wrote: Whichever way that point goes, this definition would allow PEP 310 to handle Alex's example of factoring out standardised exception handling, as well as the original use case of resource cleanup, and the transaction handling: class transaction(obje

__except__ use cases (was: Re: [Python-Dev] PEP 310 and exceptions)

2005-04-23 Thread holger krekel
On Sat, Apr 23, 2005 at 13:41 +1000, Nick Coghlan wrote: > Nick Coghlan wrote: > In light of Alex's comments, I'd actually like to suggest the below as a > potential new definition for PEP 310 (making __exit__ optional, and adding > an __else__ handler): > > if hasattr(x, '__enter__'): >

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread Aahz
On Sat, Apr 23, 2005, Nick Coghlan wrote: > > In light of Alex's comments, I'd actually like to suggest the below as a > potential new definition for PEP 310 (making __exit__ optional, and adding > an __else__ handler): > > if hasattr(x, '__enter__'): > x.__enter__() > try: >

Re: [Python-Dev] PEP 310 and exceptions

2005-04-23 Thread holger krekel
On Fri, Apr 22, 2005 at 19:03 -0700, Josiah Carlson wrote: > [EMAIL PROTECTED] (holger krekel) wrote: > > basically translates to: > > > > if hasattr(x, '__enter__'): > > x.__enter__() > > try: > > ... > > except: > > if hasattr(x, '__except__'): x.__excep

Re: [Python-Dev] PEP 310 and exceptions

2005-04-22 Thread Nick Coghlan
Nick Coghlan wrote: Alternately, PEP 310 could be defined as equivalent to: if hasattr(x, '__enter__'): x.__enter__() try: try: ... except: if hasattr(x, '__except__'): x.__except__(*sys.exc_info()) else:

Re: [Python-Dev] PEP 310 and exceptions

2005-04-22 Thread Alex Martelli
On Apr 22, 2005, at 16:51, holger krekel wrote: Moreover, i think that there are more than the "transactional" use cases mentioned in the PEP. For example, a handler may want to log exceptions to some tracing utility or it may want to swallow certain exceptions when its block does IO operations th

[Python-Dev] PEP 310 and exceptions

2005-04-22 Thread holger krekel
Hi all, probably unsuprisingly i am still pondering the idea of having an optional __except__ hook on block handlers. The PEP says this about this: An extension to the protocol to include an optional __except__ handler, which is called when an exception is raised, and which can han

Re: [Python-Dev] PEP 310 and exceptions

2005-04-22 Thread Josiah Carlson
[EMAIL PROTECTED] (holger krekel) wrote: > basically translates to: > > if hasattr(x, '__enter__'): > x.__enter__() > try: > ... > except: > if hasattr(x, '__except__'): x.__except__(...) > else: x.__exit__() > else: > x.__exit__()

Re: [Python-Dev] PEP 310 and exceptions

2005-04-22 Thread Nick Coghlan
holger krekel wrote: Moreover, i think that there are more than the "transactional" use cases mentioned in the PEP. For example, a handler may want to log exceptions to some tracing utility or it may want to swallow certain exceptions when its block does IO operations that are ok to fail. With