2024-05-01 22:24:45 发布
网友
python PEP 8 linter不喜欢这样:
assert type(a) == type(b)
它告诉我改为使用“isinstance()”。但是要使用isinstance我必须做如下的事情
isinstance
这似乎更不明智,我不太明白这一点。在
林特在某种程度上是我看不见的智慧吗?或者说我是不是在某种程度上是智者看不见的?在
根据注释中添加的上下文:
according to my program's logic, one should have type(a) == type(b) at this point in the code, and I just want to assert that to see that everything is running smoothly
type(a) == type(b)
在这种情况下,您应该忽略掉linter,因为它对您没有任何有用的建议。E271旨在通过类型检查警告人们有关问题,例如:
if type(a) == A: ...
上面的例子可能是由于忽略了a是A的子类的一个实例的可能性而意外地调试了逻辑流。在
a
A
根据注释中添加的上下文:
在这种情况下,您应该忽略掉linter,因为它对您没有任何有用的建议。E271旨在通过类型检查警告人们有关问题,例如:
上面的例子可能是由于忽略了
a
是A
的子类的一个实例的可能性而意外地调试了逻辑流。在相关问题 更多 >
编程相关推荐