[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

Cooper Lees report at bugs.python.org
Tue Feb 22 13:19:47 EST 2022


Cooper Lees <me at cooperlees.com> added the comment:

Ok thanks. Looks like the warning in flake8-bugbear is the right place then, unfortunately.

And just to be sure:

> Note that suppress without arguments corresponds to "except" and isinstance() with empty tuple.

Are you saying that `contextlib.suppress()` should effectively `except BaseException` (cause this is not the behavior from my tests) and suppress all or suppress nothing? I believe the empty tuple makes it except nothing?

```python
cooper at home1:~$ python3.11
Python 3.11.0a5+ (main, Feb 22 2022, 08:51:50) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import contextlib
>>> with contextlib.suppress():
...   raise ValueError("I raise ...")
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError: I raise ...
>>>
```

----------

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


More information about the Python-bugs-list mailing list