From e6b78c7ce3b3df8fd275af18a90b29d2ac264a21 2012-09-11 09:41:52 From: Jan Schulz Date: 2012-09-11 09:41:52 Subject: [PATCH] Optimise a check for empty jobs/target lists If the inputs are empty, no msg_ids should be returned. So change the test to not only check for None but also for empty lists. Signed-off-by: Jan Schulz --- diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index b87b6a5..ea2ee59 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -1607,17 +1607,16 @@ class Client(HasTraits): def _build_msgids_from_target(self, targets=None): """Build a list of msg_ids from the list of engine targets""" - if targets == None: # needed as _build_targets otherwise uses all engines + if not targets: # needed as _build_targets otherwise uses all engines return [] target_ids = self._build_targets(targets)[0] return filter(lambda md_id: self.metadata[md_id]["engine_uuid"] in target_ids, self.metadata) def _build_msgids_from_jobs(self, jobs=None): """Build a list of msg_ids from "jobs" """ + if not jobs: + return [] msg_ids = [] - if jobs == None: - return msg_ids - if isinstance(jobs, (basestring,AsyncResult)): jobs = [jobs] bad_ids = filter(lambda obj: not isinstance(obj, (basestring, AsyncResult)), jobs)