Re: [Python-Dev] PEP 343 - Abstract Block Redux

2005-05-15 Thread Arnold deVos
Guido van Rossum wrote:
> [...] But some of the claims from PEP 3XX seem to be incorrect now: Nick
> claims that a with-statement can abstract an except clause, but that's
> not the case; [...]

Sorry for being a lurker, but can I try and expand this point.

The options:

- If we don't allow the except clause in the generator, the exception 
can't be examined there.

- If we do allow the except clause we must (IMO) also allow the 
generator to suppress the exception. It would be surprising behaviour if 
an a caught exception was re-raised without an explicit raise statement.

An argument:

Despite the control-flow-macros-are-harmful discussion, I see nothing 
wrong with a block controller swallowing its block's exceptions because:

- In most proposals it can raise its own exception in place of the 
block's exception anyway.

- In the following example there is nothing surprising if controller() 
swallows block()'s exception:

def block():
# do stuff
raise E
controller(block)

Perhaps we don't want the block controller statement to have as much 
power over its block as controller() has over block() above. But 
handling an exception is not so radical is it?

- Arnold.

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 343 rewrite complete

2005-06-02 Thread Arnold deVos
Guido van Rossum wrote:
> [Phillip J. Eby]
>>* The transaction handler could also be written as:
>>
>> @with_template
>> def transactional(db):
>> db.begin()
>> try:
>> yield db
>> except:
>> db.rollback()
>> else:
>> db.commit()
>>
>>at least, if I understand it correctly.
> 
> 
> Ah, of course. I've updated the PEP.
> 

This template eats eats the exception, which will cause a RuntimeError
in the proposed Wrapper, I think.  A raise after rollback is needed.

- Arnold
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 343 rewrite complete

2005-06-02 Thread Arnold deVos
Arnold deVos wrote:
> 
> This template eats eats the exception, which will cause a RuntimeError
> in the proposed Wrapper, I think.  A raise after rollback is needed.

Actually, the Wrapper as written in the PEP does not raise RuntimeError
if the generator catches a block's exception.

Shouldn't the relevant clause in the Wrapper go like this:

try:
self.gen.throw(type, value, traceback)
except type:
return
except StopIteration:
raise RuntimeError("generator caught exception")
else:
raise RuntimeError("generator didn't stop")

And the transaction template would go like this (re-raising the exception):

@with_template
def transactional(db):
db.begin()
try:
yield None
except:
db.rollback()
raise
else:
db.commit()

At least this is what I gleaned from the earlier threads.  It means that
the template does not appear to supress an exception that it cannot
actually supress.

- Arnold

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 343 rewrite complete

2005-06-02 Thread Arnold deVos
Guido van Rossum wrote:
> 
>[...] a generator doing cleanup depending on the
>exception thrown (like the transactional() example below) can
>*catch* the exception thrown if it wants to and doesn't have to
>worry about re-raising it.  I find this more convenient for the
>generator writer.  Against this was brought in that the
>generator *appears* to suppress an exception that it cannot
>suppress: the transactional() example would be more clear
>according to this view if it re-raised the original exception
>after the call to db.rollback().  [...]

Of course, the explicit re-raise is only needed in a minority of use 
cases where the exception is caught. Two additional points in favour of 
this:

- refactoring a naked try as a with + template is more direct and 
uniform across all use cases.

- it is upwards compatible if the prohibition on templates suppressing 
exceptions is ever reconsidered. (Flow control macro discussion not 
withstanding.)

- Arnold

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com