summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-06-11 00:25:29 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-06-11 00:25:29 (GMT)
commitcaea65e465101554b3cf46ca107e60027f8da312 (patch)
tree186a9f1eaab8d5913956a5df4c79c16f75054396 /Lib
parent31296c09ed1f1114a325da4ecafc5a8d8f079284 (diff)
downloadcpython-caea65e465101554b3cf46ca107e60027f8da312.zip
cpython-caea65e465101554b3cf46ca107e60027f8da312.tar.gz
cpython-caea65e465101554b3cf46ca107e60027f8da312.tar.bz2
Mini-PEP: Simplifying numbers.py
* Convert binary methods in Integral to mixin methods * Remove three-arg __pow__ as a required method * Make __int__ the root method instead of __long__.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/numbers.py67
1 files changed, 17 insertions, 50 deletions
diff --git a/Lib/numbers.py b/Lib/numbers.py
index 38240d6..972fe1f 100644
--- a/Lib/numbers.py
+++ b/Lib/numbers.py
@@ -283,87 +283,54 @@ class Rational(Real):
class Integral(Rational):
- """Integral adds a conversion to long and the bit-string operations."""
+ """Integral adds a conversion to int and the bit-string operations."""
@abstractmethod
- def __long__(self):
- """long(self)"""
+ def __int__(self):
+ """int(self)"""
raise NotImplementedError
def __index__(self):
"""index(self)"""
- return long(self)
+ return int(self)
- @abstractmethod
- def __pow__(self, exponent, modulus=None):
- """self ** exponent % modulus, but maybe faster.
-
- Accept the modulus argument if you want to support the
- 3-argument version of pow(). Raise a TypeError if exponent < 0
- or any argument isn't Integral. Otherwise, just implement the
- 2-argument version described in Complex.
- """
- raise NotImplementedError
-
- @abstractmethod
def __lshift__(self, other):
- """self << other"""
- raise NotImplementedError
+ return int(self) << int(other)
- @abstractmethod
def __rlshift__(self, other):
- """other << self"""
- raise NotImplementedError
+ return int(other) << int(self)
- @abstractmethod
def __rshift__(self, other):
- """self >> other"""
- raise NotImplementedError
+ return int(self) >> int(other)
- @abstractmethod
def __rrshift__(self, other):
- """other >> self"""
- raise NotImplementedError
+ return int(other) >> int(self)
- @abstractmethod
def __and__(self, other):
- """self & other"""
- raise NotImplementedError
+ return int(self) & int(other)
- @abstractmethod
def __rand__(self, other):
- """other & self"""
- raise NotImplementedError
+ return int(other) & int(self)
- @abstractmethod
def __xor__(self, other):
- """self ^ other"""
- raise NotImplementedError
+ return int(self) ^ int(other)
- @abstractmethod
def __rxor__(self, other):
- """other ^ self"""
- raise NotImplementedError
+ return int(other) ^ int(self)
- @abstractmethod
def __or__(self, other):
- """self | other"""
- raise NotImplementedError
+ return int(self) | int(other)
- @abstractmethod
def __ror__(self, other):
- """other | self"""
- raise NotImplementedError
+ return int(other) | int(self)
- @abstractmethod
def __invert__(self):
- """~self"""
- raise NotImplementedError
+ return ~int(self)
# Concrete implementations of Rational and Real abstract methods.
def __float__(self):
- """float(self) == float(long(self))"""
- return float(long(self))
+ """float(self) == float(int(self))"""
+ return float(int(self))
@property
def numerator(self):