From de3a4ed5cc55ce8dad9e3d71abd1154956a84f48 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:42:09 +0200 Subject: [PATCH 1/5] STY: Apply ruff/pycodestyle rule E401 E401 Multiple imports on one line --- nipype/algorithms/modelgen.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nipype/algorithms/modelgen.py b/nipype/algorithms/modelgen.py index 38b5e47549..78083cb628 100644 --- a/nipype/algorithms/modelgen.py +++ b/nipype/algorithms/modelgen.py @@ -7,7 +7,9 @@ experiments. """ from copy import deepcopy -import csv, math, os +import csv +import math +import os from nibabel import load import numpy as np From ccff8d9d92b34b8b89fd6d97ba60493650fab38f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:47:23 +0200 Subject: [PATCH 2/5] STY: Apply ruff/pycodestyle rule E712 E712 Avoid equality comparisons to `False`; use `if not trait.__dict__[key]:` for false checks --- tools/checkspecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/checkspecs.py b/tools/checkspecs.py index 959acef0e0..7c9ebf4157 100644 --- a/tools/checkspecs.py +++ b/tools/checkspecs.py @@ -301,7 +301,7 @@ def test_specs(self, uri): bad_specs.append( [uri, c, "Inputs", traitname, "mandatory=False"] ) - if key == "usedefault" and trait.__dict__[key] == False: + if key == "usedefault" and trait.__dict__[key] is False: bad_specs.append( [uri, c, "Inputs", traitname, "usedefault=False"] ) From 5f6d4920f3f3689e875c58e995d27f885aaeda86 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:43:00 +0200 Subject: [PATCH 3/5] STY: Apply ruff/pycodestyle rule E714 E714 Test for object identity should be `is not` --- nipype/pipeline/plugins/dagman.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nipype/pipeline/plugins/dagman.py b/nipype/pipeline/plugins/dagman.py index ad8e4ec733..55f3f03bee 100644 --- a/nipype/pipeline/plugins/dagman.py +++ b/nipype/pipeline/plugins/dagman.py @@ -78,7 +78,7 @@ def __init__(self, **kwargs): ): if ( "plugin_args" in kwargs - and not kwargs["plugin_args"] is None + and kwargs["plugin_args"] is not None and id_ in kwargs["plugin_args"] ): if id_ == "wrapper_cmd": @@ -89,7 +89,7 @@ def __init__(self, **kwargs): val = self._get_str_or_file(kwargs["plugin_args"][id_]) setattr(self, var, val) # TODO remove after some time - if "plugin_args" in kwargs and not kwargs["plugin_args"] is None: + if "plugin_args" in kwargs and kwargs["plugin_args"] is not None: plugin_args = kwargs["plugin_args"] if "template" in plugin_args: warn( From 3bc9c5820e0e036e11cecf31019482c5a75c34dc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:44:56 +0200 Subject: [PATCH 4/5] STY: Apply ruff/pycodestyle rule E721 E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks --- nipype/interfaces/base/tests/test_support.py | 2 +- nipype/interfaces/fsl/tests/test_base.py | 2 +- nipype/pipeline/engine/tests/test_workflows.py | 2 +- nipype/scripts/utils.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nipype/interfaces/base/tests/test_support.py b/nipype/interfaces/base/tests/test_support.py index 3997a88280..6bac7d0852 100644 --- a/nipype/interfaces/base/tests/test_support.py +++ b/nipype/interfaces/base/tests/test_support.py @@ -35,7 +35,7 @@ def test_bunch_methods(): assert b.get("a") == 3 assert b.get("badkey", "otherthing") == "otherthing" assert b != newb - assert type(dict()) == type(newb) + assert type(dict()) is type(newb) assert newb["a"] == 3 diff --git a/nipype/interfaces/fsl/tests/test_base.py b/nipype/interfaces/fsl/tests/test_base.py index 2b07381e81..1a76d0f6a5 100644 --- a/nipype/interfaces/fsl/tests/test_base.py +++ b/nipype/interfaces/fsl/tests/test_base.py @@ -37,7 +37,7 @@ def test_FSLCommand(): # testing the one item that is not. cmd = fsl.FSLCommand(command="ls") res = cmd.run() - assert type(res) == InterfaceResult + assert type(res) is InterfaceResult @pytest.mark.skipif(no_fsl(), reason="fsl is not installed") diff --git a/nipype/pipeline/engine/tests/test_workflows.py b/nipype/pipeline/engine/tests/test_workflows.py index 9b06eb56bb..12d56de285 100644 --- a/nipype/pipeline/engine/tests/test_workflows.py +++ b/nipype/pipeline/engine/tests/test_workflows.py @@ -20,7 +20,7 @@ def test_init(): with pytest.raises(TypeError): pe.Workflow() pipe = pe.Workflow(name="pipe") - assert type(pipe._graph) == nx.DiGraph + assert type(pipe._graph) is nx.DiGraph def test_connect(): diff --git a/nipype/scripts/utils.py b/nipype/scripts/utils.py index 77e7231bea..8d8dc52627 100644 --- a/nipype/scripts/utils.py +++ b/nipype/scripts/utils.py @@ -71,12 +71,12 @@ def add_args_options(arg_parser, interface): if not spec.is_trait_type(traits.TraitCompound): trait_type = type(spec.trait_type.default_value) if trait_type in (bytes, str, int, float): - if trait_type == bytes: + if trait_type is bytes: trait_type = str args["type"] = trait_type elif len(spec.inner_traits) == 1: trait_type = type(spec.inner_traits[0].trait_type.default_value) - if trait_type == bytes: + if trait_type is bytes: trait_type = str if trait_type in (bytes, bool, str, int, float): args["type"] = trait_type From e84ada2293db100edef8f8b5632d7f1510b97a4d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:35:11 +0200 Subject: [PATCH 5/5] STY: Further simplification Co-authored-by: Chris Markiewicz --- nipype/interfaces/base/tests/test_support.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/interfaces/base/tests/test_support.py b/nipype/interfaces/base/tests/test_support.py index 6bac7d0852..52770e476c 100644 --- a/nipype/interfaces/base/tests/test_support.py +++ b/nipype/interfaces/base/tests/test_support.py @@ -35,7 +35,7 @@ def test_bunch_methods(): assert b.get("a") == 3 assert b.get("badkey", "otherthing") == "otherthing" assert b != newb - assert type(dict()) is type(newb) + assert type(newb) is dict assert newb["a"] == 3