MCPcopy Index your code
hub / github.com/python/cpython / Symbolic

Class Symbolic

Lib/test/test_fractions.py:97–135  ·  view source on GitHub ↗

Simple non-numeric class for testing mixed arithmetic. It is not Integral, Rational, Real or Complex, and cannot be converted to int, float or complex. but it supports some arithmetic operations.

Source from the content-addressed store, hash-verified

95 return type(a) == type(b) and (a == b or math.isclose(a, b))
96
97class Symbolic:
98 """Simple non-numeric class for testing mixed arithmetic.
99 It is not Integral, Rational, Real or Complex, and cannot be converted
100 to int, float or complex. but it supports some arithmetic operations.
101 """
102 def __init__(self, value):
103 self.value = value
104 def __mul__(self, other):
105 if isinstance(other, F):
106 return NotImplemented
107 return self.__class__(f'{self} * {other}')
108 def __rmul__(self, other):
109 return self.__class__(f'{other} * {self}')
110 def __truediv__(self, other):
111 if isinstance(other, F):
112 return NotImplemented
113 return self.__class__(f'{self} / {other}')
114 def __rtruediv__(self, other):
115 return self.__class__(f'{other} / {self}')
116 def __mod__(self, other):
117 if isinstance(other, F):
118 return NotImplemented
119 return self.__class__(f'{self} % {other}')
120 def __rmod__(self, other):
121 return self.__class__(f'{other} % {self}')
122 def __pow__(self, other):
123 if isinstance(other, F):
124 return NotImplemented
125 return self.__class__(f'{self} ** {other}')
126 def __rpow__(self, other):
127 return self.__class__(f'{other} ** {self}')
128 def __eq__(self, other):
129 if other.__class__ != self.__class__:
130 return NotImplemented
131 return self.value == other.value
132 def __str__(self):
133 return f'{self.value}'
134 def __repr__(self):
135 return f'{self.__class__.__name__}({self.value!r})'
136
137class SymbolicReal(Symbolic):
138 pass

Callers 4

testMixedDivisionMethod · 0.85
testMixedPowerMethod · 0.85

Calls

no outgoing calls

Tested by 4

testMixedDivisionMethod · 0.68
testMixedPowerMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…