On 6/20/05, Dmitry Dvoinikov <[EMAIL PROTECTED]> wrote:
> Excuse me if I couldn't find that in the existing PEPs, but
> wouldn't that be useful to have a construct that explicitly
> tells that we know an exception of specific type could happen
> within a block, like:
> ignore TypeError:
> do stuff
> [else:
> do other stuff]
If I understand PEP 343 correctly, it allows for easy implementation
of part of your request. It doesn't implement the else: clause, but
you don't give a use case for it either.
class ignored_exceptions(object):
def __init__(self, *exceptions):
self.exceptions = exceptions
def __enter__(self):
return None
def __exit__(self, type, value, traceback):
try:
raise type, value, traceback
except self.exceptions:
pass
with ignored_exceptions(SomeError):
do stuff
I don't see the use, but it's possible.
> The reason for that being self-tests with lots and lots of
> little code snippets like this:
If you're trying to write tests, perhaps a better use-case would be
something like:
with required_exception(SomeError):
do something that should cause SomeError
paul
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com