OSDN Git Service

util/gen_xmlpool: Don't use len to test for container emptiness
authorDylan Baker <dylan@pnwbakers.com>
Wed, 24 Oct 2018 19:30:03 +0000 (12:30 -0700)
committerDylan Baker <dylan@pnwbakers.com>
Wed, 31 Oct 2018 23:37:46 +0000 (16:37 -0700)
This is a very common python anti-pattern. Not using length allows us to
go through faster C paths, but has the same meaning.

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/util/xmlpool/gen_xmlpool.py

index 078bced..f1983c7 100644 (file)
@@ -182,7 +182,7 @@ def main():
         with io.open(args.template, mode="rt", encoding='utf-8') as template:
             descMatches = []
             for line in template:
-                if len(descMatches) > 0:
+                if descMatches:
                     matchENUM = reENUM.match(line)
                     matchDESC_END = reDESC_END.match(line)
                     if matchENUM:
@@ -201,16 +201,16 @@ def main():
                 matchDESC = reDESC.match(line)
                 matchDESC_BEGIN = reDESC_BEGIN.match(line)
                 if matchDESC:
-                    assert len(descMatches) == 0
+                    assert not descMatches
                     expandMatches([matchDESC], translations, output)
                 elif matchDESC_BEGIN:
-                    assert len(descMatches) == 0
+                    assert not descMatches
                     descMatches = [matchDESC_BEGIN]
                 else:
 
                     output.write(line)
 
-        if len(descMatches) > 0:
+        if descMatches:
             print("Warning: unterminated description at end of file.", file=sys.stderr)
             expandMatches(descMatches, translations, output)