Skip to content

Commit 60284ae

Browse files
committed
RF: Basic check that file-like is a file-like
1 parent 6c9c385 commit 60284ae

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nibabel/freesurfer/io.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def _read_annot_ctab_old_format(fobj, n_entries):
402402
Parameters
403403
----------
404404
405-
fobj : file
405+
fobj : file-like
406406
Open file handle to a Freesurfer `.annot` file, with seek point
407407
at the beginning of the color table data.
408408
n_entries : int
@@ -416,8 +416,9 @@ def _read_annot_ctab_old_format(fobj, n_entries):
416416
names : list of str
417417
The names of the labels. The length of the list is n_entries.
418418
"""
419-
dt = _ANNOT_DT
419+
assert hasattr(fobj, 'read')
420420

421+
dt = _ANNOT_DT
421422
# orig_tab string length + string
422423
length = np.fromfile(fobj, dt, 1)[0]
423424
orig_tab = np.fromfile(fobj, '>c', length)
@@ -443,7 +444,7 @@ def _read_annot_ctab_new_format(fobj, ctab_version):
443444
Parameters
444445
----------
445446
446-
fobj : file
447+
fobj : file-like
447448
Open file handle to a Freesurfer `.annot` file, with seek point
448449
at the beginning of the color table data.
449450
ctab_version : int
@@ -457,6 +458,8 @@ def _read_annot_ctab_new_format(fobj, ctab_version):
457458
names : list of str
458459
The names of the labels. The length of the list is n_labels.
459460
"""
461+
assert hasattr(fobj, 'read')
462+
460463
dt = _ANNOT_DT
461464
# This code works with a file version == 2, nothing else
462465
if ctab_version != 2:

0 commit comments

Comments
 (0)