Skip to content

Commit c4ba9b9

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

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

nipype/interfaces/afni/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3248,7 +3248,7 @@ def _run_interface(self, runtime):
32483248
return runtime
32493249

32503250
def _list_outputs(self):
3251-
return {"out": getattr(self, "_gcor")}
3251+
return {"out": self._gcor}
32523252

32533253

32543254
class AxializeInputSpec(AFNICommandInputSpec):

nipype/interfaces/ants/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def _format_arg(self, opt, spec, val):
536536
return super()._format_arg(opt, spec, val)
537537

538538
def _list_outputs(self):
539-
return getattr(self, "_output")
539+
return self._output
540540

541541

542542
class AverageAffineTransformInputSpec(ANTSCommandInputSpec):

nipype/interfaces/base/support.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __exit__(self, exc_type, exc_value, exc_tb):
9999
traceback.format_exception(exc_type, exc_value, exc_tb)
100100
)
101101
# Gather up the exception arguments and append nipype info.
102-
exc_args = exc_value.args if getattr(exc_value, "args") else tuple()
102+
exc_args = exc_value.args if exc_value.args else tuple()
103103
exc_args += (
104104
f"An exception of type {exc_type.__name__} occurred while "
105105
f"running interface {self._runtime.interface}.",

nipype/interfaces/elastix/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ def _run_interface(self, runtime):
164164

165165
def _list_outputs(self):
166166
outputs = self.output_spec().get()
167-
outputs["output_file"] = getattr(self, "_out_file")
167+
outputs["output_file"] = self._out_file
168168
return outputs
169169

170170
def _get_outfile(self):
171-
val = getattr(self, "_out_file")
171+
val = self._out_file
172172
if val is not None and val != "":
173173
return val
174174

nipype/interfaces/fsl/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2580,11 +2580,11 @@ def _coords_to_trk(self, points, out_file):
25802580

25812581
def _overload_extension(self, value, name):
25822582
if name == "out_file":
2583-
return "{}.{}".format(value, getattr(self, "_outformat"))
2583+
return "{}.{}".format(value, self._outformat)
25842584

25852585
def _run_interface(self, runtime):
2586-
fname = getattr(self, "_in_file")
2587-
outformat = getattr(self, "_outformat")
2586+
fname = self._in_file
2587+
outformat = self._outformat
25882588
tmpfile = None
25892589

25902590
if outformat == "vtk":

nipype/pipeline/engine/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def _identity_nodes(graph, include_iterables):
852852
node
853853
for node in nx.topological_sort(graph)
854854
if isinstance(node.interface, IdentityInterface)
855-
and (include_iterables or getattr(node, "iterables") is None)
855+
and (include_iterables or node.iterables is None)
856856
]
857857

858858

nipype/utils/profiler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ def log_nodes_cb(node, status):
174174
status_dict = {
175175
"name": node.name,
176176
"id": node._id,
177-
"start": getattr(node.result.runtime, "startTime"),
178-
"finish": getattr(node.result.runtime, "endTime"),
179-
"duration": getattr(node.result.runtime, "duration"),
177+
"start": node.result.runtime.startTime,
178+
"finish": node.result.runtime.endTime,
179+
"duration": node.result.runtime.duration,
180180
"runtime_threads": getattr(node.result.runtime, "cpu_percent", "N/A"),
181181
"runtime_memory_gb": getattr(node.result.runtime, "mem_peak_gb", "N/A"),
182182
"estimated_memory_gb": node.mem_gb,

nipype/utils/provenance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def write_provenance(results, filename="provenance", format="all"):
300300
import traceback
301301

302302
err_msg = traceback.format_exc()
303-
if getattr(e, "args"):
303+
if e.args:
304304
err_msg += "\n\nException arguments:\n" + ", ".join(
305305
['"%s"' % arg for arg in e.args]
306306
)

tools/checkspecs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def test_specs(self, uri):
287287
continue
288288
parent_metadata = []
289289
if "parent" in trait.__dict__:
290-
parent_metadata = list(getattr(trait, "parent").__dict__.keys())
290+
parent_metadata = list(trait.parent.__dict__.keys())
291291
if (
292292
key
293293
not in allowed_keys
@@ -375,7 +375,7 @@ def test_specs(self, uri):
375375
continue
376376
parent_metadata = []
377377
if "parent" in trait.__dict__:
378-
parent_metadata = list(getattr(trait, "parent").__dict__.keys())
378+
parent_metadata = list(trait.parent.__dict__.keys())
379379
if (
380380
key
381381
not in allowed_keys

0 commit comments

Comments
 (0)