相关疑难解决方法(0)

__le __,__ ge__的python bug?

我或python是否与以下代码混淆?我希望__le__被召唤a <= ab,而不是__ge__:

#!/usr/bin/env python2

class B(object):
    def __ge__(self, other):
        print("__ge__ unexpectedly called")

class A(object):
    def __le__(self, other):
        print("__le__ called")

class AB(A, B):
    pass

a = A()
ab = AB()

a <= ab # --> __ge__ unexpectedly called
ab <= a # --> __le__ called
Run Code Online (Sandbox Code Playgroud)

我得到了与python 2.7,3.2和pypy 1.9相同的行为.

我该怎么办才能被__le__召唤而不是__ge__

python

6
推荐指数
1
解决办法
915
查看次数

标签 统计

python ×1