On Wed, May 18, 2022 at 12:24 PM Serhiy Storchaka <storch...@gmail.com>
wrote:

> try:
>      expression block
> expect Exception if condition else ():
>      expression block
>

That's an interesting idea I haven't seen before, but it doesn't work if
the condition you want to test depends on the exception object, which in my
experience it often does.

Some of OP's examples are of that form: for instance,
in setuptools/sandbox.py:

    try:
        ...
    except SystemExit as v:
        if v.args and v.args[0]:
            raise
        # Normal exit, just return

In pip/_internal/utils/misc.py:

    try:
        os.makedirs(path)
    except OSError as e:
        # Windows can raise spurious ENOTEMPTY errors. See #6426.
        if e.errno != errno.EEXIST and e.errno != errno.ENOTEMPTY:
            raise

I suppose the right way to implement it would be to support PEP 622
patterns in except clauses.

    except case SystemExit(args=args) if not args or not args[0]:
        pass  # Normal exit, just return

    except case OSError(errno = errno.EEXIST | errno.ENOTEMPTY):
        # Windows can raise spurious ENOTEMPTY errors. See #6426.
        pass
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JIJQFAXIS4TGURIMAZOGCBMEBYM6FXOD/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to