Skip to content

compress "True if bool(x) else False" expressions #77009

Closed

Description

@dilyanpalauzov
BPO 32828
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2018-02-12.15:06:48.382>
created_at = <Date 2018-02-12.11:54:27.589>
labels = ['build', '3.8', 'performance']
title = 'compress "True if bool(x) else False" expressions'
updated_at = <Date 2018-02-12.15:56:00.075>
user = 'https://bugs.python.org/dilyanpalauzov'

bugs.python.org fields:

activity = <Date 2018-02-12.15:56:00.075>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2018-02-12.15:06:48.382>
closer = 'r.david.murray'
components = ['Build']
creation = <Date 2018-02-12.11:54:27.589>
creator = 'dilyan.palauzov'
dependencies = []
files = []
hgrepos = []
issue_num = 32828
keywords = []
message_count = 3.0
messages = ['312039', '312057', '312061']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'dilyan.palauzov']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue32828'
versions = ['Python 3.8']

Activity

  1. dilyanpalauzov commented on Feb 12, 2018

    dilyanpalauzovmannequin
    MannequinAuthor
    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.
  2. added
    3.8 (EOL)
    build
    performance
    on Feb 12, 2018
  3. bitdancer commented on Feb 12, 2018

    @bitdancer
    Member

    The one in generator.py should not be changed, it is clearer as written. I don't have a strong opinion on the others.

  4. bitdancer commented on Feb 12, 2018

    @bitdancer
    Member

    Oops. I actually didn't intend to close this, but thinking about it I'm going to leave it closed. We generally don't do this kind of "tidy work" unless we are touching the code for other reasons.

  5. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.8 (EOL)buildperformance

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions