Python 2 and 3 are significantly different from each other, so I think you should bite the bullet and check the versions. This can only be expected if you are trying to write code that works on both (sooner or later in my experience you will find something that you need to fix). To avoid any performance impact, you can do something like:
from six import PY2 class Derived(int): if PY2: def __eq__(self, other): return super(Derived, self).__cmp__(other) == 0 else: def __eq__(self, other): return super(Derived, self).__eq__(other)
What would i do. If I really wanted to subclass int ...
If you really do not want this, perhaps you could try:
class Derived(int): def __eq__(self, other): return (self ^ other) == 0
Obviously, if you care about performance, you will have to do some profiling with the rest of your code and find out if any of them are much worse ...
source share