[issue33146] contextlib.suppress should capture exception for inspection and filter on substrings

Serhiy Storchaka report at bugs.python.org
Tue Mar 27 03:18:01 EDT 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

I'm not sure that contextlib.suppress() should be added at first place.

    try:
        os.remove(somefile)
    except FileNotFoundError:
        pass

is a tiny bit longer, but is more explicit, doesn't depend on the other module, works in all Python versions that have this exception, and is easily extensible.

    try:
        os.remove(somefile)
    except FileNotFoundError as e:
        # what do you want to do with e?
        pass

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33146>
_______________________________________


More information about the Python-bugs-list mailing list