Skip to content

Commit ab7ce7d

Browse files
committed
switched to six.string_types for string type checks
1 parent 52842a0 commit ab7ce7d

File tree

22 files changed

+73
-50
lines changed

22 files changed

+73
-50
lines changed

doc/sphinxext/numpy_ext/docscrape_sphinx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re, inspect, textwrap, pydoc
22
import sphinx
33
from docscrape import NumpyDocString, FunctionDoc, ClassDoc
4+
from nipype.external import six
45

56
class SphinxDocString(NumpyDocString):
67
def __init__(self, docstring, config={}):
@@ -140,7 +141,7 @@ def _str_references(self):
140141
out = []
141142
if self['References']:
142143
out += self._str_header('References')
143-
if isinstance(self['References'], basestring):
144+
if isinstance(self['References'], six.string_types):
144145
self['References'] = [self['References']]
145146
out.extend(self['References'])
146147
out += ['']

examples/fmri_ants_openfmri.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from nipype import config
1616
config.enable_provenance()
17+
from nipype.external import six
18+
1719

1820
from glob import glob
1921
import os
@@ -443,7 +445,7 @@ def get_contrasts(contrast_file, task_id, conds):
443445

444446
def check_behav_list(behav):
445447
out_behav = []
446-
if isinstance(behav, basestring):
448+
if isinstance(behav, six.string_types):
447449
behav = [behav]
448450
for val in behav:
449451
if not isinstance(val, list):

examples/fmri_openfmri.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from nipype import config
1616
config.enable_provenance()
17+
from nipype.external import six
1718

1819
from glob import glob
1920
import os
@@ -237,7 +238,7 @@ def get_contrasts(contrast_file, task_id, conds):
237238

238239
def check_behav_list(behav):
239240
out_behav = []
240-
if isinstance(behav, basestring):
241+
if isinstance(behav, six.string_types):
241242
behav = [behav]
242243
for val in behav:
243244
if not isinstance(val, list):

nipype/algorithms/modelgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
isdefined)
3131
from nipype.utils.filemanip import filename_to_list
3232
from .. import config, logging
33+
from nipype.external import six
3334
iflogger = logging.getLogger('interface')
3435

3536
def gcd(a, b):
@@ -422,7 +423,7 @@ def _concatenate_info(self, infolist):
422423
for i, f in enumerate(self.inputs.functional_runs):
423424
if isinstance(f, list):
424425
numscans = len(f)
425-
elif isinstance(f, basestring):
426+
elif isinstance(f, six.string_types):
426427
img = load(f)
427428
numscans = img.get_shape()[3]
428429
else:

nipype/algorithms/rapidart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import numpy as np
2727
from scipy import signal
2828
import scipy.io as sio
29+
from nipype.external import six
2930

3031
from ..interfaces.base import (BaseInterface, traits, InputMultiPath,
3132
OutputMultiPath, TraitedSpec, File,
@@ -279,7 +280,7 @@ def _get_output_filenames(self, motionfile, output_dir):
279280
output_dir: string
280281
output directory in which the files will be generated
281282
"""
282-
if isinstance(motionfile, basestring):
283+
if isinstance(motionfile, six.string_types):
283284
infile = motionfile
284285
elif isinstance(motionfile, list):
285286
infile = motionfile[0]
@@ -350,7 +351,7 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
350351
cwd = os.getcwd()
351352

352353
# read in functional image
353-
if isinstance(imgfile, basestring):
354+
if isinstance(imgfile, six.string_types):
354355
nim = load(imgfile)
355356
elif isinstance(imgfile, list):
356357
if len(imgfile) == 1:

nipype/external/provcopy.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import dateutil.parser
1818
import collections
1919
from collections import defaultdict
20+
import six
2021

2122
try:
2223
from rdflib.term import URIRef, BNode
@@ -187,7 +188,7 @@ def _parse_xsd_dateTime(s):
187188

188189

189190
def _ensure_datetime(time):
190-
if isinstance(time, basestring):
191+
if isinstance(time, six.string_types):
191192
return _parse_xsd_dateTime(time)
192193
else:
193194
return time
@@ -232,12 +233,12 @@ def parse_xsd_types(value, datatype):
232233

233234

234235
def _ensure_multiline_string_triple_quoted(s):
235-
format_str = u'"""%s"""' if isinstance(s, basestring) and '\n' in s else u'"%s"'
236+
format_str = u'"""%s"""' if isinstance(s, six.string_types) and '\n' in s else u'"%s"'
236237
return format_str % s
237238

238239

239240
def encoding_PROV_N_value(value):
240-
if isinstance(value, basestring):
241+
if isinstance(value, six.string_types):
241242
return _ensure_multiline_string_triple_quoted(value)
242243
elif isinstance(value, datetime.datetime):
243244
return value.isoformat()
@@ -536,7 +537,7 @@ def _auto_literal_conversion(self, literal):
536537
if isinstance(literal, URIRef):
537538
return literal
538539

539-
if isinstance(literal, basestring):
540+
if isinstance(literal, six.string_types):
540541
return unicode(literal)
541542

542543
if isinstance(literal, Literal) and literal.has_no_langtag():
@@ -1568,7 +1569,7 @@ def _decode_JSON_container(self, jc):
15681569
key=lambda tuple_rec: tuple_rec[0])
15691570

15701571
record_map = {}
1571-
_parse_attr_value = lambda value: record_map[value] if (isinstance(value, basestring) and value in record_map) else self._decode_json_representation(value)
1572+
_parse_attr_value = lambda value: record_map[value] if (isinstance(value, six.string_types) and value in record_map) else self._decode_json_representation(value)
15721573
# Create all the records before setting their attributes
15731574
for (record_type, identifier, content) in records:
15741575
if record_type == PROV_REC_BUNDLE:

nipype/fixes/numpy/testing/nosetester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import os
88
import sys
9+
from nipype.external import six
910

1011
def get_package_name(filepath):
1112
"""
@@ -166,7 +167,7 @@ def _test_argv(self, label, verbose, extra_argv):
166167
'''
167168
argv = [__file__, self.package_path, '-s']
168169
if label and label != 'full':
169-
if not isinstance(label, basestring):
170+
if not isinstance(label, six.string_types):
170171
raise TypeError('Selection label should be a string')
171172
if label == 'fast':
172173
label = 'not slow'

nipype/interfaces/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from datetime import datetime as dt
2525
from dateutil.parser import parse as parseutc
2626
from warnings import warn
27+
from nipype.external import six
2728

2829

2930
from .traits_extension import (traits, Undefined, TraitDictObject,
@@ -541,7 +542,7 @@ def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
541542
out = tuple(out)
542543
else:
543544
if isdefined(object):
544-
if (hash_files and isinstance(object, basestring) and
545+
if (hash_files and isinstance(object, six.string_types) and
545546
os.path.isfile(object)):
546547
if hash_method is None:
547548
hash_method = config.get('execution', 'hash_method')
@@ -984,7 +985,7 @@ def run(self, **inputs):
984985
else:
985986
inputs_str = ''
986987

987-
if len(e.args) == 1 and isinstance(e.args[0], basestring):
988+
if len(e.args) == 1 and isinstance(e.args[0], six.string_types):
988989
e.args = (e.args[0] + " ".join([message, inputs_str]),)
989990
else:
990991
e.args += (message, )

nipype/interfaces/dcmstack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import nibabel as nb
2424
from nipype.interfaces.traits_extension import isdefined, Undefined
2525
import imghdr
26+
from nipype.external import six
2627

2728
have_dcmstack = True
2829
try:
@@ -109,7 +110,7 @@ class DcmStack(NiftiGeneratorBase):
109110
output_spec = DcmStackOutputSpec
110111

111112
def _get_filelist(self, trait_input):
112-
if isinstance(trait_input, basestring):
113+
if isinstance(trait_input, six.string_types):
113114
if path.isdir(trait_input):
114115
return glob(path.join(trait_input, '*.dcm'))
115116
else:
@@ -334,7 +335,7 @@ def _run_interface(self, runtime):
334335
]
335336
if self.inputs.sort_order:
336337
sort_order = self.inputs.sort_order
337-
if isinstance(sort_order, basestring):
338+
if isinstance(sort_order, six.string_types):
338339
sort_order = [sort_order]
339340
nws.sort(key=make_key_func(sort_order))
340341
if self.inputs.merge_dim == traits.Undefined:

nipype/interfaces/io.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import sqlite3
3232
from nipype.utils.misc import human_order_sorted
33+
from nipype.external import six
3334

3435
try:
3536
import pyxnat
@@ -520,7 +521,7 @@ def _list_outputs(self):
520521
for argnum, arglist in enumerate(args):
521522
maxlen = 1
522523
for arg in arglist:
523-
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
524+
if isinstance(arg, six.string_types) and hasattr(self.inputs, arg):
524525
arg = getattr(self.inputs, arg)
525526
if isinstance(arg, list):
526527
if (maxlen > 1) and (len(arg) != maxlen):
@@ -531,7 +532,7 @@ def _list_outputs(self):
531532
for i in range(maxlen):
532533
argtuple = []
533534
for arg in arglist:
534-
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
535+
if isinstance(arg, six.string_types) and hasattr(self.inputs, arg):
535536
arg = getattr(self.inputs, arg)
536537
if isinstance(arg, list):
537538
argtuple.append(arg[i])
@@ -786,7 +787,7 @@ def _match_path(self, target_path):
786787

787788
def _run_interface(self, runtime):
788789
#Prepare some of the inputs
789-
if isinstance(self.inputs.root_paths, basestring):
790+
if isinstance(self.inputs.root_paths, six.string_types):
790791
self.inputs.root_paths = [self.inputs.root_paths]
791792
self.match_regex = re.compile(self.inputs.match_regex)
792793
if self.inputs.max_depth is Undefined:
@@ -1155,7 +1156,7 @@ def _list_outputs(self):
11551156
for argnum, arglist in enumerate(args):
11561157
maxlen = 1
11571158
for arg in arglist:
1158-
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
1159+
if isinstance(arg, six.string_types) and hasattr(self.inputs, arg):
11591160
arg = getattr(self.inputs, arg)
11601161
if isinstance(arg, list):
11611162
if (maxlen > 1) and (len(arg) != maxlen):
@@ -1168,7 +1169,7 @@ def _list_outputs(self):
11681169
for i in range(maxlen):
11691170
argtuple = []
11701171
for arg in arglist:
1171-
if isinstance(arg, basestring) and \
1172+
if isinstance(arg, six.string_types) and \
11721173
hasattr(self.inputs, arg):
11731174
arg = getattr(self.inputs, arg)
11741175
if isinstance(arg, list):
@@ -1725,7 +1726,7 @@ def _list_outputs(self):
17251726
for argnum, arglist in enumerate(args):
17261727
maxlen = 1
17271728
for arg in arglist:
1728-
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
1729+
if isinstance(arg, six.string_types) and hasattr(self.inputs, arg):
17291730
arg = getattr(self.inputs, arg)
17301731
if isinstance(arg, list):
17311732
if (maxlen > 1) and (len(arg) != maxlen):
@@ -1736,7 +1737,7 @@ def _list_outputs(self):
17361737
for i in range(maxlen):
17371738
argtuple = []
17381739
for arg in arglist:
1739-
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
1740+
if isinstance(arg, six.string_types) and hasattr(self.inputs, arg):
17401741
arg = getattr(self.inputs, arg)
17411742
if isinstance(arg, list):
17421743
argtuple.append(arg[i])

0 commit comments

Comments
 (0)