Patchwork [1,of,2] mq: prefer a loop to a double-for list comprehension

login
register
mail settings
Submitter Kevin Bullock
Date Nov. 24, 2013, 11:38 p.m.
Message ID <4f8e4f2eb8fdfd521d48.1385336283@billings.local>
Download mbox | patch
Permalink /patch/3118/
State Accepted
Commit 1648e44edd8dd5376cbe545b29db77839f4ef8db
Headers show

Comments

Kevin Bullock - Nov. 24, 2013, 11:38 p.m.
# HG changeset patch
# User Kevin Bullock <kbullock@ringworld.org>
# Date 1385335750 21600
#      Sun Nov 24 17:29:10 2013 -0600
# Node ID 4f8e4f2eb8fdfd521d4883d48d9ab6685f64d0a4
# Parent  1c46b18b0e1c47fa4cecf21b78c083a54ae9903f
mq: prefer a loop to a double-for list comprehension

The [x for y in l for x in y] syntax is nigh-incomprehensible, and this
is a particularly easy case to expand into a loop since there's no 'if'
condition in the list comprehension.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1204,7 +1204,9 @@  class queue(object):
         diffopts = self.diffopts()
         wlock = repo.wlock()
         try:
-            heads = [h for hs in repo.branchmap().itervalues() for h in hs]
+            heads = []
+            for hs in repo.branchmap().itervalues():
+                heads.extend(hs)
             if not heads:
                 heads = [nullid]
             if repo.dirstate.p1() not in heads and not exact: