From e01173d113ed0fa296c000283e5e1b10873000c5 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:15:35 +0200 Subject: [PATCH 1/3] STY: Apply ruff rule RUF017 RUF017 Avoid quadratic list summation --- nipype/info.py | 2 +- nipype/interfaces/fsl/utils.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nipype/info.py b/nipype/info.py index 284fe4101b..7b68ec909c 100644 --- a/nipype/info.py +++ b/nipype/info.py @@ -187,7 +187,7 @@ def get_nipype_gitversion(): def _list_union(iterable): - return list(set(sum(iterable, []))) + return list(set(x for sublist in iterable for x in sublist)) # Enable a handle to install all extra dependencies at once diff --git a/nipype/interfaces/fsl/utils.py b/nipype/interfaces/fsl/utils.py index acdd771fc8..89daa41b8b 100644 --- a/nipype/interfaces/fsl/utils.py +++ b/nipype/interfaces/fsl/utils.py @@ -483,7 +483,9 @@ class ExtractROI(FSLCommand): def _format_arg(self, name, spec, value): if name == "crop_list": - return " ".join(map(str, sum(list(map(list, value)), []))) + return " ".join( + map(str, (x for sublist in map(list, value) for x in sublist)) + ) return super()._format_arg(name, spec, value) def _list_outputs(self): From 1be9a67d4ce66ec46aaa4ae83a95184f8aad30e6 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:17:24 +0200 Subject: [PATCH 2/3] STY: Apply ruff rule RUF021 RUF021 Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear --- nipype/interfaces/spm/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/spm/base.py b/nipype/interfaces/spm/base.py index ac20682696..e224eec91b 100644 --- a/nipype/interfaces/spm/base.py +++ b/nipype/interfaces/spm/base.py @@ -52,7 +52,7 @@ def func_is_3d(in_file): else: img = load(in_file) shape = img.shape - return len(shape) == 3 or len(shape) == 4 and shape[3] == 1 + return len(shape) == 3 or (len(shape) == 4 and shape[3] == 1) def get_first_3dfile(in_files): From 5ce526f318abe59d4213455ea327b55201838065 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:31:02 +0200 Subject: [PATCH 3/3] STY: Further simplification Co-authored-by: Chris Markiewicz --- nipype/interfaces/fsl/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nipype/interfaces/fsl/utils.py b/nipype/interfaces/fsl/utils.py index 89daa41b8b..2cf868371d 100644 --- a/nipype/interfaces/fsl/utils.py +++ b/nipype/interfaces/fsl/utils.py @@ -483,9 +483,7 @@ class ExtractROI(FSLCommand): def _format_arg(self, name, spec, value): if name == "crop_list": - return " ".join( - map(str, (x for sublist in map(list, value) for x in sublist)) - ) + return " ".join(str(x) for sublist in value for x in sublist) return super()._format_arg(name, spec, value) def _list_outputs(self):