From 427c84f13f7719e6014a21bd1b81efdc02a046fb Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 6 Feb 2020 06:54:05 -0800 Subject: 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. --- Lib/fractions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/fractions.py') diff --git a/Lib/fractions.py b/Lib/fractions.py index 501f4b74a0..f5a854414c 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 -- cgit v1.2.1