Skip to content

Commit

Permalink
Fix Flake8 C419 for Ubuntu CI (#800)
Browse files Browse the repository at this point in the history
C419 Unnecessary list comprehension passed to any()/all() prevents short-circuiting - rewrite as a generator

Signed-off-by: Aleksander Kantak <[email protected]>
  • Loading branch information
akantak authored Apr 20, 2023
1 parent 4084d79 commit 60911a6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions openfl/component/aggregator/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,9 @@ def _is_round_done(self):
"""Check that round is done."""
tasks_for_round = self.assigner.get_all_tasks_for_round(self.round_number)

return all([
return all(
self._is_task_done(
task_name) for task_name in tasks_for_round])
task_name) for task_name in tasks_for_round)

def _log_big_warning(self):
"""Warn user about single collaborator cert mode."""
Expand Down
2 changes: 1 addition & 1 deletion openfl/pipelines/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ def backward(self, data, transformer_metadata, **kwargs):

def is_lossy(self):
"""If any of the transformers are lossy, then the pipeline is lossy."""
return any([transformer.lossy for transformer in self.transformers])
return any(transformer.lossy for transformer in self.transformers)
2 changes: 1 addition & 1 deletion openfl/utilities/data_splitters/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def split(self, data, num_collaborators):
slice_end = slice_start + self.min_samples_per_class
print(f'Assigning {slice_start}:{slice_end} of class {label} to {col} col...')
idx[col] += list(label_idx[slice_start:slice_end])
if any([len(i) != samples_per_col for i in idx]):
if any(len(i) != samples_per_col for i in idx):
raise SystemError(f'''All collaborators should have {samples_per_col} elements
but distribution is {[len(i) for i in idx]}''')

Expand Down
2 changes: 1 addition & 1 deletion openfl/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def split_tensor_dict_by_types(tensor_dict, keep_types):
keep_dict = {}
holdout_dict = {}
for k, v in tensor_dict.items():
if any([np.issubdtype(v.dtype, type_) for type_ in keep_types]):
if any(np.issubdtype(v.dtype, type_) for type_ in keep_types):
keep_dict[k] = v
else:
holdout_dict[k] = v
Expand Down

0 comments on commit 60911a6

Please sign in to comment.