Index: Lib/numbers.py =================================================================== --- Lib/numbers.py (revision 64290) +++ Lib/numbers.py (working copy) @@ -295,34 +295,54 @@ return int(self) def __lshift__(self, other): - return int(self) << int(other) + if isinstance(other, (type(self), int, long)): + return int(self) << int(other) + return NotImplemented def __rlshift__(self, other): - return int(other) << int(self) + if isinstance(other, Integral): + return int(other) << int(self) + return NotImplemented def __rshift__(self, other): - return int(self) >> int(other) + if isinstance(other, (type(self), int, long)): + return int(self) >> int(other) + return NotImplemented def __rrshift__(self, other): - return int(other) >> int(self) + if isinstance(other, Integral): + return int(other) >> int(self) + return NotImplemented def __and__(self, other): - return int(self) & int(other) + if isinstance(other, (type(self), int, long)): + return int(self) & int(other) + return NotImplemented def __rand__(self, other): - return int(other) & int(self) + if isinstance(other, Integral): + return int(other) & int(self) + return NotImplemented def __xor__(self, other): - return int(self) ^ int(other) + if isinstance(other, (type(self), int, long)): + return int(self) ^ int(other) + return NotImplemented def __rxor__(self, other): - return int(other) ^ int(self) + if isinstance(other, Integral): + return int(other) ^ int(self) + return NotImplemented def __or__(self, other): - return int(self) | int(other) + if isinstance(other, (type(self), int, long)): + return int(self) | int(other) + return NotImplemented def __ror__(self, other): - return int(other) | int(self) + if isinstance(other, Integral): + return int(other) | int(self) + return NotImplemented def __invert__(self): return ~int(self)