Commit 95b43c48 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

MNT: Remove use of six

parent 9a2f4904
......@@ -10,12 +10,12 @@ files. Pillow is required to use the ``Bitmap`` class.
import os.path as op
import pathlib
import logging
import six
import numpy as np
from . import image as fslimage
import fsl.data.image as fslimage
log = logging.getLogger(__name__)
......@@ -51,7 +51,7 @@ class Bitmap(object):
data.
"""
if isinstance(bmp, six.string_types):
if isinstance(bmp, (pathlib.Path, str)):
try:
# Allow big images
......@@ -61,7 +61,7 @@ class Bitmap(object):
except ImportError:
raise RuntimeError('Install Pillow to use the Bitmap class')
src = bmp
src = str(bmp)
img = Image.open(src)
# If this is a palette/LUT
......
......@@ -10,8 +10,8 @@ Freesurfer ``mgh``/``mgz`` image files.
import os.path as op
import pathlib
import six
import numpy as np
import nibabel as nib
......@@ -47,7 +47,7 @@ class MGHImage(fslimage.Image):
All other arguments are passed through to :meth:`Image.__init__`
"""
if isinstance(image, six.string_types):
if isinstance(image, (str, pathlib.Path)):
filename = op.abspath(image)
name = op.basename(filename)
image = nib.load(image)
......
......@@ -14,8 +14,6 @@ that some condition is met.
"""
import six
import nibabel as nib
import fsl.data.image as fslimage
......@@ -24,7 +22,7 @@ import fsl.data.image as fslimage
def ensureIsImage(img):
"""Ensures that the given ``img`` is an in-memory ``nibabel`` object.
"""
if isinstance(img, six.string_types):
if isinstance(img, str):
img = fslimage.addExt(img)
img = nib.load(img)
return img
......@@ -37,7 +37,7 @@ Example usage, building a short pipeline::
"""
from six import BytesIO
from io import BytesIO
import os.path as op
import glob
import time
......@@ -439,7 +439,7 @@ _external_job = ("""#!{}
# This is a temporary file designed to run the python function {},
# so that it can be submitted to the cluster
import pickle
from six import BytesIO
from io import BytesIO
from importlib import import_module
{}
pickle_bytes = BytesIO({})
......
......@@ -21,7 +21,6 @@ a function:
import logging
import hashlib
import functools
import six
log = logging.getLogger(__name__)
......@@ -171,7 +170,7 @@ def memoizeMD5(func):
# compatible) bytes , and take
# the hash of those bytes.
for arg in args:
if not isinstance(arg, six.string_types):
if not isinstance(arg, str):
arg = str(arg)
arg = arg.encode('utf-8')
hashobj.update(arg)
......
......@@ -14,9 +14,6 @@ import inspect
import contextlib
import collections
import six
import fsl.utils.idle as idle
import fsl.utils.weakfuncref as weakfuncref
......@@ -297,7 +294,7 @@ class Notifier(object):
:arg topic: Topic or topics that the listener is registered on.
"""
if topic is None or isinstance(topic, six.string_types):
if topic is None or isinstance(topic, str):
topic = [topic]
topics = topic
......
......@@ -30,8 +30,6 @@ import subprocess as sp
import os.path as op
import os
import six
from fsl.utils.platform import platform as fslplatform
import fsl.utils.fslsub as fslsub
import fsl.utils.tempdir as tempdir
......@@ -83,7 +81,7 @@ def prepareArgs(args):
if len(args) == 1:
# Argument was a command string
if isinstance(args[0], six.string_types):
if isinstance(args[0], str):
args = shlex.split(args[0])
# Argument was an unpacked sequence
......
......@@ -7,13 +7,12 @@
"""This module provides the :class:`WeakFunctionRef` class. """
import six
import types
import weakref
import inspect
class WeakFunctionRef(object):
class WeakFunctionRef:
"""Class which encapsulates a :mod:`weakref` to a function or method.
This class is used by :class:`.Notifier` instances to reference
......@@ -28,10 +27,10 @@ class WeakFunctionRef(object):
"""
# Bound method
if self.__isMethod(func):
if inspect.ismethod(func):
boundMeth = six.get_method_function(func)
boundSelf = six.get_method_self( func)
boundMeth = func.__func__
boundSelf = func.__self__
# We can't take a weakref of the method
# object, so we have to weakref the object
......@@ -73,35 +72,6 @@ class WeakFunctionRef(object):
return self.__str__()
def __isMethod(self, func):
"""Returns ``True`` if the given function is a bound method,
``False`` otherwise.
This seems to be one of the few areas where python 2 and 3 are
irreconcilably incompatible (or just where :mod:`six` does not have a
function to help us).
In Python 3 there is no difference between an unbound method and a
function. But in Python 2, an unbound method is still a method (and
inspect.ismethod returns True).
"""
ismethod = False
# Therefore, in python2 we need to test
# whether the function is a method, and
# also test whether it is bound.
if six.PY2:
ismethod = (inspect.ismethod(func) and
six.get_method_self(func) is not None)
# But in python3, if the function is a
# method it is, by definition, bound.
elif six.PY3:
ismethod = inspect.ismethod(func)
return ismethod
def __findPrivateMethod(self):
"""Finds and returns the bound method associated with the encapsulated
......@@ -125,8 +95,7 @@ class WeakFunctionRef(object):
att = getattr(obj, name)
if isinstance(att, types.MethodType) and \
six.get_method_function(att) is func:
if isinstance(att, types.MethodType) and att.__func__ is func:
return att
return None
......
......@@ -10,8 +10,6 @@
"""
import six
import fsl.utils.assertions as asrt
from . import wrapperutils as wutils
......@@ -28,7 +26,7 @@ def fast(imgs, out='fast', **kwargs):
command line option)
"""
if isinstance(imgs, six.string_types):
if isinstance(imgs, str):
imgs = [imgs]
asrt.assertIsNifti(*imgs)
......
......@@ -8,8 +8,6 @@
`FSL_ANAT <https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat>`_ command.
"""
import six
import fsl.utils.assertions as asrt
from . import wrapperutils as wutils
......
......@@ -103,8 +103,6 @@ import tempfile
import warnings
import functools
import six
import nibabel as nib
import numpy as np
......@@ -346,8 +344,7 @@ def applyArgStyle(style,
# always returns a sequence
def fmtval(val):
if isinstance(val, abc.Sequence) and \
not isinstance(val, six.string_types):
if isinstance(val, abc.Sequence) and (not isinstance(val, str)):
val = [str(v) for v in val]
if valsep == ' ': return val
......@@ -711,8 +708,7 @@ class FileOrThing(object):
kwargs.get('cmdonly', False):
allargs = {**dict(zip(argnames, args)), **kwargs}
for name, val in allargs.items():
if (name in self.__things) and \
(not isinstance(val, six.string_types)):
if (name in self.__things) and (not isinstance(val, str)):
raise ValueError('Cannot use in-memory objects '
'or LOAD with submit=True!')
return func(*args, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment