让 pylint(或其他工具)捕捉重叠异常
Getting pylint (or other tool) to catch overlapping exceptions
我还没有找到任何方法让 pylint(或其他代码分析工具)来捕获存在 overlapping/redundant 异常的情况,如下例所示:
"""doc"""
import socket
try:
pass
except (ConnectionError, IOError, OSError, socket.error):
# ConnectionError inherits from OSError
# socket.error and IOError are aliases for OSError
pass
这里我想投诉 ConnectionError、IOError 和 socket.error 已经被 OSError 包含在 except-clause 中。
In [1]: import socket
In [2]: OSError
Out[2]: builtins.OSError
In [3]: socket.error
Out[3]: builtins.OSError
In [4]: IOError
Out[4]: builtins.OSError
In [5]: ConnectionError, ConnectionError.__bases__
Out[5]: (builtins.ConnectionError, (builtins.OSError,))
这个存在吗?
如果不是,这会是一个 good/bad 想法吗?
现已在此处实施:
Overlap-except-checker
我还没有找到任何方法让 pylint(或其他代码分析工具)来捕获存在 overlapping/redundant 异常的情况,如下例所示:
"""doc"""
import socket
try:
pass
except (ConnectionError, IOError, OSError, socket.error):
# ConnectionError inherits from OSError
# socket.error and IOError are aliases for OSError
pass
这里我想投诉 ConnectionError、IOError 和 socket.error 已经被 OSError 包含在 except-clause 中。
In [1]: import socket
In [2]: OSError
Out[2]: builtins.OSError
In [3]: socket.error
Out[3]: builtins.OSError
In [4]: IOError
Out[4]: builtins.OSError
In [5]: ConnectionError, ConnectionError.__bases__
Out[5]: (builtins.ConnectionError, (builtins.OSError,))
这个存在吗? 如果不是,这会是一个 good/bad 想法吗?
现已在此处实施: Overlap-except-checker