https://github.com/python/cpython/commit/d7fcaa73b71f4c49c1b24cac04c9b6f1cf69b944
commit: d7fcaa73b71f4c49c1b24cac04c9b6f1cf69b944
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-06-03T12:29:01+03:00
summary:

gh-119838: Treat Fraction as a real value in mixed arithmetic operations with 
complex (GH-119839)

files:
A Misc/NEWS.d/next/Library/2024-05-31-13-56-21.gh-issue-119838.H6XHlE.rst
M Lib/fractions.py
M Lib/test/test_fractions.py

diff --git a/Lib/fractions.py b/Lib/fractions.py
index 95adccd86e33a0..565503911bbe97 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -668,7 +668,7 @@ def forward(a, b):
             elif isinstance(b, float):
                 return fallback_operator(float(a), b)
             elif handle_complex and isinstance(b, complex):
-                return fallback_operator(complex(a), b)
+                return fallback_operator(float(a), b)
             else:
                 return NotImplemented
         forward.__name__ = '__' + fallback_operator.__name__ + '__'
@@ -681,7 +681,7 @@ def reverse(b, a):
             elif isinstance(a, numbers.Real):
                 return fallback_operator(float(a), float(b))
             elif handle_complex and isinstance(a, numbers.Complex):
-                return fallback_operator(complex(a), complex(b))
+                return fallback_operator(complex(a), float(b))
             else:
                 return NotImplemented
         reverse.__name__ = '__r' + fallback_operator.__name__ + '__'
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index 3c7780e40db096..71865f68eb0f12 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -806,10 +806,7 @@ def testMixedMultiplication(self):
         self.assertTypedEquals(F(3, 2) * Polar(4, 2), Polar(F(6, 1), 2))
         self.assertTypedEquals(F(3, 2) * Polar(4.0, 2), Polar(6.0, 2))
         self.assertTypedEquals(F(3, 2) * Rect(4, 3), Rect(F(6, 1), F(9, 2)))
-        with self.assertWarnsRegex(DeprecationWarning,
-                "argument 'real' must be a real number, not complex"):
-            self.assertTypedEquals(F(3, 2) * RectComplex(4, 3),
-                                   RectComplex(6.0+0j, 4.5+0j))
+        self.assertTypedEquals(F(3, 2) * RectComplex(4, 3), RectComplex(6.0, 
4.5))
         self.assertRaises(TypeError, operator.mul, Polar(4, 2), F(3, 2))
         self.assertTypedEquals(Rect(4, 3) * F(3, 2), 6.0 + 4.5j)
         self.assertEqual(F(3, 2) * SymbolicComplex('X'), SymbolicComplex('3/2 
* X'))
diff --git 
a/Misc/NEWS.d/next/Library/2024-05-31-13-56-21.gh-issue-119838.H6XHlE.rst 
b/Misc/NEWS.d/next/Library/2024-05-31-13-56-21.gh-issue-119838.H6XHlE.rst
new file mode 100644
index 00000000000000..17a87327b5b1d6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-31-13-56-21.gh-issue-119838.H6XHlE.rst
@@ -0,0 +1,3 @@
+In mixed arithmetic operations with :class:`~fractions.Fraction` and
+complex, the fraction is now converted to :class:`float` instead of
+:class:`complex`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to