summaryrefslogtreecommitdiffstats
path: root/Lib/fractions.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-06 15:14:37 (GMT)
committerGitHub <noreply@github.com>2020-02-06 15:14:37 (GMT)
commit705d271d553b77fd170d27ab8d0f11f638c7f145 (patch)
tree487542e8ec1179b1d5951065729348bc30135de6 /Lib/fractions.py
parent6ba8dc6aae6fa0a7e29ba4ac18227beb38872392 (diff)
downloadcpython-705d271d553b77fd170d27ab8d0f11f638c7f145.zip
cpython-705d271d553b77fd170d27ab8d0f11f638c7f145.tar.gz
cpython-705d271d553b77fd170d27ab8d0f11f638c7f145.tar.bz2
bpo-39274: Ensure Fraction.__bool__() returns a bool (GH-18017)
Some numerator types used (specifically NumPy) decides to not return a Python boolean for the "a != b" operation. Using the equivalent call to bool() guarantees a bool return also for such types. (cherry picked from commit 427c84f13f7719e6014a21bd1b81efdc02a046fb) Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r--Lib/fractions.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 8330202..64bff70 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -625,7 +625,9 @@ class Fraction(numbers.Rational):
def __bool__(a):
"""a != 0"""
- return a._numerator != 0
+ # bpo-39274: Use bool() because (a._numerator != 0) can return an
+ # object which is not a bool.
+ return bool(a._numerator)
# support for pickling, copy, and deepcopy