Skip to content

Commit abe1b59

Browse files
STY: Apply ruff/flake8-bugbear rule B010
B010 Do not call `setattr` with a constant attribute value. It is not any safer than normal property access.
1 parent b67cf08 commit abe1b59

File tree

8 files changed

+19
-33
lines changed

8 files changed

+19
-33
lines changed

nipype/algorithms/tests/test_modelgen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_modelgen_spm_concat(tmpdir):
122122
s = SpecifySPMModel()
123123
s.inputs.input_units = "secs"
124124
s.inputs.concatenate_runs = True
125-
setattr(s.inputs, "output_units", "secs")
125+
s.inputs.output_units = "secs"
126126
assert s.inputs.output_units == "secs"
127127
s.inputs.functional_runs = [filename1, filename2]
128128
s.inputs.time_repetition = 6
@@ -147,7 +147,7 @@ def test_modelgen_spm_concat(tmpdir):
147147
)
148148

149149
# Test case of scans as output units instead of seconds
150-
setattr(s.inputs, "output_units", "scans")
150+
s.inputs.output_units = "scans"
151151
assert s.inputs.output_units == "scans"
152152
s.inputs.subject_info = deepcopy(info)
153153
res = s.run()

nipype/interfaces/afni/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,7 @@ def _run_interface(self, runtime):
32433243
for line in runtime.stdout.split("\n")
32443244
if line.strip().startswith("GCOR = ")
32453245
][-1]
3246-
setattr(self, "_gcor", float(gcor_line[len("GCOR = ") :]))
3246+
self._gcor = float(gcor_line[len("GCOR = "):])
32473247
return runtime
32483248

32493249
def _list_outputs(self):

nipype/interfaces/elastix/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ def _get_outfile(self):
173173
return val
174174

175175
if isdefined(self.inputs.output_file):
176-
setattr(self, "_out_file", self.inputs.output_file)
176+
self._out_file = self.inputs.output_file
177177
return self.inputs.output_file
178178

179179
out_file = op.abspath(op.basename(self.inputs.transform_file))
180-
setattr(self, "_out_file", out_file)
180+
self._out_file = out_file
181181
return out_file

nipype/interfaces/fsl/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def _run_interface(self, runtime):
928928
float(r) for r in out["translations"].strip().split(" ")
929929
]
930930

931-
setattr(self, "_results", outputs)
931+
self._results = outputs
932932
return runtime
933933

934934
def _list_outputs(self):
@@ -2512,8 +2512,8 @@ def _format_arg(self, name, trait_spec, value):
25122512

25132513
def _parse_inputs(self, skip=None):
25142514
fname, ext = op.splitext(self.inputs.in_coords)
2515-
setattr(self, "_in_file", fname)
2516-
setattr(self, "_outformat", ext[1:])
2515+
self._in_file = fname
2516+
self._outformat = ext[1:]
25172517
first_args = super()._parse_inputs(skip=["in_coords", "out_file"])
25182518

25192519
second_args = fname + ".txt"

nipype/interfaces/spm/model.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -848,31 +848,17 @@ def _make_matlab_command(self, _):
848848

849849
def aggregate_outputs(self, runtime=None):
850850
outputs = self._outputs()
851-
setattr(outputs, "thresholded_map", self._gen_thresholded_map_filename())
852-
setattr(outputs, "pre_topo_fdr_map", self._gen_pre_topo_map_filename())
851+
outputs.thresholded_map = self._gen_thresholded_map_filename()
852+
outputs.pre_topo_fdr_map = self._gen_pre_topo_map_filename()
853853
for line in runtime.stdout.split("\n"):
854854
if line.startswith("activation_forced = "):
855-
setattr(
856-
outputs,
857-
"activation_forced",
858-
line[len("activation_forced = ") :].strip() == "1",
859-
)
855+
outputs.activation_forced = line[len("activation_forced = "):].strip() == "1"
860856
elif line.startswith("n_clusters = "):
861-
setattr(
862-
outputs, "n_clusters", int(line[len("n_clusters = ") :].strip())
863-
)
857+
outputs.n_clusters = int(line[len("n_clusters = "):].strip())
864858
elif line.startswith("pre_topo_n_clusters = "):
865-
setattr(
866-
outputs,
867-
"pre_topo_n_clusters",
868-
int(line[len("pre_topo_n_clusters = ") :].strip()),
869-
)
859+
outputs.pre_topo_n_clusters = int(line[len("pre_topo_n_clusters = "):].strip())
870860
elif line.startswith("cluster_forming_thr = "):
871-
setattr(
872-
outputs,
873-
"cluster_forming_thr",
874-
float(line[len("cluster_forming_thr = ") :].strip()),
875-
)
861+
outputs.cluster_forming_thr = float(line[len("cluster_forming_thr = "):].strip())
876862
return outputs
877863

878864
def _list_outputs(self):

nipype/interfaces/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def test_datasink_copydir_2(_temp_analyze_files, tmpdir):
517517
base_directory=tmpdir.mkdir("basedir").strpath, parameterization=False
518518
)
519519
ds.inputs.remove_dest_dir = True
520-
setattr(ds.inputs, "outdir", pth)
520+
ds.inputs.outdir = pth
521521
ds.run()
522522
sep = os.path.sep
523523
assert not tmpdir.join("basedir", pth.split(sep)[-1], fname).check()

nipype/pipeline/engine/tests/test_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def test_1mod(iterables, expected):
2626
pipe = pe.Workflow(name="pipe")
2727
mod1 = pe.Node(interface=EngineTestInterface(), name="mod1")
28-
setattr(mod1, "iterables", iterables["1"])
28+
mod1.iterables = iterables["1"]
2929
pipe.add_nodes([mod1])
3030
pipe._flatgraph = pipe._create_flat_graph()
3131
pipe._execgraph = pe.generate_expanded_graph(deepcopy(pipe._flatgraph))
@@ -49,7 +49,7 @@ def test_2mods(iterables, expected):
4949
mod1 = pe.Node(interface=EngineTestInterface(), name="mod1")
5050
mod2 = pe.Node(interface=EngineTestInterface(), name="mod2")
5151
for nr in ["1", "2"]:
52-
setattr(eval("mod" + nr), "iterables", iterables[nr])
52+
eval("mod" + nr).iterables = iterables[nr]
5353
pipe.connect([(mod1, mod2, [("output1", "input2")])])
5454
pipe._flatgraph = pipe._create_flat_graph()
5555
pipe._execgraph = pe.generate_expanded_graph(deepcopy(pipe._flatgraph))
@@ -87,7 +87,7 @@ def test_3mods(iterables, expected, connect):
8787
mod2 = pe.Node(interface=EngineTestInterface(), name="mod2")
8888
mod3 = pe.Node(interface=EngineTestInterface(), name="mod3")
8989
for nr in ["1", "2", "3"]:
90-
setattr(eval("mod" + nr), "iterables", iterables[nr])
90+
eval("mod" + nr).iterables = iterables[nr]
9191
if connect == ("1-2", "2-3"):
9292
pipe.connect(
9393
[

nipype/utils/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def _mock():
353353

354354
# Older versions of xvfbwrapper used vdisplay_num
355355
if not hasattr(self._display, "new_display"):
356-
setattr(self._display, "new_display", self._display.vdisplay_num)
356+
self._display.new_display = self._display.vdisplay_num
357357
return self.get_display()
358358

359359
def stop_display(self):

0 commit comments

Comments
 (0)