[PATCH 4 of 8 v2] commands: stop abusing int-ness of Python booleans

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Aug 31 21:19:23 UTC 2016


> On Aug 30, 2016, at 15:16, Augie Fackler <raf at durin42.com> wrote:
> 
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1472586452 14400
> #      Tue Aug 30 15:47:32 2016 -0400
> # Node ID c65c0181a9885d3c95e808272c2f609c3a9c8749
> # Parent  69d84366fa224f5dedfdd18a9f5e2413060a8121
> commands: stop abusing int-ness of Python booleans
> 
> This will break as soon as fancyopts starts returning None for all
> unspecified boolean flags.
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -896,7 +896,8 @@ def bisect(ui, repo, rev=None, extra=Non
>             bad = True
>         else:
>             reset = True
> -    elif extra or good + bad + skip + reset + extend + bool(command) > 1:
> +    elif extra or sum(1 for b in (good, bad, skip,
> +                                  reset, extend, command) if b) > 1:

Couldn't we stop abusing math for this at all using any()?

    elif extra or any((good, bad, skip, reset, extend, command)):

Docs say it was added in Python 2.5.

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock




More information about the Mercurial-devel mailing list