flake8-simplify icon indicating copy to clipboard operation
flake8-simplify copied to clipboard

[Adjust rule] SIM105

Open xqt opened this issue 2 years ago • 0 comments

Desired change

  • Rule: SIM105
  • Adjustment: suppress should not be used inside try/finally statement

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()

xqt avatar Jun 03 '22 19:06 xqt