Update PEP to match the mini-pep for simplifying Intergal.

This commit is contained in:
Raymond Hettinger 2008-06-11 00:26:20 +00:00
parent e078deceb9
commit 054ae8d319
1 changed files with 14 additions and 38 deletions

View File

@ -319,76 +319,52 @@ And finally integers::
"""__index__() exists because float has __int__()."""
return int(self)
@abstractmethod
def __pow__(self, exponent, modulus=None):
"""self ** exponent % modulus, but maybe faster.
Implement this if you want to support the 3-argument
version of pow(). Otherwise, just implement the 2-argument
version described in Complex. If modulus is None, this
should behave as the 2-argument version; otherwise, raise
a TypeError if exponent < 0 or any argument isn't
Integral.
"""
raise NotImplementedError
@abstractmethod
def __lshift__(self, other):
"""i<<j returns i * 2**j."""
raise NotImplementedError
return int(self) << int(other)
@abstractmethod
def __rlshift__(self, other):
raise NotImplementedError
return int(other) << int(self)
@abstractmethod
def __rshift__(self, other):
"""i>>j returns i // 2**j."""
raise NotImplementedError
return int(self) >> int(other)
@abstractmethod
def __rrshift__(self, other):
raise NotImplementedError
return int(other) >> int(self)
@abstractmethod
def __and__(self, other):
raise NotImplementedError
return int(self) & int(other)
@abstractmethod
def __rand__(self, other):
raise NotImplementedError
return int(other) & int(self)
@abstractmethod
def __xor__(self, other):
raise NotImplementedError
return int(self) ^ int(other)
@abstractmethod
def __rxor__(self, other):
raise NotImplementedError
return int(other) ^ int(self)
@abstractmethod
def __or__(self, other):
raise NotImplementedError
return int(self) | int(other)
@abstractmethod
def __ror__(self, other):
raise NotImplementedError
return int(other) | int(self)
@abstractmethod
def __invert__(self):
raise NotImplementedError
return ~int(self)
# Concrete implementations of Rational and Real abstract methods.
def __float__(self):
"""float(self) == float(int(self))"""
return float(int(self))
@property
def numerator(self):
"""Integers are their own numerators."""
return +self
@property
def denominator(self):
"""Integers have a denominator of 1."""
return 1