Merge pull request #5373 from jenshnielsen/python26removal · matplotlib/matplotlib@1866a8c · GitHub
Skip to content

Commit 1866a8c

Browse files
committed
Merge pull request #5373 from jenshnielsen/python26removal
CLN: Remove various Python 2.6 related workarounds
1 parent 19de414 commit 1866a8c

7 files changed

Lines changed: 20 additions & 88 deletions

File tree

examples/misc/multiprocess.py

Lines changed: 1 addition & 6 deletions

lib/matplotlib/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ def _forward_ilshift(self, other):
197197

198198

199199
major, minor1, minor2, s, tmp = sys.version_info
200-
_python26 = (major == 2 and minor1 >= 6) or major >= 3
200+
_python27 = (major == 2 and minor1 >= 7)
201+
_python34 = (major == 3 and minor1 >= 4)
201202

202-
if not _python26:
203-
raise ImportError('matplotlib requires Python 2.6 or later')
203+
if not (_python27 or _python34):
204+
raise ImportError('matplotlib requires Python 2.7 or 3.4 or later')
204205

205206

206207
if not compare_versions(numpy.__version__, __version__numpy__):

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,31 +235,14 @@ def get_latex_manager():
235235
LatexManagerFactory.previous_instance = new_inst
236236
return new_inst
237237

238-
class WeakSet(object):
239-
# TODO: Poor man's weakref.WeakSet.
240-
# Remove this once python 2.6 support is dropped from matplotlib.
241-
242-
def __init__(self):
243-
self.weak_key_dict = weakref.WeakKeyDictionary()
244-
245-
def add(self, item):
246-
self.weak_key_dict[item] = None
247-
248-
def discard(self, item):
249-
if item in self.weak_key_dict:
250-
del self.weak_key_dict[item]
251-
252-
def __iter__(self):
253-
return six.iterkeys(self.weak_key_dict)
254-
255238

256239
class LatexManager(object):
257240
"""
258241
The LatexManager opens an instance of the LaTeX application for
259242
determining the metrics of text elements. The LaTeX environment can be
260243
modified by setting fonts and/or a custem preamble in the rc parameters.
261244
"""
262-
_unclean_instances = WeakSet()
245+
_unclean_instances = weakref.WeakSet()
263246

264247
@staticmethod
265248
def _build_latex_header():

lib/matplotlib/cbook.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,7 @@ def deprecate(func, message=message, name=name, alternative=alternative,
191191
import textwrap
192192

193193
if isinstance(func, classmethod):
194-
try:
195-
func = func.__func__
196-
except AttributeError:
197-
# classmethods in Python2.6 and below lack the __func__
198-
# attribute so we need to hack around to get it
199-
method = func.__get__(None, object)
200-
if hasattr(method, '__func__'):
201-
func = method.__func__
202-
elif hasattr(method, 'im_func'):
203-
func = method.im_func
204-
else:
205-
# Nothing we can do really... just return the original
206-
# classmethod
207-
return func
194+
func = func.__func__
208195
is_classmethod = True
209196
else:
210197
is_classmethod = False

lib/matplotlib/tests/test_labeled_data_unpacking.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77
# 3.2+ versions
88
from nose.tools import assert_regex, assert_not_regex
99
except ImportError:
10-
try:
11-
# 2.7 versions
12-
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
13-
assert_regex = assert_regexp_matches
14-
assert_not_regex = assert_not_regexp_matches
15-
except ImportError:
16-
# 2.6 versions
17-
def noop(txt, regex):
18-
raise SkipTest("No assert for regex matching in py2.6")
19-
assert_regex = noop
20-
assert_not_regex = noop
10+
# 2.7 versions
11+
from nose.tools import assert_regexp_matches, assert_not_regexp_matches
12+
assert_regex = assert_regexp_matches
13+
assert_not_regex = assert_not_regexp_matches
2114

2215
from ..testing import assert_produces_warning
2316

lib/matplotlib/tests/test_spines.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
unicode_literals)
33

44
import numpy as np
5-
from nose.tools import assert_true
5+
from nose.tools import assert_true, assert_less
66
from matplotlib.externals import six
77

88
import matplotlib
@@ -71,13 +71,11 @@ def test_label_without_ticks():
7171
spine = ax.spines['left']
7272
spinebbox = spine.get_transform().transform_path(
7373
spine.get_path()).get_extents()
74-
# replace with assert_less if >python2.6
75-
assert_true(ax.yaxis.label.get_position()[0] < spinebbox.xmin,
74+
assert_less(ax.yaxis.label.get_position()[0], spinebbox.xmin,
7675
"Y-Axis label not left of the spine")
7776

7877
spine = ax.spines['bottom']
7978
spinebbox = spine.get_transform().transform_path(
8079
spine.get_path()).get_extents()
81-
# replace with assert_less if >python2.6
82-
assert_true(ax.xaxis.label.get_position()[1] < spinebbox.ymin,
80+
assert_less(ax.xaxis.label.get_position()[1], spinebbox.ymin,
8381
"X-Axis label not below the spine")

setupext.py

Lines changed: 6 additions & 31 deletions

0 commit comments

Comments
 (0)