build-bash-completion: Check for None before comparing
authorMichael Hanselmann <hansmi@google.com>
Wed, 25 Nov 2009 11:19:58 +0000 (12:19 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 25 Nov 2009 12:08:56 +0000 (13:08 +0100)
Comparing a number with None is not a good idea:

  >>> (0 < None, 0 > None)
  (False, True)

This patch also adds build-bash-completion to the list
of checked Python scripts and wraps one line of more
than 80 characters.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

Makefile.am
autotools/build-bash-completion

index 718775e..8aa6430 100644 (file)
@@ -351,6 +351,7 @@ srclink_files = \
        $(all_python_code)
 
 check_python_code = \
+       autotools/build-bash-completion \
        $(all_python_code)
 
 devel/upload: devel/upload.in $(REPLACE_VARS_SED)
index 0d03cf8..aa130d4 100755 (executable)
@@ -465,11 +465,11 @@ class CompletionWriter:
 
         if arg.min == 1 and arg.max == 1:
           cmpcode = """"$arg_idx" == %d""" % (last_arg_end)
+        elif arg.max is None:
+          cmpcode = """"$arg_idx" -ge %d""" % (last_arg_end)
         elif arg.min <= arg.max:
           cmpcode = (""""$arg_idx" -ge %d && "$arg_idx" -lt %d""" %
                      (last_arg_end, last_arg_end + arg.max))
-        elif arg.max is None:
-          cmpcode = """"$arg_idx" -ge %d""" % (last_arg_end)
         else:
           raise Exception("Unable to generate argument position condition")
 
@@ -487,7 +487,8 @@ class CompletionWriter:
             if choices:
               sw.Write("""choices="$choices "%s""", choices)
             if compgenargs:
-              sw.Write("compgenargs=%s", utils.ShellQuote(" ".join(compgenargs)))
+              sw.Write("compgenargs=%s",
+                       utils.ShellQuote(" ".join(compgenargs)))
           finally:
             sw.DecIndent()