Skip to content

Commit 8c54c97

Browse files
STY: Apply ruff/flake8-simplify rule SIM118
SIM118 Use `key in dict` instead of `key in dict.keys()`
1 parent 059496c commit 8c54c97

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

nipype/interfaces/afni/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def _parse_inputs(self, skip=None):
641641
def _list_outputs(self):
642642
outputs = self.output_spec().get()
643643

644-
for key in outputs.keys():
644+
for key in outputs:
645645
if isdefined(self.inputs.get()[key]):
646646
outputs[key] = os.path.abspath(self.inputs.get()[key])
647647

@@ -727,7 +727,7 @@ class Synthesize(AFNICommand):
727727
def _list_outputs(self):
728728
outputs = self.output_spec().get()
729729

730-
for key in outputs.keys():
730+
for key in outputs:
731731
if isdefined(self.inputs.get()[key]):
732732
outputs[key] = os.path.abspath(self.inputs.get()[key])
733733

nipype/interfaces/afni/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
233233
m = re.search(pattern, line)
234234
if m:
235235
d = m.groupdict()
236-
outputs.trait_set(**{k: int(d[k]) for k in d.keys()})
236+
outputs.trait_set(**{k: int(d[k]) for k in d})
237237
return outputs
238238

239239

nipype/interfaces/base/specs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def __deepcopy__(self, memo):
383383
dup_dict = deepcopy(self.trait_get(), memo)
384384
# access all keys
385385
for key in self.copyable_trait_names():
386-
if key in self.__dict__.keys():
386+
if key in self.__dict__:
387387
_ = getattr(self, key)
388388
# clone once
389389
dup = self.clone_traits(memo=memo)

nipype/interfaces/dipy/tests/test_base.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ def test_create_interface_specs():
109109
assert new_interface.__name__ == "MyInterface"
110110
current_params = new_interface().get()
111111
assert len(current_params) == 4
112-
assert "params1" in current_params.keys()
113-
assert "params2_files" in current_params.keys()
114-
assert "params3" in current_params.keys()
115-
assert "out_params" in current_params.keys()
112+
assert "params1" in current_params
113+
assert "params2_files" in current_params
114+
assert "params3" in current_params
115+
assert "out_params" in current_params
116116

117117

118118
@pytest.mark.skipif(
@@ -184,10 +184,10 @@ def run(self, in_files, param1=1, out_dir="", out_ref="out1.txt"):
184184
params_in = new_specs().inputs.get()
185185
params_out = new_specs()._outputs().get()
186186
assert len(params_in) == 4
187-
assert "in_files" in params_in.keys()
188-
assert "param1" in params_in.keys()
189-
assert "out_dir" in params_out.keys()
190-
assert "out_ref" in params_out.keys()
187+
assert "in_files" in params_in
188+
assert "param1" in params_in
189+
assert "out_dir" in params_out
190+
assert "out_ref" in params_out
191191

192192
with pytest.raises(ValueError):
193193
new_specs().run()

nipype/interfaces/fsl/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _create_ev_files(
317317

318318
for fconidx in ftest_idx:
319319
fval = 0
320-
if con[0] in con_map.keys() and fconidx in con_map[con[0]]:
320+
if con[0] in con_map and fconidx in con_map[con[0]]:
321321
fval = 1
322322
ev_txt += contrast_ftest_element.substitute(
323323
cnum=ftest_idx.index(fconidx) + 1,

nipype/interfaces/fsl/tests/test_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_gen_fname(args, desired_name):
7979
cmd = fsl.FSLCommand(command="junk", output_type="NIFTI_GZ")
8080
pth = os.getcwd()
8181
fname = cmd._gen_fname("foo.nii.gz", **args)
82-
if "dir" in desired_name.keys():
82+
if "dir" in desired_name:
8383
desired = os.path.join(desired_name["dir"], desired_name["file"])
8484
else:
8585
desired = os.path.join(pth, desired_name["file"])

nipype/interfaces/spm/model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ def _list_outputs(self):
321321

322322
betas = [vbeta.fname[0] for vbeta in spm["SPM"][0, 0].Vbeta[0]]
323323
if (
324-
"Bayesian" in self.inputs.estimation_method.keys()
325-
or "Bayesian2" in self.inputs.estimation_method.keys()
324+
"Bayesian" in self.inputs.estimation_method
325+
or "Bayesian2" in self.inputs.estimation_method
326326
):
327327
outputs["labels"] = os.path.join(pth, f"labels.{outtype}")
328328
outputs["SDerror"] = glob(os.path.join(pth, "Sess*_SDerror*"))
@@ -331,7 +331,7 @@ def _list_outputs(self):
331331
outputs["Cbetas"] = [os.path.join(pth, f"C{beta}") for beta in betas]
332332
outputs["SDbetas"] = [os.path.join(pth, f"SD{beta}") for beta in betas]
333333

334-
if "Classical" in self.inputs.estimation_method.keys():
334+
if "Classical" in self.inputs.estimation_method:
335335
outputs["residual_image"] = os.path.join(pth, f"ResMS.{outtype}")
336336
outputs["RPVimage"] = os.path.join(pth, f"RPV.{outtype}")
337337
if self.inputs.write_residuals:

nipype/utils/draw_gantt_chart.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def _convert_string_to_datetime(datestring):
115115

116116
date_object_node_list: list = list()
117117
for n in nodes_list:
118-
if "start" in n.keys():
118+
if "start" in n:
119119
n["start"] = _convert_string_to_datetime(n["start"])
120-
if "finish" in n.keys():
120+
if "finish" in n:
121121
n["finish"] = _convert_string_to_datetime(n["finish"])
122122
date_object_node_list.append(n)
123123

0 commit comments

Comments
 (0)