8000 gh-119838: Treat Fraction as a real value in mixed arithmetic operati… · python/cpython@d7fcaa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d7fcaa7

Browse files
gh-119838: Treat Fraction as a real value in mixed arithmetic operations with complex (GH-119839)
1 parent 70934fb commit d7fcaa7

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Lib/fractions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def forward(a, b):
668668
elif isinstance(b, float):
669669
return fallback_operator(float(a), b)
670670
elif handle_complex and isinstance(b, complex):
671-
return fallback_operator(complex(a), b)
671+
return fallback_operator(float(a), b)
672672
else:
673673
return NotImplemented
674674
forward.__name__ = '__' + fallback_operator.__name__ + '__'
@@ -681,7 +681,7 @@ def reverse(b, a):
681681
elif isinstance(a, numbers.Real):
682682
return fallback_operator(float(a), float(b))
683683
elif handle_complex and isinstance(a, numbers.Complex):
684-
return fallback_operator(complex(a), complex(b))
684+
return fallback_operator(complex(a), float(b))
685685
else:
686686
return NotImplemented
687687
reverse.__name__ = '__r' + fallback_operator.__name__ + '__'

Lib/test/test_fractions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,7 @@ def testMixedMultiplication(self):
806806
self.assertTypedEquals(F(3, 2) * Polar(4, 2), Polar(F(6, 1), 2))
807807
self.assertTypedEquals(F(3, 2) * Polar(4.0, 2), Polar(6.0, 2))
808808
self.assertTypedEquals(F(3, 2) * Rect(4, 3), Rect(F(6, 1), F(9, 2)))
809-
with self.assertWarnsRegex(DeprecationWarning,
810- 9B9F
"argument 'real' must be a real number, not complex"):
811-
self.assertTypedEquals(F(3, 2) * RectComplex(4, 3),
812-
RectComplex(6.0+0j, 4.5+0j))
809+
self.assertTypedEquals(F(3, 2) * RectComplex(4, 3), RectComplex(6.0, 4.5))
813810
self.assertRaises(TypeError, operator.mul, Polar(4, 2), F(3, 2))
814811
self.assertTypedEquals(Rect(4, 3) * F(3, 2), 6.0 + 4.5j)
815812
self.assertEqual(F(3, 2) * SymbolicComplex('X'), SymbolicComplex('3/2 * X'))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In mixed arithmetic operations with :class:`~fractions.Fraction` and
2+
complex, the fraction is now converted to :class:`float` instead of
3+
:class:`complex`.

0 commit comments

Comments
 (0)
0