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

Class Rect

Lib/test/test_fractions.py:253–280  ·  view source on GitHub ↗

Other simple Complex class for testing mixed arithmetic.

Source from the content-addressed store, hash-verified

251numbers.Complex.register(Polar)
252
253class Rect:
254 """Other simple Complex class for testing mixed arithmetic."""
255 def __init__(self, x, y):
256 self.x = x
257 self.y = y
258 def __mul__(self, other):
259 if isinstance(other, F):
260 return NotImplemented
261 return self.__class__(self.x * other, self.y * other)
262 def __rmul__(self, other):
263 return self.__class__(other * self.x, other * self.y)
264 def __truediv__(self, other):
265 if isinstance(other, F):
266 return NotImplemented
267 return self.__class__(self.x / other, self.y / other)
268 def __rtruediv__(self, other):
269 r = self.x * self.x + self.y * self.y
270 return self.__class__(other * (self.x / r), other * (self.y / r))
271 def __rpow__(self, other):
272 return Polar(other ** self.x, math.log(other) * self.y)
273 def __complex__(self):
274 return complex(self.x, self.y)
275 def __eq__(self, other):
276 if self.__class__ != other.__class__:
277 return NotImplemented
278 return typed_approx_eq(self.x, other.x) and typed_approx_eq(self.y, other.y)
279 def __repr__(self):
280 return f'{self.__class__.__name__}({self.x!r}, {self.y!r})'
281numbers.Complex.register(Rect)
282
283class RectComplex(Rect, complex):

Callers 4

testMixedDivisionMethod · 0.70
testMixedPowerMethod · 0.70

Calls

no outgoing calls

Tested by 4

testMixedDivisionMethod · 0.56
testMixedPowerMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…