Standard, near-universal stdlib example for things like this: a weakref.proxy to a dead object will raise a ReferenceError for almost any operation, including bool.
>>> import weakref
>>> class Foo:
... pass
...
>>> bool(weakref.proxy(Foo()))
[...]
ReferenceError: weakly-referenced object no longer exists
当}时,
__bool__
不返回True
或{bool
会抱怨。在不过,没有一种内置类型是如此疯狂。在
DSM做了一个非常有价值的评论:流行的numpy库有一些例子,
^{pr2}$bool
会产生错误。在user2357112指出了下面的情况。在
这不是
bool
独有的,任何使用其dead参数的函数都可能抛出此错误,例如myfunc = lambda x: print(x)
。在相关问题 更多 >
编程相关推荐