Skip to content

Commit 697297b

Browse files
STY: Apply ruff/flake8-simplify rule SIM118
SIM118 Use `key in dict` instead of `key in dict.keys()`
1 parent d294476 commit 697297b

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
@@ -636,7 +636,7 @@ def _parse_inputs(self, skip=None):
636636
def _list_outputs(self):
637637
outputs = self.output_spec().get()
638638

639-
for key in outputs.keys():
639+
for key in outputs:
640640
if isdefined(self.inputs.get()[key]):
641641
outputs[key] = os.path.abspath(self.inputs.get()[key])
642642

@@ -722,7 +722,7 @@ class Synthesize(AFNICommand):
722722
def _list_outputs(self):
723723
outputs = self.output_spec().get()
724724

725-
for key in outputs.keys():
725+
for key in outputs:
726726
if isdefined(self.inputs.get()[key]):
727727
outputs[key] = os.path.abspath(self.inputs.get()[key])
728728

nipype/interfaces/afni/utils.py

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

240240

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
@@ -318,7 +318,7 @@ def _create_ev_files(
318318

319319
for fconidx in ftest_idx:
320320
fval = 0
321-
if con[0] in con_map.keys() and fconidx in con_map[con[0]]:
321+
if con[0] in con_map and fconidx in con_map[con[0]]:
322322
fval = 1
323323
ev_txt += contrast_ftest_element.substitute(
324324
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
@@ -322,8 +322,8 @@ def _list_outputs(self):
322322

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

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

nipype/utils/draw_gantt_chart.py

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

115115
date_object_node_list: list = list()
116116
for n in nodes_list:
117-
if "start" in n.keys():
117+
if "start" in n:
118118
n["start"] = _convert_string_to_datetime(n["start"])
119-
if "finish" in n.keys():
119+
if "finish" in n:
120120
n["finish"] = _convert_string_to_datetime(n["finish"])
121121
date_object_node_list.append(n)
122122

0 commit comments

Comments
 (0)