On Wed, 11 May 2005, Guido van Rossum wrote: > [Steven Bethard] > > exc = () > > try: > > try: > > BLOCK1 > > except: > > exc = sys.exc_info() > > finally: > > stmt_exit(*exc) > > > > would this make any of the examples impossible to write? All you have > > to do to suppress an exception is to not reraise it in __exit__. > > But this use case would contain a trap for the unwary user who is > writing an __exit__ method -- they have to remember to re-raise an > exception if it was passed in, but that's easy to forget (and slightly > tricky since you have to check the arg count or whether the first > argument is not None).
Then wouldn't it be simplest to separate normal exit from exceptional exit? That is, split __exit__ into __except__ and __finally__. If __except__ is defined, then it handles the exception, otherwise the exception is raised normally. > class locking: > def __init__(self, lock): self.lock = lock > def __enter__(self): self.lock.acquire() > def __exit__(self, *args): self.lock.release() Having __exit__ take varargs is a signal to me that it mashes together what really are two different methods. -- ?!ng _______________________________________________ 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