Skip to content

Commit 55b7d33

Browse files
committed
replaced str with basestring in instance checks to support unicode strings
1 parent 7afedad commit 55b7d33

File tree

16 files changed

+37
-37
lines changed

16 files changed

+37
-37
lines changed

doc/sphinxext/numpy_ext/docscrape_sphinx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _str_references(self):
140140
out = []
141141
if self['References']:
142142
out += self._str_header('References')
143-
if isinstance(self['References'], str):
143+
if isinstance(self['References'], basestring):
144144
self['References'] = [self['References']]
145145
out.extend(self['References'])
146146
out += ['']

nipype/algorithms/modelgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def _concatenate_info(self, infolist):
422422
for i, f in enumerate(self.inputs.functional_runs):
423423
if isinstance(f, list):
424424
numscans = len(f)
425-
elif isinstance(f, str):
425+
elif isinstance(f, basestring):
426426
img = load(f)
427427
numscans = img.get_shape()[3]
428428
else:

nipype/algorithms/rapidart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def _get_output_filenames(self, motionfile, output_dir):
279279
output_dir: string
280280
output directory in which the files will be generated
281281
"""
282-
if isinstance(motionfile, str):
282+
if isinstance(motionfile, basestring):
283283
infile = motionfile
284284
elif isinstance(motionfile, list):
285285
infile = motionfile[0]
@@ -350,7 +350,7 @@ def _detect_outliers_core(self, imgfile, motionfile, runidx, cwd=None):
350350
cwd = os.getcwd()
351351

352352
# read in functional image
353-
if isinstance(imgfile, str):
353+
if isinstance(imgfile, basestring):
354354
nim = load(imgfile)
355355
elif isinstance(imgfile, list):
356356
if len(imgfile) == 1:

nipype/interfaces/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def _get_sorteddict(self, object, dictwithhash=False, hash_method=None,
541541
out = tuple(out)
542542
else:
543543
if isdefined(object):
544-
if (hash_files and isinstance(object, str) and
544+
if (hash_files and isinstance(object, basestring) and
545545
os.path.isfile(object)):
546546
if hash_method is None:
547547
hash_method = config.get('execution', 'hash_method')
@@ -984,7 +984,7 @@ def run(self, **inputs):
984984
else:
985985
inputs_str = ''
986986

987-
if len(e.args) == 1 and isinstance(e.args[0], str):
987+
if len(e.args) == 1 and isinstance(e.args[0], basestring):
988988
e.args = (e.args[0] + " ".join([message, inputs_str]),)
989989
else:
990990
e.args += (message, )

nipype/interfaces/dcmstack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class DcmStack(NiftiGeneratorBase):
109109
output_spec = DcmStackOutputSpec
110110

111111
def _get_filelist(self, trait_input):
112-
if isinstance(trait_input, str):
112+
if isinstance(trait_input, basestring):
113113
if path.isdir(trait_input):
114114
return glob(path.join(trait_input, '*.dcm'))
115115
else:
@@ -334,7 +334,7 @@ def _run_interface(self, runtime):
334334
]
335335
if self.inputs.sort_order:
336336
sort_order = self.inputs.sort_order
337-
if isinstance(sort_order, str):
337+
if isinstance(sort_order, basestring):
338338
sort_order = [sort_order]
339339
nws.sort(key=make_key_func(sort_order))
340340
if self.inputs.merge_dim == traits.Undefined:

nipype/interfaces/io.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def _list_outputs(self):
520520
for argnum, arglist in enumerate(args):
521521
maxlen = 1
522522
for arg in arglist:
523-
if isinstance(arg, str) and hasattr(self.inputs, arg):
523+
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
524524
arg = getattr(self.inputs, arg)
525525
if isinstance(arg, list):
526526
if (maxlen > 1) and (len(arg) != maxlen):
@@ -531,7 +531,7 @@ def _list_outputs(self):
531531
for i in range(maxlen):
532532
argtuple = []
533533
for arg in arglist:
534-
if isinstance(arg, str) and hasattr(self.inputs, arg):
534+
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
535535
arg = getattr(self.inputs, arg)
536536
if isinstance(arg, list):
537537
argtuple.append(arg[i])
@@ -786,7 +786,7 @@ def _match_path(self, target_path):
786786

787787
def _run_interface(self, runtime):
788788
#Prepare some of the inputs
789-
if isinstance(self.inputs.root_paths, str):
789+
if isinstance(self.inputs.root_paths, basestring):
790790
self.inputs.root_paths = [self.inputs.root_paths]
791791
self.match_regex = re.compile(self.inputs.match_regex)
792792
if self.inputs.max_depth is Undefined:
@@ -1155,7 +1155,7 @@ def _list_outputs(self):
11551155
for argnum, arglist in enumerate(args):
11561156
maxlen = 1
11571157
for arg in arglist:
1158-
if isinstance(arg, str) and hasattr(self.inputs, arg):
1158+
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
11591159
arg = getattr(self.inputs, arg)
11601160
if isinstance(arg, list):
11611161
if (maxlen > 1) and (len(arg) != maxlen):
@@ -1168,7 +1168,7 @@ def _list_outputs(self):
11681168
for i in range(maxlen):
11691169
argtuple = []
11701170
for arg in arglist:
1171-
if isinstance(arg, str) and \
1171+
if isinstance(arg, basestring) and \
11721172
hasattr(self.inputs, arg):
11731173
arg = getattr(self.inputs, arg)
11741174
if isinstance(arg, list):
@@ -1725,7 +1725,7 @@ def _list_outputs(self):
17251725
for argnum, arglist in enumerate(args):
17261726
maxlen = 1
17271727
for arg in arglist:
1728-
if isinstance(arg, str) and hasattr(self.inputs, arg):
1728+
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
17291729
arg = getattr(self.inputs, arg)
17301730
if isinstance(arg, list):
17311731
if (maxlen > 1) and (len(arg) != maxlen):
@@ -1736,7 +1736,7 @@ def _list_outputs(self):
17361736
for i in range(maxlen):
17371737
argtuple = []
17381738
for arg in arglist:
1739-
if isinstance(arg, str) and hasattr(self.inputs, arg):
1739+
if isinstance(arg, basestring) and hasattr(self.inputs, arg):
17401740
arg = getattr(self.inputs, arg)
17411741
if isinstance(arg, list):
17421742
argtuple.append(arg[i])

nipype/interfaces/mne/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _list_outputs(self):
8989
out_files = []
9090
for value in value_list:
9191
out_files.append(op.abspath(value))
92-
elif isinstance(value_list, str):
92+
elif isinstance(value_list, basestring):
9393
out_files = op.abspath(value_list)
9494
else:
9595
raise TypeError

nipype/interfaces/nipy/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _run_interface(self, runtime):
8080
session_info = self.inputs.session_info
8181

8282
functional_runs = self.inputs.session_info[0]['scans']
83-
if isinstance(functional_runs, str):
83+
if isinstance(functional_runs, basestring):
8484
functional_runs = [functional_runs]
8585
nii = nb.load(functional_runs[0])
8686
data = nii.get_data()

nipype/interfaces/slicer/generate_classes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def add_class_to_package(class_codes, class_names, module_name, package_dir):
4747
def crawl_code_struct(code_struct, package_dir):
4848
subpackages = []
4949
for k, v in code_struct.iteritems():
50-
if isinstance(v, str) or isinstance(v, unicode):
50+
if isinstance(v, basestring) or isinstance(v, unicode):
5151
module_name = k.lower()
5252
class_name = k
5353
class_code = v
@@ -57,7 +57,7 @@ def crawl_code_struct(code_struct, package_dir):
5757
l1 = {}
5858
l2 = {}
5959
for key in v.keys():
60-
if (isinstance(v[key], str) or isinstance(v[key], unicode)):
60+
if (isinstance(v[key], basestring) or isinstance(v[key], unicode)):
6161
l1[key] = v[key]
6262
else:
6363
l2[key] = v[key]
@@ -313,7 +313,7 @@ def grab_xml(module, launcher):
313313
def parse_params(params):
314314
list = []
315315
for key, value in params.iteritems():
316-
if isinstance(value, str) or isinstance(value, unicode):
316+
if isinstance(value, basestring) or isinstance(value, unicode):
317317
list.append('%s="%s"' % (key, value.replace('"', "'")))
318318
else:
319319
list.append('%s=%s' % (key, value))

nipype/interfaces/spm/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _generate_job(self, prefix='', contents=None):
416416
if isinstance(val, np.ndarray):
417417
jobstring += self._generate_job(prefix=None,
418418
contents=val)
419-
elif isinstance(val, str):
419+
elif isinstance(val, basestring):
420420
jobstring += '\'%s\';...\n' % (val)
421421
else:
422422
jobstring += '%s;...\n' % str(val)
@@ -431,7 +431,7 @@ def _generate_job(self, prefix='', contents=None):
431431
jobstring += self._generate_job(newprefix,
432432
val[field])
433433
return jobstring
434-
if isinstance(contents, str):
434+
if isinstance(contents, basestring):
435435
jobstring += "%s = '%s';\n" % (prefix, contents)
436436
return jobstring
437437
jobstring += "%s = %s;\n" % (prefix, str(contents))

nipype/interfaces/spm/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _format_arg(self, opt, spec, val):
196196
if opt == 'spm_mat_file':
197197
return np.array([str(val)], dtype=object)
198198
if opt == 'estimation_method':
199-
if isinstance(val, str):
199+
if isinstance(val, basestring):
200200
return {'%s' % val: 1}
201201
else:
202202
return val

nipype/interfaces/utility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def __init__(self, input_names, output_names, function=None, imports=None,
386386
raise Exception('Interface Function does not accept ' \
387387
'function objects defined interactively ' \
388388
'in a python session')
389-
elif isinstance(function, str):
389+
elif isinstance(function, basestring):
390390
self.inputs.function_str = dumps(function)
391391
else:
392392
raise Exception('Unknown type of function')
@@ -404,7 +404,7 @@ def _set_function_string(self, obj, name, old, new):
404404
if name == 'function_str':
405405
if hasattr(new, '__call__'):
406406
function_source = getsource(new)
407-
elif isinstance(new, str):
407+
elif isinstance(new, basestring):
408408
function_source = dumps(new)
409409
self.inputs.trait_set(trait_change_notify=False,
410410
**{'%s' % name: function_source})

nipype/pipeline/engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def connect(self, *args, **kwargs):
361361
# handles the case that source is specified
362362
# with a function
363363
sourcename = source[0]
364-
elif isinstance(source, str):
364+
elif isinstance(source, basestring):
365365
sourcename = source
366366
else:
367367
raise Exception(('Unknown source specification in '
@@ -382,7 +382,7 @@ def connect(self, *args, **kwargs):
382382
# turn functions into strings
383383
for srcnode, destnode, connects in connection_list:
384384
for idx, (src, dest) in enumerate(connects):
385-
if isinstance(src, tuple) and not isinstance(src[1], str):
385+
if isinstance(src, tuple) and not isinstance(src[1], basestring):
386386
function_source = getsource(src[1])
387387
connects[idx] = ((src[0], function_source, src[2:]), dest)
388388

@@ -896,7 +896,7 @@ def _set_input(self, object, name, newvalue):
896896

897897
def _set_node_input(self, node, param, source, sourceinfo):
898898
"""Set inputs of a node given the edge connection"""
899-
if isinstance(sourceinfo, str):
899+
if isinstance(sourceinfo, basestring):
900900
val = source.get_output(sourceinfo)
901901
elif isinstance(sourceinfo, tuple):
902902
if callable(sourceinfo[1]):
@@ -1841,7 +1841,7 @@ def __init__(self, interface, name, joinsource, joinfield=None,
18411841
if not joinfield:
18421842
# default is the interface fields
18431843
joinfield = self._interface.inputs.copyable_trait_names()
1844-
elif isinstance(joinfield, str):
1844+
elif isinstance(joinfield, basestring):
18451845
joinfield = [joinfield]
18461846
self.joinfield = joinfield
18471847
"""the fields to join"""
@@ -2047,7 +2047,7 @@ def __init__(self, interface, iterfield, name, serial=False, **kwargs):
20472047

20482048

20492049
super(MapNode, self).__init__(interface, name, **kwargs)
2050-
if isinstance(iterfield, str):
2050+
if isinstance(iterfield, basestring):
20512051
iterfield = [iterfield]
20522052
self.iterfield = iterfield
20532053
self._inputs = self._create_dynamic_traits(self._interface.inputs,

nipype/pipeline/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def modify_paths(object, relative=True, basedir=None):
103103
out = tuple(out)
104104
else:
105105
if isdefined(object):
106-
if isinstance(object, str) and os.path.isfile(object):
106+
if isinstance(object, basestring) and os.path.isfile(object):
107107
if relative:
108108
if config.getboolean('execution', 'use_relative_paths'):
109109
out = relpath(object, start=basedir)
@@ -186,7 +186,7 @@ def _write_detailed_dot(graph, dotfilename):
186186
inports = []
187187
for u, v, d in graph.in_edges_iter(nbunch=n, data=True):
188188
for cd in d['connect']:
189-
if isinstance(cd[0], str):
189+
if isinstance(cd[0], basestring):
190190
outport = cd[0]
191191
else:
192192
outport = cd[0][0]
@@ -206,7 +206,7 @@ def _write_detailed_dot(graph, dotfilename):
206206
outports = []
207207
for u, v, d in graph.out_edges_iter(nbunch=n, data=True):
208208
for cd in d['connect']:
209-
if isinstance(cd[0], str):
209+
if isinstance(cd[0], basestring):
210210
outport = cd[0]
211211
else:
212212
outport = cd[0][0]
@@ -607,7 +607,7 @@ def generate_expanded_graph(graph_in):
607607
# the itersource is a (node name, fields) tuple
608608
src_name, src_fields = inode.itersource
609609
# convert a single field to a list
610-
if isinstance(src_fields, str):
610+
if isinstance(src_fields, basestring):
611611
src_fields = [src_fields]
612612
# find the unique iterable source node in the graph
613613
try:
@@ -789,7 +789,7 @@ def _standardize_iterables(node):
789789
if node.synchronize:
790790
if len(iterables) == 2:
791791
first, last = iterables
792-
if all((isinstance(item, str) and item in fields
792+
if all((isinstance(item, basestring) and item in fields
793793
for item in first)):
794794
iterables = _transpose_iterables(first, last)
795795

nipype/utils/docparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _parse_doc(doc, style=['--']):
277277
# individual flag/option.
278278
doclist = doc.split('\n')
279279
optmap = {}
280-
if isinstance(style,str):
280+
if isinstance(style,basestring):
281281
style = [style]
282282
for line in doclist:
283283
linelist = line.split()

nipype/utils/provenance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _get_sorteddict(object, dictwithhash=False):
9494
if isinstance(object, tuple):
9595
out = tuple(out)
9696
else:
97-
if isinstance(object, str) and os.path.isfile(object):
97+
if isinstance(object, basestring) and os.path.isfile(object):
9898
hash = hash_infile(object)
9999
if dictwithhash:
100100
out = (object, hash)

0 commit comments

Comments
 (0)