[New-bugs-announce] [issue32828] compress "True if bool(x) else False" expressions

Дилян Палаузов report at bugs.python.org
Mon Feb 12 06:54:27 EST 2018


New submission from Дилян Палаузов <dilyan.palauzov at aegee.org>:

diff --git a/Lib/_strptime.py b/Lib/_strptime.py
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -525,7 +525,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
     # out the Julian day of the year.
     if julian is None and weekday is not None:
         if week_of_year is not None:
-            week_starts_Mon = True if week_of_year_start == 0 else False
+            week_starts_Mon = week_of_year_start == 0
             julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
                                                 week_starts_Mon)
         elif iso_year is not None and iso_week is not None:
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -59,7 +59,7 @@ class Generator:
         """
 
         if mangle_from_ is None:
-            mangle_from_ = True if policy is None else policy.mangle_from_
+            mangle_from_ = policy is None or policy.mangle_from_
         self._fp = outfp
         self._mangle_from_ = mangle_from_
         self.maxheaderlen = maxheaderlen
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -576,7 +576,7 @@ def rand_aligned_slices(maxdim=5, maxshape=16):
         minshape = 0
     elif n >= 90:
         minshape = 1
-    all_random = True if randrange(100) >= 80 else False
+    all_random = randrange(100) >= 80
     lshape = [0]*ndim; rshape = [0]*ndim
     lslices = [0]*ndim; rslices = [0]*ndim
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -117,7 +117,7 @@ skip_expected = not os.path.isdir(directory)
 EXTENDEDERRORTEST = False
 
 # Test extra functionality in the C version (-DEXTRA_FUNCTIONALITY).
-EXTRA_FUNCTIONALITY = True if hasattr(C, 'DecClamped') else False
+EXTRA_FUNCTIONALITY = hasattr(C, 'DecClamped')
 requires_extra_functionality = unittest.skipUnless(
   EXTRA_FUNCTIONALITY, "test requires build with -DEXTRA_FUNCTIONALITY")
 skip_if_extra_functionality = unittest.skipIf(
@@ -1455,7 +1455,7 @@ class ArithmeticOperatorsTest(unittest.TestCase):
         for x, y in qnan_pairs + snan_pairs:
             for op in order_ops + equality_ops:
                 got = op(x, y)
-                expected = True if op is operator.ne else False
+                expected = op is operator.ne
                 self.assertIs(expected, got,
                               "expected {0!r} for operator.{1}({2!r}, {3!r}); "
                               "got {4!r}".format(
@@ -1468,7 +1468,7 @@ class ArithmeticOperatorsTest(unittest.TestCase):
             for x, y in qnan_pairs:
                 for op in equality_ops:
                     got = op(x, y)
-                    expected = True if op is operator.ne else False
+                    expected = op is operator.ne
                     self.assertIs(expected, got,
                                   "expected {0!r} for "
                                   "operator.{1}({2!r}, {3!r}); "
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -20,13 +20,13 @@ except (IndexError, ValueError):
 # tuple of (major, minor)
 WIN_VER = sys.getwindowsversion()[:2]
 # Some tests should only run on 64-bit architectures where WOW64 will be.
-WIN64_MACHINE = True if machine() == "AMD64" else False
+WIN64_MACHINE = machine() == "AMD64"
 
 # Starting with Windows 7 and Windows Server 2008 R2, WOW64 no longer uses
 # registry reflection and formerly reflected keys are shared instead.
 # Windows 7 and Windows Server 2008 R2 are version 6.1. Due to this, some
 # tests are only valid up until 6.1
-HAS_REFLECTION = True if WIN_VER < (6, 1) else False
+HAS_REFLECTION = WIN_VER < (6, 1)
 
 # Use a per-process key to prevent concurrent test runs (buildbot!) from
 # stomping on each other.

----------
components: Build
messages: 312039
nosy: dilyan.palauzov
priority: normal
severity: normal
status: open
title: compress "True if bool(x) else False" expressions
type: performance
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32828>
_______________________________________


More information about the New-bugs-announce mailing list