Back to index

python3.2  3.2.2
Public Member Functions | Static Private Attributes
numbers.Complex Class Reference

Notes on Decimal

Decimal has all of the methods specified by the Real abc, but it should not be registered as a Real because decimals do not interoperate with binary floats (i.e. More...

Inheritance diagram for numbers.Complex:
Inheritance graph
[legend]
Collaboration diagram for numbers.Complex:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __complex__
def __bool__
def real
def imag
def __add__
def __radd__
def __neg__
def __pos__
def __sub__
def __rsub__
def __mul__
def __rmul__
def __truediv__
def __rtruediv__
def __pow__
def __rpow__
def __abs__
def conjugate
def __eq__
def __ne__
def __new__
def register
def __instancecheck__
def __subclasscheck__

Static Private Attributes

tuple __slots__ = ()

Detailed Description

Notes on Decimal

Decimal has all of the methods specified by the Real abc, but it should not be registered as a Real because decimals do not interoperate with binary floats (i.e.

Decimal('3.14') + 2.71828 is undefined). But, abstract reals are expected to interoperate (i.e. R1 + R2 should be expected to work if R1 and R2 are both Reals).

Complex defines the operations that work on the builtin complex type.

In short, those are: a conversion to complex, .real, .imag, +, -,
*, /, abs(), .conjugate, ==, and !=.

If it is given heterogenous arguments, and doesn't have special
knowledge about them, it should fall back to the builtin complex
type as described below.

Definition at line 32 of file numbers.py.


Member Function Documentation

def numbers.Complex.__abs__ (   self)
Returns the Real distance from 0. Called for abs(self).

Reimplemented in fractions.Fraction.

Definition at line 128 of file numbers.py.

00128 
00129     def __abs__(self):
00130         """Returns the Real distance from 0. Called for abs(self)."""
00131         raise NotImplementedError

def numbers.Complex.__add__ (   self,
  other 
)
self + other

Definition at line 70 of file numbers.py.

00070 
00071     def __add__(self, other):
00072         """self + other"""
00073         raise NotImplementedError

def numbers.Complex.__bool__ (   self)
True if self != 0. Called for bool(self).

Reimplemented in fractions.Fraction.

Definition at line 49 of file numbers.py.

00049 
00050     def __bool__(self):
00051         """True if self != 0. Called for bool(self)."""
00052         return self != 0

Return a builtin complex instance. Called for complex(self).

Reimplemented in numbers.Real.

Definition at line 46 of file numbers.py.

00046 
00047     def __complex__(self):
00048         """Return a builtin complex instance. Called for complex(self)."""

def numbers.Complex.__eq__ (   self,
  other 
)
self == other

Reimplemented in fractions.Fraction.

Definition at line 138 of file numbers.py.

00138 
00139     def __eq__(self, other):
00140         """self == other"""
00141         raise NotImplementedError

def abc.ABCMeta.__instancecheck__ (   cls,
  instance 
) [inherited]
Override for isinstance(instance, cls).

Definition at line 158 of file abc.py.

00158 
00159     def __instancecheck__(cls, instance):
00160         """Override for isinstance(instance, cls)."""
00161         # Inline the cache checking
00162         subclass = instance.__class__
00163         if subclass in cls._abc_cache:
00164             return True
00165         subtype = type(instance)
00166         if subtype is subclass:
00167             if (cls._abc_negative_cache_version ==
00168                 ABCMeta._abc_invalidation_counter and
00169                 subclass in cls._abc_negative_cache):
00170                 return False
00171             # Fall back to the subclass check.
00172             return cls.__subclasscheck__(subclass)
00173         return any(cls.__subclasscheck__(c) for c in {subclass, subtype})

Here is the call graph for this function:

def numbers.Complex.__mul__ (   self,
  other 
)
self * other

Definition at line 98 of file numbers.py.

00098 
00099     def __mul__(self, other):
00100         """self * other"""
00101         raise NotImplementedError

def numbers.Complex.__ne__ (   self,
  other 
)
self != other

Definition at line 142 of file numbers.py.

00142 
00143     def __ne__(self, other):
00144         """self != other"""
00145         # The default __ne__ doesn't negate __eq__ until 3.0.
00146         return not (self == other)
00147 
00148 Complex.register(complex)
00149 

def numbers.Complex.__neg__ (   self)
-self

Reimplemented in fractions.Fraction.

Definition at line 80 of file numbers.py.

00080 
00081     def __neg__(self):
00082         """-self"""
00083         raise NotImplementedError

def abc.ABCMeta.__new__ (   mcls,
  name,
  bases,
  namespace 
) [inherited]

Definition at line 116 of file abc.py.

00116 
00117     def __new__(mcls, name, bases, namespace):
00118         cls = super().__new__(mcls, name, bases, namespace)
00119         # Compute set of abstract method names
00120         abstracts = {name
00121                      for name, value in namespace.items()
00122                      if getattr(value, "__isabstractmethod__", False)}
00123         for base in bases:
00124             for name in getattr(base, "__abstractmethods__", set()):
00125                 value = getattr(cls, name, None)
00126                 if getattr(value, "__isabstractmethod__", False):
00127                     abstracts.add(name)
00128         cls.__abstractmethods__ = frozenset(abstracts)
00129         # Set up inheritance registry
00130         cls._abc_registry = WeakSet()
00131         cls._abc_cache = WeakSet()
00132         cls._abc_negative_cache = WeakSet()
00133         cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
00134         return cls

Here is the call graph for this function:

def numbers.Complex.__pos__ (   self)
+self

Reimplemented in fractions.Fraction.

Definition at line 85 of file numbers.py.

00085 
00086     def __pos__(self):
00087         """+self"""
00088         raise NotImplementedError

def numbers.Complex.__pow__ (   self,
  exponent 
)
self**exponent; should promote to float or complex when necessary.

Reimplemented in fractions.Fraction.

Definition at line 118 of file numbers.py.

00118 
00119     def __pow__(self, exponent):
00120         """self**exponent; should promote to float or complex when necessary."""
00121         raise NotImplementedError

def numbers.Complex.__radd__ (   self,
  other 
)
other + self

Definition at line 75 of file numbers.py.

00075 
00076     def __radd__(self, other):
00077         """other + self"""
00078         raise NotImplementedError

def numbers.Complex.__rmul__ (   self,
  other 
)
other * self

Definition at line 103 of file numbers.py.

00103 
00104     def __rmul__(self, other):
00105         """other * self"""
00106         raise NotImplementedError

def numbers.Complex.__rpow__ (   self,
  base 
)
base ** self

Reimplemented in fractions.Fraction.

Definition at line 123 of file numbers.py.

00123 
00124     def __rpow__(self, base):
00125         """base ** self"""
00126         raise NotImplementedError

def numbers.Complex.__rsub__ (   self,
  other 
)
other - self

Definition at line 93 of file numbers.py.

00093 
00094     def __rsub__(self, other):
00095         """other - self"""
00096         return -self + other

def numbers.Complex.__rtruediv__ (   self,
  other 
)
other / self

Definition at line 113 of file numbers.py.

00113 
00114     def __rtruediv__(self, other):
00115         """other / self"""
00116         raise NotImplementedError

def numbers.Complex.__sub__ (   self,
  other 
)
self - other

Definition at line 89 of file numbers.py.

00089 
00090     def __sub__(self, other):
00091         """self - other"""
00092         return self + -other

def abc.ABCMeta.__subclasscheck__ (   cls,
  subclass 
) [inherited]
Override for issubclass(subclass, cls).

Definition at line 174 of file abc.py.

00174 
00175     def __subclasscheck__(cls, subclass):
00176         """Override for issubclass(subclass, cls)."""
00177         # Check cache
00178         if subclass in cls._abc_cache:
00179             return True
00180         # Check negative cache; may have to invalidate
00181         if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter:
00182             # Invalidate the negative cache
00183             cls._abc_negative_cache = WeakSet()
00184             cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
00185         elif subclass in cls._abc_negative_cache:
00186             return False
00187         # Check the subclass hook
00188         ok = cls.__subclasshook__(subclass)
00189         if ok is not NotImplemented:
00190             assert isinstance(ok, bool)
00191             if ok:
00192                 cls._abc_cache.add(subclass)
00193             else:
00194                 cls._abc_negative_cache.add(subclass)
00195             return ok
00196         # Check if it's a direct subclass
00197         if cls in getattr(subclass, '__mro__', ()):
00198             cls._abc_cache.add(subclass)
00199             return True
00200         # Check if it's a subclass of a registered class (recursive)
00201         for rcls in cls._abc_registry:
00202             if issubclass(subclass, rcls):
00203                 cls._abc_cache.add(subclass)
00204                 return True
00205         # Check if it's a subclass of a subclass (recursive)
00206         for scls in cls.__subclasses__():
00207             if issubclass(subclass, scls):
00208                 cls._abc_cache.add(subclass)
00209                 return True
00210         # No dice; update negative cache
00211         cls._abc_negative_cache.add(subclass)
00212         return False

Here is the call graph for this function:

def numbers.Complex.__truediv__ (   self,
  other 
)
self / other: Should promote to float when necessary.

Definition at line 108 of file numbers.py.

00108 
00109     def __truediv__(self, other):
00110         """self / other: Should promote to float when necessary."""
00111         raise NotImplementedError

def numbers.Complex.conjugate (   self)
(x+y*i).conjugate() returns (x-y*i).

Reimplemented in numbers.Real.

Definition at line 133 of file numbers.py.

00133 
00134     def conjugate(self):
00135         """(x+y*i).conjugate() returns (x-y*i)."""
00136         raise NotImplementedError

def numbers.Complex.imag (   self)
Retrieve the imaginary component of this number.

This should subclass Real.

Reimplemented in numbers.Real.

Definition at line 62 of file numbers.py.

00062 
00063     def imag(self):
00064         """Retrieve the imaginary component of this number.
00065 
00066         This should subclass Real.
00067         """
00068         raise NotImplementedError

def numbers.Complex.real (   self)
Retrieve the real component of this number.

This should subclass Real.

Reimplemented in numbers.Real.

Definition at line 54 of file numbers.py.

00054 
00055     def real(self):
00056         """Retrieve the real component of this number.
00057 
00058         This should subclass Real.
00059         """
00060         raise NotImplementedError

def abc.ABCMeta.register (   cls,
  subclass 
) [inherited]
Register a virtual subclass of an ABC.

Definition at line 135 of file abc.py.

00135 
00136     def register(cls, subclass):
00137         """Register a virtual subclass of an ABC."""
00138         if not isinstance(subclass, type):
00139             raise TypeError("Can only register classes")
00140         if issubclass(subclass, cls):
00141             return  # Already a subclass
00142         # Subtle: test for cycles *after* testing for "already a subclass";
00143         # this means we allow X.register(X) and interpret it as a no-op.
00144         if issubclass(cls, subclass):
00145             # This would create a cycle, which is bad for the algorithm below
00146             raise RuntimeError("Refusing to create an inheritance cycle")
00147         cls._abc_registry.add(subclass)
00148         ABCMeta._abc_invalidation_counter += 1  # Invalidate negative cache

Here is the caller graph for this function:


Member Data Documentation

tuple numbers.Complex.__slots__ = () [static, private]

Reimplemented from numbers.Number.

Reimplemented in numbers.Integral, numbers.Rational, numbers.Real, and fractions.Fraction.

Definition at line 43 of file numbers.py.


The documentation for this class was generated from the following file: