[New-bugs-announce] [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
Mon Feb 21 12:26:24 EST 2022


New submission from Cooper Lees <me at cooperlees.com>:

Today if you enter a `contextlib.suppress()` context and specify no exceptions there is no error or warning (I didn't check pywarnings to be fair). Isn't this a useless context then? If not, please explain why and close.

If it is, I'd love to discuss possibly raising a new NoSupressionError or at least a warning to let people know they executing an unneeded context.

Example code that 3.11 does not error on:

```python
cooper at home1:~$ python3.11
Python 3.11.0a5+ (main, Feb 21 2022, 08:52:10) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import contextlib
>>> with contextlib.suppress():
...   print("Foo")
...
Foo
```

This was reported to `flake8-bugbear` and if this is not accepted I may accept adding this to the linter. But feel this could be fixable in cpython itself.

----------
components: Library (Lib)
messages: 413663
nosy: cooperlees
priority: normal
severity: normal
status: open
title: Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress
versions: Python 3.11

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


More information about the New-bugs-announce mailing list