Re: [Python-Dev] __exit__ API?

2006-03-08 Thread Guido van Rossum
I have a patch for this now -- python.org/sf/1445739.

Please review.

--Guido

On 3/3/06, Guido van Rossum [EMAIL PROTECTED] wrote:
 A few days ago there were rumbling noises that requiring __exit__ to
 re-raise the exception (as I amended PEP 343 at the time) could lead
 to easily-missed bugs in __exit__ handlers.

 After thinking it over I think I agree and I think I'd like to change
 the API so that the exception is only ignored if __exit__ returns a
 true value.

 The easiest implementation is probably to just let the WITH_CLEANUP
 opcode do everything. This becomes a rather heavy opcode then but the
 alternative is to generate very hairy code (like the original patch
 did, full of ROT 4 choruses).

 Any objections? I probably won't get to this until Monday.

 --
 --Guido van Rossum (home page: http://www.python.org/~guido/)



--
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
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] __exit__ API?

2006-03-04 Thread Nick Coghlan
Guido van Rossum wrote:
 A few days ago there were rumbling noises that requiring __exit__ to
 re-raise the exception (as I amended PEP 343 at the time) could lead
 to easily-missed bugs in __exit__ handlers.
 
 After thinking it over I think I agree and I think I'd like to change
 the API so that the exception is only ignored if __exit__ returns a
 true value.
 
 The easiest implementation is probably to just let the WITH_CLEANUP
 opcode do everything. This becomes a rather heavy opcode then but the
 alternative is to generate very hairy code (like the original patch
 did, full of ROT 4 choruses).
 
 Any objections? I probably won't get to this until Monday.

Sounds good to me - I believe the majority of explicit __exit__ handlers will 
be of a try/finally nature rather than try/except, and that situations where 
the exception is going to be suppressed are better handled using 
@contextmanager.

The solution you propose means that __exit__ methods *can* suppress exceptions 
if they want to, but their default behaviour will still do the right thing.

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
 http://www.boredomandlaziness.org
___
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


[Python-Dev] __exit__ API?

2006-03-03 Thread Guido van Rossum
A few days ago there were rumbling noises that requiring __exit__ to
re-raise the exception (as I amended PEP 343 at the time) could lead
to easily-missed bugs in __exit__ handlers.

After thinking it over I think I agree and I think I'd like to change
the API so that the exception is only ignored if __exit__ returns a
true value.

The easiest implementation is probably to just let the WITH_CLEANUP
opcode do everything. This becomes a rather heavy opcode then but the
alternative is to generate very hairy code (like the original patch
did, full of ROT 4 choruses).

Any objections? I probably won't get to this until Monday.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
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