diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2020-02-06 14:54:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-06 14:54:05 (GMT) |
commit | 427c84f13f7719e6014a21bd1b81efdc02a046fb (patch) | |
tree | 10bf00b3c7211b2581887ee3e07c2baca3b8cb07 /Lib/fractions.py | |
parent | 3f563cea567fbfed9db539ecbbacfee2d86f7735 (diff) | |
download | cpython-427c84f13f7719e6014a21bd1b81efdc02a046fb.zip cpython-427c84f13f7719e6014a21bd1b81efdc02a046fb.tar.gz cpython-427c84f13f7719e6014a21bd1b81efdc02a046fb.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.
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r-- | Lib/fractions.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 501f4b7..f5a8544 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 |