PyCQA/flake8-bugbear

Report on uncatchable exception handlers (?)

开放

#349 创建于 2023年2月7日

 (3 条评论) (0 个反应) (0 位负责人)Python (116 个派生)github user discovery
enhancementhelp wanted

仓库指标

星标
 (1,116 个星标)
PR 合并指标
 (平均合并 4小时 17分钟) (30 天内合并 3 个 PR)

描述

Was surprised bugbear didn't report this, but not encountered in live code so I don't know if it's seen much / ever in the wild:

try:
  ...
except BaseException:
  ...
except:
  ...

will report B001/E722, but in a project that uses bare excepts widely and disables those checks the except never being possible to run seems like a separate error.

try:
  ...
except BaseException:
  ...
except Exception:
  ...

Gives no warning, nor does a plausibly more common

try:
  ...
except Exception:
  ...
except ValueError:
  ...

or similar variants. Checking whether a caught exception is a built-in, and if so issubclass of a previously caught exception, seems straightforward. I quickly checked mypy and vulture as well and neither of them sees it. But this might definitely not be common enough that it's worth bothering with.

贡献者指南