MartinThoma / flake8-simplify

❄ A flake8 plugin that helps you to simplify code
MIT License
185 stars 19 forks source link

[Adjust rule] SIM105 #143

Open xqt opened 2 years ago

xqt commented 2 years ago

Desired change

Explanation

The code is not simplified because the try statement is still necessary then

Example

This is an example where the mentioned rule would currently be suboptimal:

        try:
            self._write_bytes(send_data)
        except Exception:
            pass
        finally:
            self._force_close()

using suppress would lead to

        from contextlib import suppress
        try:
            with suppress(Exception):
                self._write_bytes(send_data)
        finally:
            self._force_close()