Skip to content

Commit 7a337ed

Browse files
committed
No need to do a versino check here. If Normalize is not a new-style class just replace it with a subclass that is.
1 parent b1e02bd commit 7a337ed

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

‎astropy/visualization/mpl_normalize.py‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44

55
from __future__ import division, print_function
66

7-
from distutils.version import LooseVersion
8-
97
import numpy as np
108
from numpy import ma
119

1210
try:
1311
import matplotlib
14-
HAS_MATPLOTLIB = True
15-
MATPLOTLIB_LT_12 = LooseVersion(matplotlib.__version__) < LooseVersion("1.2.0")
1612
from matplotlib.colors import Normalize
13+
14+
# On older versions of matplotlib Normalize is an old-style class
15+
if not isinstance(Normalize, type):
16+
class Normalize(Normalize, object):
17+
pass
1718
except ImportError:
18-
HAS_MATPLOTLIB = False
1919
class Normalize(object):
2020
def __init__(self, *args, **kwargs):
2121
raise ImportError("matplotlib is required in order to use this class")
2222

23+
2324
__all__ = ['ImageNormalize']
2425

2526

@@ -38,12 +39,7 @@ class ImageNormalize(Normalize):
3839
"""
3940

4041
def __init__(self, vmin=None, vmax=None, stretch=None, clip=False):
41-
42-
if HAS_MATPLOTLIB and MATPLOTLIB_LT_12:
43-
# Normalize is an old-style class
44-
Normalize.__init__(self, vmin=vmin, vmax=vmax, clip=clip)
45-
else: # Normalize is a new-style class
46-
super(ImageNormalize, self).__init__(vmin=vmin, vmax=vmax, clip=clip)
42+
super(ImageNormalize, self).__init__(vmin=vmin, vmax=vmax, clip=clip)
4743

4844
self.vmin = vmin
4945
self.vmax = vmax

0 commit comments

Comments
 (0)