Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04cb90d

Browse files
jamesobutlerjcfr
andcommitted
STYLE: Update python scripts to fix RUF059 unpacked variable never used
See https://docs.astral.sh/ruff/rules/unused-unpacked-variable/ Adding the prefix underscore allows the variables to still be defined for easy use in the future to be able to use the variable and understand what is unpacked at that position. Changes applied by temporarily updating the `ruff` version to `v0.13.0` and specifying `--unsafe-fixes` in the `.pre-commit-config.yaml`. Remaining errors were manually reviewed and fixed Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
1 parent 44e8969 commit 04cb90d

File tree

16 files changed

+24
-24
lines changed

16 files changed

+24
-24
lines changed

Applications/SlicerApp/Testing/Python/DWMRIMultishellIOTests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_nrrd_dwi_roundtrip(test_nrrd_path):
151151
storagenode1.SetFileName(tmp_nrrd1)
152152
storagenode1.WriteData(dw_node1)
153153

154-
parsed_nrrd2, dw_node2 = test_nrrd_dwi_load(test_nrrd_path, tmp_nrrd1)
154+
_parsed_nrrd2, dw_node2 = test_nrrd_dwi_load(test_nrrd_path, tmp_nrrd1)
155155

156156
# re-save NRRD again
157157
storagenode2 = slicer.vtkMRMLNRRDStorageNode()
@@ -161,7 +161,7 @@ def test_nrrd_dwi_roundtrip(test_nrrd_path):
161161
storagenode2.WriteData(dw_node2)
162162

163163
# test twice-saved file against original NRRD
164-
parsed_nrrd3, dw_node3 = test_nrrd_dwi_load(test_nrrd_path, tmp_nrrd2)
164+
_parsed_nrrd3, _dw_node3 = test_nrrd_dwi_load(test_nrrd_path, tmp_nrrd2)
165165

166166

167167
def run_tests(data_dir, tmp_dir):

Applications/SlicerApp/Testing/Python/MeasureStartupTimes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ def collect_modules(output_file):
130130
output.write(json.dumps(modules, indent=4))
131131
""".format(output_file))
132132

133-
(returnCode, stdout, stderr) = runSlicerAndExit(slicer_executable, ["--python-script", python_script.name])
133+
(returnCode, _stdout, _stderr) = runSlicerAndExit(slicer_executable, ["--python-script", python_script.name])
134134
assert returnCode == EXIT_SUCCESS
135135
print("=> ok\n")
136136

137137
return read_modules(output_file)
138138

139139

140140
def slicerRevision():
141-
(returnCode, stdout, stderr) = runSlicerAndExit(slicer_executable, [
141+
(returnCode, stdout, _stderr) = runSlicerAndExit(slicer_executable, [
142142
"--no-main-window", "--ignore-slicerrc", "--disable-modules",
143143
"--python-code", "print(slicer.app.repositoryRevision)",
144144
])

Applications/SlicerApp/Testing/Python/ScriptedModuleCleanupTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def check_exit_code(slicer_executable, testing_enabled=True, debug=False):
7373
args.append("--testing")
7474
else:
7575
args.append("--exit-after-startup")
76-
(returnCode, stdout, stderr) = run(slicer_executable, args)
76+
(returnCode, _stdout, _stderr) = run(slicer_executable, args)
7777

7878
assert os.path.isfile(test_output_file)
7979

Applications/SlicerApp/Testing/Python/SlicerDisplayNodeSequenceTest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_ScalarVolumeDisplayNodeSequence(self):
5959
mrHead.GetDisplayNode().ApplyThresholdOn()
6060
mrHead.GetDisplayNode().SetAutoWindowLevel(False)
6161
mrHead.GetDisplayNode().SetWindowLevelMinMax(10, 120)
62-
min, max = mrHead.GetImageData().GetScalarRange()
62+
_min, max = mrHead.GetImageData().GetScalarRange()
6363
mrHead.GetDisplayNode().SetThreshold(0, max)
6464
window_preset = 99
6565
level_preset = 49
@@ -69,7 +69,7 @@ def test_ScalarVolumeDisplayNodeSequence(self):
6969
mrHead2 = sampleDataLogic.downloadMRHead()
7070
mrHead2.GetDisplayNode().SetAndObserveColorNodeID("vtkMRMLColorTableNodeRed")
7171
mrHead2.GetDisplayNode().ApplyThresholdOn()
72-
min, max = mrHead2.GetImageData().GetScalarRange()
72+
_min, max = mrHead2.GetImageData().GetScalarRange()
7373
mrHead2.GetDisplayNode().SetThreshold(79, max)
7474
mrHead2.GetDisplayNode().ApplyThresholdOn()
7575
mrHead2.GetDisplayNode().SetAutoWindowLevel(False)

Applications/SlicerApp/Testing/Python/SlicerOptionDisableSettingsTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def checkKeepTemporarySettingsWithoutDisableSettingsDisplayWarning(slicer_execut
8181
args = list(common_args)
8282
args.remove("--disable-settings")
8383
args.extend(["--keep-temporary-settings"])
84-
(returnCode, stdout, stderr) = runSlicerAndExit(slicer_executable, args)
84+
(returnCode, _stdout, stderr) = runSlicerAndExit(slicer_executable, args)
8585
expectedMessage = "Argument '--keep-temporary-settings' requires '--settings-disabled' to be specified."
8686
if expectedMessage not in stderr:
8787
print(f"=> return code{returnCode}\n")

Applications/SlicerApp/Testing/Python/SlicerTransformInteractionTest1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_3D_interactionDefaults(self):
9696

9797
# self.delayDisplay("Starting test_3D_interactionDefaults")
9898
logic = SlicerTransformInteractionTest1Logic()
99-
tNode, tdNode = logic.addTransform()
99+
_tNode, tdNode = logic.addTransform()
100100
self.assertFalse(tdNode.GetEditorVisibility())
101101
self.assertFalse(tdNode.GetEditorSliceIntersectionVisibility())
102102

@@ -423,7 +423,7 @@ def test_3D_parentTransform(self):
423423
markupNode.AddControlPoint([-1500.0, -200.0, -100.0])
424424

425425
logic = SlicerTransformInteractionTest1Logic()
426-
parentNode, parendDisplayNode = logic.addTransform()
426+
parentNode, _parendDisplayNode = logic.addTransform()
427427

428428
leafNode, tdNode = logic.addTransform()
429429
slicer.app.layoutManager().layout = slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView

Base/Python/slicer/tests/test_slicer_util_VTKObservationMixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_getObserver(self):
117117
priority = 42.0
118118

119119
foo.addObserver(obj, event, callback, group=group, priority=priority)
120-
group_, tag_, priority_ = foo.getObserver(obj, event, callback)
120+
group_, _tag, priority_ = foo.getObserver(obj, event, callback)
121121

122122
self.assertEqual(group, group_)
123123
self.assertEqual(priority, priority_)

Base/Python/slicer/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ def removeObservers(self, method=None):
28952895
for obj, events in self.__observations.items():
28962896
for e, methods in events.items():
28972897
if method in methods:
2898-
g, t, p = methods.pop(method)
2898+
_g, t, _p = methods.pop(method)
28992899
obj.RemoveObserver(t)
29002900

29012901
def addObserver(self, obj, event, method, group="none", priority=0.0):
@@ -2917,7 +2917,7 @@ def removeObserver(self, obj, event, method):
29172917
try:
29182918
events = self.__observations[obj]
29192919
methods = events[event]
2920-
group, tag, priority = methods.pop(method)
2920+
_group, tag, _priority = methods.pop(method)
29212921
obj.RemoveObserver(tag)
29222922
except KeyError:
29232923
warn("does not have observer")
@@ -3580,7 +3580,7 @@ def extractArchive(archiveFilePath, outputDir, expectedNumberOfExtractedFiles=No
35803580
if not os.path.exists(archiveFilePath):
35813581
logging.error("Specified file %s does not exist" % (archiveFilePath))
35823582
return False
3583-
fileName, fileExtension = os.path.splitext(archiveFilePath)
3583+
_fileName, fileExtension = os.path.splitext(archiveFilePath)
35843584
if fileExtension.lower() != ".zip":
35853585
# TODO: Support other archive types
35863586
logging.error("Only zip archives are supported now, got " + fileExtension)

Modules/Loadable/Markups/Testing/Python/MarkupsCurveCoordinateFrameTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def createCoordinateSystemsModel(curve, axisLength=5):
6565

6666

6767
def addCoordinateSystemUpdater(updateInfo):
68-
model, curve, coordinateSystemAppender, curvePointToWorldTransform, transform, transformer = updateInfo
68+
_model, curve, _coordinateSystemAppender, _curvePointToWorldTransform, _transform, _transformer = updateInfo
6969
observation = curve.AddObserver(slicer.vtkMRMLMarkupsNode.PointModifiedEvent,
7070
lambda caller, eventData, updateInfo=updateInfo: updateCoordinateSystemsModel(updateInfo))
7171
return [curve, observation]

Modules/Scripted/DICOMLib/DICOMBrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def examineForLoading(self):
446446
of what to load
447447
"""
448448

449-
(self.loadablesByPlugin, loadEnabled) = self.getLoadablesFromFileLists(self.fileLists)
449+
(self.loadablesByPlugin, _loadEnabled) = self.getLoadablesFromFileLists(self.fileLists)
450450
DICOMLib.selectHighestConfidenceLoadables(self.loadablesByPlugin)
451451
self.loadableTable.setLoadables(self.loadablesByPlugin)
452452
self.updateButtonStates()

0 commit comments

Comments
 (0)