Skip to content

Commit 9915bfc

Browse files
committed
Address typing issues (and avoid some minor code duplication)
1 parent 16ce3fd commit 9915bfc

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

heudiconv/convert.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,19 @@ def save_converted_files(
894894
bvals, bvecs = res.outputs.bvals, res.outputs.bvecs
895895
bvals = list(bvals) if isinstance(bvals, TraitListObject) else bvals
896896
bvecs = list(bvecs) if isinstance(bvecs, TraitListObject) else bvecs
897-
if prefix.endswith("dwi"):
897+
898+
def rename_files() -> None:
899+
# shared code for renaming files
900+
if isinstance(bvecs, list):
901+
assert len(bvecs) == len(bvals) == 1
898902
outname_bvecs, outname_bvals = prefix + ".bvec", prefix + ".bval"
899-
safe_movefile(bvecs, outname_bvecs, overwrite)
900-
safe_movefile(bvals, outname_bvals, overwrite)
903+
bvecs_src = bvecs[0] if isinstance(bvecs, list) else bvecs
904+
bvals_src = bvals[0] if isinstance(bvals, list) else bvals
905+
safe_movefile(bvecs_src, outname_bvecs, overwrite)
906+
safe_movefile(bvals_src, outname_bvals, overwrite)
907+
908+
if prefix.endswith("dwi"):
909+
rename_files()
901910
else:
902911
if bvals_are_zero(bvals):
903912
to_remove = bvals + bvecs if isinstance(bvals, list) else [bvals, bvecs]
@@ -909,9 +918,7 @@ def save_converted_files(
909918
lgr.warning(
910919
".bvec and .bval files will be generated. This is NOT BIDS compliant"
911920
)
912-
outname_bvecs, outname_bvals = prefix + ".bvec", prefix + ".bval"
913-
safe_movefile(bvecs, outname_bvecs, overwrite)
914-
safe_movefile(bvals, outname_bvals, overwrite)
921+
rename_files()
915922

916923
if isinstance(res_files, list):
917924
res_files = sorted(res_files)

heudiconv/dicoms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
# TODO: remove the kludge whenever
5151
# https://github.com/moloney/dcmstack/pull/90 is merged and released
5252
if not hasattr(dcm, "read_file"):
53-
dcm.read_file = dcm.dcmread
53+
dcm.read_file = dcm.dcmread # type: ignore[attr-defined]
5454

5555
lgr = logging.getLogger(__name__)
5656
total_files = 0

heudiconv/tests/test_dicoms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,6 @@ def test_get_reproducible_int_raises_assertion_wo_dt(tmp_path: Path) -> None:
224224
del XA30_enhanced_dcm.AcquisitionDateTime
225225
del XA30_enhanced_dcm.SeriesDate
226226
del XA30_enhanced_dcm.SeriesTime
227-
dcm.dcmwrite(tmp_path, dataset=XA30_enhanced_dcm)
227+
dcm.dcmwrite(tmp_path, XA30_enhanced_dcm)
228228
with pytest.raises(AssertionError):
229229
get_reproducible_int([str(tmp_path)])

0 commit comments

Comments
 (0)