From 4193746de28270134cf6dc10380549913192cb2c Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Mon, 23 Oct 2017 18:01:37 +0100
Subject: [PATCH] Fixing important pylint issues

---
 fsl/data/featanalysis.py    |  4 ++--
 fsl/data/featdesign.py      |  9 +++++----
 fsl/data/image.py           | 20 +++++++++++---------
 fsl/data/imagewrapper.py    |  8 ++++----
 fsl/data/melodicanalysis.py |  2 +-
 fsl/data/mesh.py            |  4 ++--
 fsl/utils/async.py          |  8 ++++----
 fsl/utils/platform.py       | 19 +++++++++----------
 fsl/utils/settings.py       |  6 +++---
 fsl/utils/weakfuncref.py    |  4 ++--
 10 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/fsl/data/featanalysis.py b/fsl/data/featanalysis.py
index a35d81b54..39e40c912 100644
--- a/fsl/data/featanalysis.py
+++ b/fsl/data/featanalysis.py
@@ -64,7 +64,7 @@ def isFEATImage(path):
 
     try:
         path = fslimage.addExt(path, mustExist=True)
-    except:
+    except fslimage.PathError:
         return False
 
     dirname  = op.dirname( path)
@@ -115,7 +115,7 @@ def hasStats(featdir):
     try:
         getZStatFile(featdir, 0)
         return True
-    except:
+    except fslimage.PathError:
         return False
 
 
diff --git a/fsl/data/featdesign.py b/fsl/data/featdesign.py
index ed8d90599..26c10595b 100644
--- a/fsl/data/featdesign.py
+++ b/fsl/data/featdesign.py
@@ -326,7 +326,8 @@ class VoxelwiseEV(NormalEV):
         if op.exists(filename):
             self.filename = filename
         else:
-            log.warning('Voxelwise EV file does not exist: '.format(filename))
+            log.warning('Voxelwise EV file does not '
+                        'exist: {}'.format(filename))
             self.filename = None
 
 
@@ -406,8 +407,8 @@ class VoxelwiseConfoundEV(EV):
         if op.exists(filename):
             self.filename = filename
         else:
-            log.warning('Voxelwise confound EV file '
-                        'does not exist: '.format(filename))
+            log.warning('Voxelwise confound EV file does '
+                        'not exist: {}'.format(filename))
             self.filename = None
 
 
@@ -547,7 +548,7 @@ def getFirstLevelEVs(featDir, settings, designMat):
         # Create the voxelwise confound EVs.
         # We make a name for the EV from the
         # file name.
-        for i, (f, l) in enumerate(zip(voxConfFiles, voxConfLocs)):
+        for i, f in enumerate(voxConfFiles):
             title = op.basename(fslimage.removeExt(f))
             evs.append(VoxelwiseConfoundEV(len(evs), i, title, f))
 
diff --git a/fsl/data/image.py b/fsl/data/image.py
index 0ec4fb103..b1c93c087 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -222,6 +222,8 @@ class Nifti(notifier.Notifier):
         #          qform  = header.get('qform_code',  -1)
         #          sform  = header.get('sform_code',  -1)
         #
+        # TODO Change this in fslpy 2.0.0
+        #
         if isinstance(header, nib.nifti1.Nifti1Header):
             intent = header['intent_code']
             qform  = header['qform_code']
@@ -309,8 +311,8 @@ class Nifti(notifier.Notifier):
 
         val = self.header[key]
 
-        try:    val = bytes(val).partition(b'\0')[0]
-        except: val = bytes(val)
+        try:              val = bytes(val).partition(b'\0')[0]
+        except Exception: val = bytes(val)
 
         val = val.decode('ascii')
 
@@ -611,12 +613,12 @@ class Nifti(notifier.Notifier):
         :class:`Nifti` instance) has the same dimensions and is in the
         same space as this image.
         """
-        return np.all(np.isclose(self .__shape[:3],
-                                 other.__shape[:3]))  and \
-               np.all(np.isclose(self .__pixdim[:3],
-                                 other.__pixdim[:3])) and \
-               np.all(np.isclose(self .__voxToWorldMat,
-                                 other.__voxToWorldMat))
+        return np.all(np.isclose(self .shape[:3],
+                                 other.shape[:3]))  and \
+               np.all(np.isclose(self .pixdim[:3],
+                                 other.pixdim[:3])) and \
+               np.all(np.isclose(self .voxToWorldMat,
+                                 other.voxToWorldMat))
 
 
     def getOrientation(self, axis, xform):
@@ -1426,7 +1428,7 @@ def read_segments(fileobj, segments, n_bytes):
         # actual file is available via the fobj attribute
         lock = getattr(fileobj.fobj, '_arrayproxy_lock')
 
-    except:
+    except AttributeError:
         return fileslice.orig_read_segments(fileobj, segments, n_bytes)
 
     if len(segments) == 0:
diff --git a/fsl/data/imagewrapper.py b/fsl/data/imagewrapper.py
index ab8362985..22883780c 100644
--- a/fsl/data/imagewrapper.py
+++ b/fsl/data/imagewrapper.py
@@ -231,7 +231,7 @@ class ImageWrapper(notifier.Notifier):
         self.__image = None
         if self.__taskThread is not None:
             self.__taskThread.stop()
-            self.__taskThraed = None
+            self.__taskThread = None
 
 
     def getTaskThread(self):
@@ -459,7 +459,7 @@ class ImageWrapper(notifier.Notifier):
         # the min/max per volume/expansion, and
         # iteratively update the stored per-volume
         # coverage and data range.
-        for i, exp in enumerate(expansions):
+        for exp in expansions:
 
             data = self.__getData(exp, isTuple=True)
             data = data.squeeze(squeezeDims)
@@ -750,7 +750,7 @@ def naninfrange(data):
     # finite values in the array
     try:
         return data[finite].min(), data[finite].max()
-    except:
+    except Exception:
         return np.nan, np.nan
 
 
@@ -1097,7 +1097,7 @@ def calcExpansion(slices, coverage):
     # 'padding' dimensions of size 1.
     def finishExpansion(exp, vol):
         exp.append((vol, vol + 1))
-        for i in range(padDims):
+        for _ in range(padDims):
             exp.append((0, 1))
         return exp
 
diff --git a/fsl/data/melodicanalysis.py b/fsl/data/melodicanalysis.py
index d0074f27f..e13dd1e99 100644
--- a/fsl/data/melodicanalysis.py
+++ b/fsl/data/melodicanalysis.py
@@ -49,7 +49,7 @@ def isMelodicImage(path):
 
     try:
         path = fslimage.addExt(path, mustExist=True)
-    except:
+    except fslimage.PathError:
         return False
 
     dirname  = op.dirname( path)
diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py
index c3c701232..d052ccb39 100644
--- a/fsl/data/mesh.py
+++ b/fsl/data/mesh.py
@@ -380,7 +380,7 @@ def findReferenceImage(modelfile):
 
         dirname  = op.dirname(modelfile)
         prefixes = [getFIRSTPrefix(modelfile)]
-    except:
+    except ValueError:
         return None
 
     if prefixes[0].endswith('_first'):
@@ -389,7 +389,7 @@ def findReferenceImage(modelfile):
     for p in prefixes:
         try:
             return fslimage.addExt(op.join(dirname, p), mustExist=True)
-        except:
+        except fslimage.PathError:
             continue
 
     return None
diff --git a/fsl/utils/async.py b/fsl/utils/async.py
index 373e49e64..4ff8dec15 100644
--- a/fsl/utils/async.py
+++ b/fsl/utils/async.py
@@ -87,8 +87,8 @@ import functools
 import threading
 import collections
 
-try:    import queue
-except: import Queue as queue
+try:                import queue
+except ImportError: import Queue as queue
 
 
 log = logging.getLogger(__name__)
@@ -142,7 +142,7 @@ def run(task, onFinish=None, onError=None, name=None):
 
         except Exception as e:
 
-            log.warn('Task "{}" crashed'.format(name), exc_info=True)
+            log.warning('Task "{}" crashed'.format(name), exc_info=True)
             callback(onError, e)
 
     # If WX, run on a thread
@@ -759,7 +759,7 @@ class TaskThread(threading.Thread):
             # Any other error typically indicates
             # that this is a daemon thread, and
             # the TaskThread object has been GC'd
-            except:
+            except Exception:
                 break
 
             finally:
diff --git a/fsl/utils/platform.py b/fsl/utils/platform.py
index 972790abd..32e9d296a 100644
--- a/fsl/utils/platform.py
+++ b/fsl/utils/platform.py
@@ -146,6 +146,7 @@ class Platform(notifier.Notifier):
         self.__glRenderer   = None
         self.__glIsSoftware = None
         self.__fslVersion   = None
+        self.__fsldir       = None
         self.fsldir         = os.environ.get('FSLDIR', None)
 
         # Determine if a display is available. We do
@@ -239,18 +240,16 @@ class Platform(notifier.Notifier):
 
         pi = [t.lower() for t in wx.PlatformInfo]
 
-        for tag in pi:
-
-            if   any(['cocoa'  in p for p in pi]): platform = WX_MAC_COCOA
-            elif any(['carbon' in p for p in pi]): platform = WX_MAC_CARBON
-            elif any(['gtk'    in p for p in pi]): platform = WX_GTK
-            else:                                  platform = WX_UNKNOWN
+        if   any(['cocoa'  in p for p in pi]): plat = WX_MAC_COCOA
+        elif any(['carbon' in p for p in pi]): plat = WX_MAC_CARBON
+        elif any(['gtk'    in p for p in pi]): plat = WX_GTK
+        else:                                  plat = WX_UNKNOWN
 
-            if platform is WX_UNKNOWN:
-                log.warning('Could not determine wx platform from '
-                            'information: {}'.format(pi))
+        if platform is WX_UNKNOWN:
+            log.warning('Could not determine wx platform from '
+                        'information: {}'.format(pi))
 
-        return platform
+        return plat
 
 
     @property
diff --git a/fsl/utils/settings.py b/fsl/utils/settings.py
index 491198adb..675ad29c4 100644
--- a/fsl/utils/settings.py
+++ b/fsl/utils/settings.py
@@ -341,7 +341,7 @@ class Settings(object):
         if not op.exists(cfgdir):
             try:
                 os.makedirs(cfgdir)
-            except:
+            except OSError:
                 log.warning(
                     'Unable to create {} configuration '
                     'directory: {}'.format(cid, cfgdir),
@@ -372,7 +372,7 @@ class Settings(object):
         try:
             with open(configFile, 'rb') as f:
                 return pickle.load(f)
-        except:
+        except (IOError, pickle.UnpicklingError):
             log.debug('Unable to load stored {} configuration file '
                       '{}'.format(self.__configID, configFile),
                       exc_info=True)
@@ -391,7 +391,7 @@ class Settings(object):
         try:
             with open(configFile, 'wb') as f:
                 pickle.dump(config, f)
-        except:
+        except (IOError, pickle.PicklingError):
             log.warning('Unable to save {} configuration file '
                         '{}'.format(self.__configID, configFile),
                         exc_info=True)
diff --git a/fsl/utils/weakfuncref.py b/fsl/utils/weakfuncref.py
index 71350145e..937481c01 100644
--- a/fsl/utils/weakfuncref.py
+++ b/fsl/utils/weakfuncref.py
@@ -148,9 +148,9 @@ class WeakFunctionRef(object):
         obj = self.obj()
 
         # Return the bound method object
-        try:    return getattr(obj, self.funcName)
+        try: return getattr(obj, self.funcName)
 
         # If the function is a bound private method,
         # its name on the instance will have been
         # mangled, so we need to search for it
-        except: return self.__findPrivateMethod()
+        except AttributeError: return self.__findPrivateMethod()
-- 
GitLab